|
1 | 1 | (migrate-from-crate-python)= |
2 | 2 | # Migrate from `crate.client` |
3 | 3 |
|
| 4 | +## Introduction |
4 | 5 | In June 2024, code from the package [crate\[sqlalchemy\]] has been transferred |
5 | 6 | to the package [sqlalchemy-cratedb]. For 80% of use cases, this will be |
6 | 7 | a drop-in replacement with no noticeable changes. |
7 | 8 |
|
8 | | -However, if you use CrateDB's special data types like `OBJECT`, `ARRAY`, |
9 | | -`GEO_POINT`, or `GEO_SHAPE`, and imported the relevant symbols from |
10 | | -`crate.client.sqlalchemy`, you will need to import the same symbols from |
11 | | -`sqlalchemy_cratedb` from now on. |
| 9 | +With the release of `crate-1.0.0` in November 2024, the SQLAlchemy dialect was |
| 10 | +dropped from this package. See the "Upgrade procedure" section for further |
| 11 | +information. |
12 | 12 |
|
13 | 13 | ## Upgrade procedure |
14 | | - |
15 | | -- Swap dependency definition from `crate[sqlalchemy]` to `sqlalchemy-cratedb` |
16 | | - in your `pyproject.toml`, `requirements.txt`, or `setup.py`. |
17 | | -- Adjust symbol imports as outlined below. |
18 | | - |
19 | | -### Symbol import adjustments |
20 | | -```python |
21 | | -# Previous import |
22 | | -# from crate.client.sqlalchemy.dialect import CrateDialect |
23 | | - |
24 | | -# New import |
25 | | -from sqlalchemy_cratedb import dialect |
| 14 | +In order to continue using the CrateDB SQLAlchemy dialect, please install the |
| 15 | +`sqlalchemy-cratedb` package [^1]. |
| 16 | +```shell |
| 17 | +pip install --upgrade sqlalchemy-cratedb |
26 | 18 | ``` |
27 | 19 |
|
28 | | -```python |
29 | | -# Previous import |
30 | | -# from crate.client.sqlalchemy.types import ObjectArray, ObjectType, FloatVector, Geopoint, Geoshape |
31 | | - |
32 | | -# New import |
33 | | -from sqlalchemy_cratedb import ObjectArray, ObjectType, FloatVector, Geopoint, Geoshape |
34 | | -``` |
| 20 | +## Code changes |
| 21 | +If you are using CrateDB's special data types like `OBJECT`, `ARRAY`, |
| 22 | +`GEO_POINT`, or `GEO_SHAPE`, and imported the relevant symbols from |
| 23 | +`crate.client.sqlalchemy` before, you will need to adjust your imports |
| 24 | +to use `sqlalchemy_cratedb` from now on, as outlined below. |
35 | 25 |
|
| 26 | +### Previous imports |
36 | 27 | ```python |
37 | | -# Previous import |
| 28 | +from crate.client.sqlalchemy.dialect import CrateDialect |
| 29 | +from crate.client.sqlalchemy.types import ObjectArray, ObjectType, FloatVector, Geopoint, Geoshape |
| 30 | +from crate.client.sqlalchemy.predicates import match |
38 | 31 | from crate.client.sqlalchemy.compiler import CrateDDLCompiler, CrateTypeCompiler |
39 | | - |
40 | | -# New import |
41 | | -from sqlalchemy_cratedb.compiler import CrateDDLCompiler, CrateTypeCompiler |
42 | 32 | ``` |
43 | 33 |
|
| 34 | +### New imports |
44 | 35 | ```python |
45 | | -# Previous import |
46 | | -# from crate.client.sqlalchemy.predicates import match |
47 | | - |
48 | | -# New import |
| 36 | +from sqlalchemy_cratedb import dialect |
| 37 | +from sqlalchemy_cratedb import ObjectArray, ObjectType, FloatVector, Geopoint, Geoshape |
49 | 38 | from sqlalchemy_cratedb import knn_match, match |
| 39 | +from sqlalchemy_cratedb.compiler import CrateDDLCompiler, CrateTypeCompiler |
50 | 40 | ``` |
51 | 41 |
|
52 | 42 |
|
53 | 43 | [crate\[sqlalchemy\]]: https://pypi.org/project/crate/ |
| 44 | +[d2c42031f]: https://github.com/crate/cratedb-examples/commit/d2c42031f |
54 | 45 | [sqlalchemy-cratedb]: https://pypi.org/project/sqlalchemy-cratedb/ |
| 46 | + |
| 47 | +[^1]: When applicable, please also update your project dependencies to use |
| 48 | +`sqlalchemy-cratedb` in your `pyproject.toml`, `requirements.txt`, or |
| 49 | +`setup.py` files, **instead** of using the previous `crate[sqlalchemy]` |
| 50 | +package. `sqlalchemy-cratedb` lists `crate` as a dependency and will |
| 51 | +automatically pull in the right version. A typical dependency update will |
| 52 | +look like [d2c42031f]. |
0 commit comments