Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SQLAlchemy 2.0 #488

Merged
merged 8 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
fail-fast: false
matrix:
language: [ python ]
sqla-version: ['1.3.24', '1.4.46']
sqla-version: ['1.3.24', '1.4.46', '2.0.0']

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
os: ['ubuntu-latest', 'macos-latest']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
cratedb-version: ['5.2.0']
sqla-version: ['1.3.24', '1.4.46']
sqla-version: ['1.3.24', '1.4.46', '2.0.0']
# To save resources, only use the most recent Python version on macOS.
exclude:
- os: 'macos-latest'
Expand Down
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ Changes for crate
Unreleased
==========

- Add deprecation warning about dropping support for SQLAlchemy 1.3 soon, it is
- Added deprecation warning about dropping support for SQLAlchemy 1.3 soon, it is
effectively EOL.

- Added support for SQLAlchemy 2.0.


2022/12/08 0.29.0
=================
Expand Down
2 changes: 1 addition & 1 deletion docs/by-example/sqlalchemy/crud.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Retrieve

Using the connection to execute a select statement:

>>> result = connection.execute('select name from locations order by name')
>>> result = connection.execute(text('select name from locations order by name'))
>>> result.rowcount
14

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
universal = 1

[flake8]
ignore = E501, C901, W504
ignore = E501, C901, W503, W504
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def read(path):
},
install_requires=['urllib3>=1.9,<3'],
extras_require=dict(
sqlalchemy=['sqlalchemy>=1.0,<1.5',
sqlalchemy=['sqlalchemy>=1.0,<2.1',
'geojson>=2.5.0,<3',
'backports.zoneinfo<1; python_version<"3.9"'],
test=['tox>=3,<4',
Expand Down
7 changes: 7 additions & 0 deletions src/crate/client/sqlalchemy/compat/core10.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# software solely pursuant to the terms of the relevant commercial agreement.

import sqlalchemy as sa
from sqlalchemy.dialects.postgresql.base import PGCompiler
from sqlalchemy.sql.crud import (REQUIRED, _create_bind_param,
_extend_values_for_multiparams,
_get_multitable_params,
Expand All @@ -32,6 +33,12 @@

class CrateCompilerSA10(CrateCompiler):

def returning_clause(self, stmt, returning_cols):
"""
Generate RETURNING clause, PostgreSQL-compatible.
"""
return PGCompiler.returning_clause(self, stmt, returning_cols)

def visit_update(self, update_stmt, **kw):
"""
used to compile <sql.expression.Update> expressions
Expand Down
7 changes: 7 additions & 0 deletions src/crate/client/sqlalchemy/compat/core14.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# software solely pursuant to the terms of the relevant commercial agreement.

import sqlalchemy as sa
from sqlalchemy.dialects.postgresql.base import PGCompiler
from sqlalchemy.sql import selectable
from sqlalchemy.sql.crud import (REQUIRED, _create_bind_param,
_extend_values_for_multiparams,
Expand All @@ -33,6 +34,12 @@

class CrateCompilerSA14(CrateCompiler):

def returning_clause(self, stmt, returning_cols):
"""
Generate RETURNING clause, PostgreSQL-compatible.
"""
return PGCompiler.returning_clause(self, stmt, returning_cols)

def visit_update(self, update_stmt, **kw):

compile_state = update_stmt._compile_state_factory(
Expand Down
Loading