Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3376b5c

Browse files
committed
SQLAlchemy: Rename leftover occurrences of Object to ObjectType
The new symbol to represent CrateDB's `OBJECT` column type is now `ObjectType`. Before, it was just called `Object`, or sometimes `Craty`, which is both either a bit ambiguous, or a bit too fancy.
1 parent d9473d0 commit 3376b5c

File tree

8 files changed

+33
-29
lines changed

8 files changed

+33
-29
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Changes for crate
55
Unreleased
66
==========
77

8+
- SQLAlchemy: Rename leftover occurrences of ``Object``. The new symbol to represent
9+
CrateDB's ``OBJECT`` column type is now ``ObjectType``.
10+
811

912
2023/07/06 0.32.0
1013
=================

docs/by-example/sqlalchemy/working-with-types.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SQLAlchemy: Working with special CrateDB types
77
This section of the documentation shows how to work with special data types
88
from the CrateDB SQLAlchemy dialect. Currently, these are:
99

10-
- Container types ``Object`` and ``ObjectArray``.
10+
- Container types ``ObjectType`` and ``ObjectArray``.
1111
- Geospatial types ``Geopoint`` and ``Geoshape``.
1212

1313

@@ -33,7 +33,7 @@ Import the relevant symbols:
3333
... except ImportError:
3434
... from sqlalchemy.ext.declarative import declarative_base
3535
>>> from uuid import uuid4
36-
>>> from crate.client.sqlalchemy.types import Object, ObjectArray
36+
>>> from crate.client.sqlalchemy.types import ObjectType, ObjectArray
3737
>>> from crate.client.sqlalchemy.types import Geopoint, Geoshape
3838

3939
Establish a connection to the database, see also :ref:`sa:engines_toplevel`
@@ -53,9 +53,9 @@ Introduction to container types
5353

5454
In a document oriented database, it is a common pattern to store objects within
5555
a single field. For such cases, the CrateDB SQLAlchemy dialect provides the
56-
``Object`` and ``ObjectArray`` types.
56+
``ObjectType`` and ``ObjectArray`` types.
5757

58-
The ``Object`` type effectively implements a dictionary- or map-like type. The
58+
The ``ObjectType`` type effectively implements a dictionary- or map-like type. The
5959
``ObjectArray`` type maps to a Python list of dictionaries.
6060

6161
For exercising those features, let's define a schema using SQLAlchemy's
@@ -69,15 +69,15 @@ For exercising those features, let's define a schema using SQLAlchemy's
6969
... id = sa.Column(sa.String, primary_key=True, default=gen_key)
7070
... name = sa.Column(sa.String)
7171
... quote = sa.Column(sa.String)
72-
... details = sa.Column(Object)
72+
... details = sa.Column(ObjectType)
7373
... more_details = sa.Column(ObjectArray)
7474

7575
In CrateDB's SQL dialect, those container types map to :ref:`crate-reference:type-object`
7676
and :ref:`crate-reference:type-array`.
7777

7878

79-
``Object``
80-
==========
79+
``ObjectType``
80+
==============
8181

8282
Let's add two records which have additional items within the ``details`` field.
8383
Note that item keys have not been defined in the DDL schema, effectively
@@ -113,7 +113,7 @@ A subsequent select query will see all the records:
113113
[('Arthur Dent', 'male'), ('Tricia McMillan', 'female')]
114114

115115
It is also possible to just select a part of the document, even inside the
116-
``Object`` type:
116+
``ObjectType`` type:
117117

118118
>>> sorted(session.query(Character.details['gender']).all())
119119
[('female',), ('male',)]
@@ -129,7 +129,7 @@ Update dictionary
129129
-----------------
130130

131131
The SQLAlchemy CrateDB dialect supports change tracking deep down the nested
132-
levels of a ``Object`` type field. For example, the following query will only
132+
levels of a ``ObjectType`` type field. For example, the following query will only
133133
update the ``gender`` key. The ``species`` key which is on the same level will
134134
be left untouched.
135135

@@ -170,7 +170,7 @@ Refresh and query "characters" table:
170170
``ObjectArray``
171171
===============
172172

173-
Note that opposed to the ``Object`` type, the ``ObjectArray`` type isn't smart
173+
Note that opposed to the ``ObjectType`` type, the ``ObjectArray`` type isn't smart
174174
and doesn't have intelligent change tracking. Therefore, the generated
175175
``UPDATE`` statement will affect the whole list:
176176

docs/sqlalchemy.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ system <sa:orm_declarative_mapping>`:
201201
... name = sa.Column(sa.String, crate_index=False)
202202
... name_normalized = sa.Column(sa.String, sa.Computed("lower(name)"))
203203
... quote = sa.Column(sa.String, nullable=False)
204-
... details = sa.Column(types.Object)
204+
... details = sa.Column(types.ObjectType)
205205
... more_details = sa.Column(types.ObjectArray)
206206
... name_ft = sa.Column(sa.String)
207207
... quote_ft = sa.Column(sa.String)
@@ -224,7 +224,7 @@ In this example, we:
224224
- Disable indexing of the ``name`` column using ``crate_index=False``
225225
- Define a computed column ``name_normalized`` (based on ``name``) that
226226
translates into a generated column
227-
- Use the `Object`_ extension type for the ``details`` column
227+
- Use the `ObjectType`_ extension type for the ``details`` column
228228
- Use the `ObjectArray`_ extension type for the ``more_details`` column
229229
- Set up the ``name_ft`` and ``quote_ft`` fulltext indexes, but exclude them from
230230
the mapping (so SQLAlchemy doesn't try to update them as if they were columns)
@@ -314,9 +314,10 @@ dialect provides.
314314
The appendix has a full :ref:`data types reference <data-types-sqlalchemy>`.
315315

316316
.. _object:
317+
.. _objecttype:
317318

318-
``Object``
319-
..........
319+
``ObjectType``
320+
..............
320321

321322
Objects are a common, and useful, data type when using CrateDB, so the CrateDB
322323
SQLAlchemy dialect provides a custom ``Object`` type extension for working with
@@ -355,7 +356,7 @@ insert two records:
355356

356357
.. NOTE::
357358

358-
Behind the scenes, if you update an ``Object`` property and ``commit`` that
359+
Behind the scenes, if you update an ``ObjectType`` property, and ``commit`` that
359360
change, the :ref:`UPDATE <crate-reference:dml-updating-data>` statement sent
360361
to CrateDB will only include the data necessary to update the changed
361362
sub-columns.
@@ -365,7 +366,7 @@ insert two records:
365366
``ObjectArray``
366367
...............
367368

368-
In addition to the `Object`_ type, the CrateDB SQLAlchemy dialect also provides
369+
In addition to the `ObjectType`_ type, the CrateDB SQLAlchemy dialect also provides
369370
an ``ObjectArray`` type, which is structured as a :class:`py:list` of
370371
:class:`dictionaries <py:dict>`.
371372

@@ -386,7 +387,7 @@ The resulting object will look like this:
386387

387388
.. CAUTION::
388389

389-
Behind the scenes, if you update an ``ObjectArray`` and ``commit`` that
390+
Behind the scenes, if you update an ``ObjectArray``, and ``commit`` that
390391
change, the :ref:`UPDATE <crate-reference:dml-updating-data>` statement
391392
sent to CrateDB will include all of the ``ObjectArray`` data.
392393

@@ -468,12 +469,12 @@ Here's what a regular select might look like:
468469
[('Arthur Dent', 'male'), ('Tricia McMillan', 'female')]
469470

470471
You can also select a portion of each record, and this even works inside
471-
`Object`_ columns:
472+
`ObjectType`_ columns:
472473

473474
>>> sorted(session.query(Character.details['gender']).all())
474475
[('female',), ('male',)]
475476

476-
You can also filter on attributes inside the `Object`_ column:
477+
You can also filter on attributes inside the `ObjectType`_ column:
477478

478479
>>> query = session.query(Character.name)
479480
>>> query.filter(Character.details['gender'] == 'male').all()

src/crate/client/sqlalchemy/dialect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
)
3434
from crate.client.exceptions import TimezoneUnawareException
3535
from .sa_version import SA_VERSION, SA_1_4, SA_2_0
36-
from .types import Object, ObjectArray
36+
from .types import ObjectType, ObjectArray
3737

3838
TYPES_MAP = {
3939
"boolean": sqltypes.Boolean,
4040
"short": sqltypes.SmallInteger,
4141
"smallint": sqltypes.SmallInteger,
4242
"timestamp": sqltypes.TIMESTAMP,
4343
"timestamp with time zone": sqltypes.TIMESTAMP,
44-
"object": Object,
44+
"object": ObjectType,
4545
"integer": sqltypes.Integer,
4646
"long": sqltypes.NUMERIC,
4747
"bigint": sqltypes.NUMERIC,

src/crate/client/sqlalchemy/tests/create_table_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
except ImportError:
2626
from sqlalchemy.ext.declarative import declarative_base
2727

28-
from crate.client.sqlalchemy.types import Object, ObjectArray, Geopoint
28+
from crate.client.sqlalchemy.types import ObjectType, ObjectArray, Geopoint
2929
from crate.client.cursor import Cursor
3030

3131
from unittest import TestCase
@@ -76,7 +76,7 @@ def test_column_obj(self):
7676
class DummyTable(self.Base):
7777
__tablename__ = 'dummy'
7878
pk = sa.Column(sa.String, primary_key=True)
79-
obj_col = sa.Column(Object)
79+
obj_col = sa.Column(ObjectType)
8080
self.Base.metadata.create_all(bind=self.engine)
8181
fake_cursor.execute.assert_called_with(
8282
('\nCREATE TABLE dummy (\n\tpk STRING NOT NULL, \n\tobj_col OBJECT, '

src/crate/client/sqlalchemy/tests/dialect_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from crate.client.cursor import Cursor
2929
from crate.client.sqlalchemy import SA_VERSION
3030
from crate.client.sqlalchemy.sa_version import SA_1_4, SA_2_0
31-
from crate.client.sqlalchemy.types import Object
31+
from crate.client.sqlalchemy.types import ObjectType
3232
from sqlalchemy import inspect
3333
from sqlalchemy.orm import Session
3434
try:
@@ -67,7 +67,7 @@ class Character(self.base):
6767

6868
name = sa.Column(sa.String, primary_key=True)
6969
age = sa.Column(sa.Integer, primary_key=True)
70-
obj = sa.Column(Object)
70+
obj = sa.Column(ObjectType)
7171
ts = sa.Column(sa.DateTime, onupdate=datetime.utcnow)
7272

7373
self.session = Session(bind=self.engine)

src/crate/client/sqlalchemy/tests/query_caching.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
except ImportError:
3535
from sqlalchemy.ext.declarative import declarative_base
3636

37-
from crate.client.sqlalchemy.types import Object, ObjectArray
37+
from crate.client.sqlalchemy.types import ObjectType, ObjectArray
3838

3939

4040
class SqlAlchemyQueryCompilationCaching(TestCase):
@@ -55,7 +55,7 @@ class Character(Base):
5555
__tablename__ = 'characters'
5656
name = sa.Column(sa.String, primary_key=True)
5757
age = sa.Column(sa.Integer)
58-
data = sa.Column(Object)
58+
data = sa.Column(ObjectType)
5959
data_list = sa.Column(ObjectArray)
6060

6161
return Character

src/crate/client/sqlalchemy/tests/update_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from unittest import TestCase
2424
from unittest.mock import patch, MagicMock
2525

26-
from crate.client.sqlalchemy.types import Object
26+
from crate.client.sqlalchemy.types import ObjectType
2727

2828
import sqlalchemy as sa
2929
from sqlalchemy.orm import Session
@@ -52,7 +52,7 @@ class Character(self.base):
5252

5353
name = sa.Column(sa.String, primary_key=True)
5454
age = sa.Column(sa.Integer)
55-
obj = sa.Column(Object)
55+
obj = sa.Column(ObjectType)
5656
ts = sa.Column(sa.DateTime, onupdate=datetime.utcnow)
5757

5858
self.character = Character

0 commit comments

Comments
 (0)