sqlalchemy-adbc 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sqlalchemy_adbc-0.1.0/.github/workflows/ci.yml +42 -0
- sqlalchemy_adbc-0.1.0/.github/workflows/publish.yml +89 -0
- sqlalchemy_adbc-0.1.0/.gitignore +13 -0
- sqlalchemy_adbc-0.1.0/LICENSE +201 -0
- sqlalchemy_adbc-0.1.0/PKG-INFO +162 -0
- sqlalchemy_adbc-0.1.0/README.md +123 -0
- sqlalchemy_adbc-0.1.0/pyproject.toml +75 -0
- sqlalchemy_adbc-0.1.0/src/sqlalchemy_adbc/__init__.py +15 -0
- sqlalchemy_adbc-0.1.0/src/sqlalchemy_adbc/base.py +110 -0
- sqlalchemy_adbc-0.1.0/src/sqlalchemy_adbc/bigquery.py +30 -0
- sqlalchemy_adbc-0.1.0/src/sqlalchemy_adbc/flightsql.py +79 -0
- sqlalchemy_adbc-0.1.0/src/sqlalchemy_adbc/postgresql.py +31 -0
- sqlalchemy_adbc-0.1.0/src/sqlalchemy_adbc/snowflake.py +38 -0
- sqlalchemy_adbc-0.1.0/src/sqlalchemy_adbc/sqlite.py +27 -0
- sqlalchemy_adbc-0.1.0/tests/__init__.py +0 -0
- sqlalchemy_adbc-0.1.0/tests/test_flightsql_url.py +55 -0
- sqlalchemy_adbc-0.1.0/tests/test_sqlite.py +56 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
lint:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.12"
|
|
21
|
+
- name: Install
|
|
22
|
+
run: pip install -e ".[dev]"
|
|
23
|
+
- name: Ruff check
|
|
24
|
+
run: ruff check src/ tests/
|
|
25
|
+
- name: Ruff format
|
|
26
|
+
run: ruff format --check src/ tests/
|
|
27
|
+
|
|
28
|
+
test:
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
strategy:
|
|
31
|
+
fail-fast: false
|
|
32
|
+
matrix:
|
|
33
|
+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@v4
|
|
36
|
+
- uses: actions/setup-python@v5
|
|
37
|
+
with:
|
|
38
|
+
python-version: ${{ matrix.python-version }}
|
|
39
|
+
- name: Install
|
|
40
|
+
run: pip install -e ".[dev]"
|
|
41
|
+
- name: Pytest
|
|
42
|
+
run: pytest tests/ --cov=sqlalchemy_adbc --cov-report=term-missing
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Trusted publishing via OIDC — no API token needed.
|
|
4
|
+
# One-time setup on pypi.org: Account → Publishing → Add a pending publisher
|
|
5
|
+
# Project name: sqlalchemy-adbc
|
|
6
|
+
# Owner: drls-io
|
|
7
|
+
# Repository: sqlalchemy-adbc
|
|
8
|
+
# Workflow: publish.yml
|
|
9
|
+
# Environment: pypi
|
|
10
|
+
# After the first successful publish the pending publisher becomes live.
|
|
11
|
+
|
|
12
|
+
on:
|
|
13
|
+
push:
|
|
14
|
+
tags: ["v*"]
|
|
15
|
+
workflow_dispatch:
|
|
16
|
+
inputs:
|
|
17
|
+
target:
|
|
18
|
+
description: "Publish target"
|
|
19
|
+
type: choice
|
|
20
|
+
default: testpypi
|
|
21
|
+
options: [testpypi, pypi]
|
|
22
|
+
|
|
23
|
+
concurrency:
|
|
24
|
+
group: publish-${{ github.ref }}
|
|
25
|
+
cancel-in-progress: false
|
|
26
|
+
|
|
27
|
+
jobs:
|
|
28
|
+
build:
|
|
29
|
+
name: Build sdist + wheel
|
|
30
|
+
runs-on: ubuntu-latest
|
|
31
|
+
steps:
|
|
32
|
+
- uses: actions/checkout@v4
|
|
33
|
+
- uses: actions/setup-python@v5
|
|
34
|
+
with:
|
|
35
|
+
python-version: "3.12"
|
|
36
|
+
- name: Install build tooling
|
|
37
|
+
run: pip install --upgrade pip build
|
|
38
|
+
- name: Verify tag matches pyproject version (tag pushes only)
|
|
39
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
40
|
+
run: |
|
|
41
|
+
TAG="${GITHUB_REF#refs/tags/v}"
|
|
42
|
+
VER=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
|
|
43
|
+
if [ "$TAG" != "$VER" ]; then
|
|
44
|
+
echo "::error::Tag v$TAG does not match pyproject.toml version $VER"
|
|
45
|
+
exit 1
|
|
46
|
+
fi
|
|
47
|
+
- name: Build
|
|
48
|
+
run: python -m build
|
|
49
|
+
- name: Upload artifacts
|
|
50
|
+
uses: actions/upload-artifact@v4
|
|
51
|
+
with:
|
|
52
|
+
name: dist
|
|
53
|
+
path: dist/
|
|
54
|
+
|
|
55
|
+
publish-testpypi:
|
|
56
|
+
name: Publish to TestPyPI
|
|
57
|
+
needs: build
|
|
58
|
+
if: github.event_name == 'workflow_dispatch' && inputs.target == 'testpypi'
|
|
59
|
+
runs-on: ubuntu-latest
|
|
60
|
+
environment:
|
|
61
|
+
name: testpypi
|
|
62
|
+
url: https://test.pypi.org/p/sqlalchemy-adbc
|
|
63
|
+
permissions:
|
|
64
|
+
id-token: write
|
|
65
|
+
steps:
|
|
66
|
+
- uses: actions/download-artifact@v4
|
|
67
|
+
with:
|
|
68
|
+
name: dist
|
|
69
|
+
path: dist/
|
|
70
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
71
|
+
with:
|
|
72
|
+
repository-url: https://test.pypi.org/legacy/
|
|
73
|
+
|
|
74
|
+
publish-pypi:
|
|
75
|
+
name: Publish to PyPI
|
|
76
|
+
needs: build
|
|
77
|
+
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.target == 'pypi')
|
|
78
|
+
runs-on: ubuntu-latest
|
|
79
|
+
environment:
|
|
80
|
+
name: pypi
|
|
81
|
+
url: https://pypi.org/p/sqlalchemy-adbc
|
|
82
|
+
permissions:
|
|
83
|
+
id-token: write
|
|
84
|
+
steps:
|
|
85
|
+
- uses: actions/download-artifact@v4
|
|
86
|
+
with:
|
|
87
|
+
name: dist
|
|
88
|
+
path: dist/
|
|
89
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sqlalchemy-adbc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Generic SQLAlchemy dialect for any ADBC driver (Flight SQL, PostgreSQL, SQLite, Snowflake, BigQuery).
|
|
5
|
+
Project-URL: Homepage, https://github.com/drls-io/sqlalchemy-adbc
|
|
6
|
+
Project-URL: Repository, https://github.com/drls-io/sqlalchemy-adbc
|
|
7
|
+
Project-URL: Issues, https://github.com/drls-io/sqlalchemy-adbc/issues
|
|
8
|
+
Author: DRLS Contributors
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: adbc,arrow,dialect,flight-sql,sqlalchemy
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Database
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Requires-Dist: adbc-driver-manager>=1.0
|
|
20
|
+
Requires-Dist: pyarrow>=14.0
|
|
21
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
22
|
+
Provides-Extra: bigquery
|
|
23
|
+
Requires-Dist: adbc-driver-bigquery>=1.0; extra == 'bigquery'
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: adbc-driver-sqlite>=1.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
30
|
+
Provides-Extra: flightsql
|
|
31
|
+
Requires-Dist: adbc-driver-flightsql>=1.0; extra == 'flightsql'
|
|
32
|
+
Provides-Extra: postgresql
|
|
33
|
+
Requires-Dist: adbc-driver-postgresql>=1.0; extra == 'postgresql'
|
|
34
|
+
Provides-Extra: snowflake
|
|
35
|
+
Requires-Dist: adbc-driver-snowflake>=1.0; extra == 'snowflake'
|
|
36
|
+
Provides-Extra: sqlite
|
|
37
|
+
Requires-Dist: adbc-driver-sqlite>=1.0; extra == 'sqlite'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# sqlalchemy-adbc
|
|
41
|
+
|
|
42
|
+
[](https://pypi.org/project/sqlalchemy-adbc/)
|
|
43
|
+
[](LICENSE)
|
|
44
|
+
|
|
45
|
+
Generic [SQLAlchemy](https://www.sqlalchemy.org/) dialect for any
|
|
46
|
+
[Apache Arrow ADBC](https://arrow.apache.org/adbc/) driver — so any tool that
|
|
47
|
+
speaks SQLAlchemy (pandas, marimo, Superset, dbt, Polars) can read and write
|
|
48
|
+
against Flight SQL, PostgreSQL, SQLite, Snowflake, and BigQuery through the
|
|
49
|
+
Arrow-native wire path.
|
|
50
|
+
|
|
51
|
+
## Why this exists
|
|
52
|
+
|
|
53
|
+
ADBC drivers speak Python DBAPI and return results as Arrow record batches —
|
|
54
|
+
zero per-row materialization, no driver-specific JDBC/ODBC install. But most
|
|
55
|
+
of the Python ecosystem wires into databases through SQLAlchemy, and ADBC
|
|
56
|
+
doesn't ship a dialect. This package is a thin translation layer: SQLAlchemy
|
|
57
|
+
URL → ADBC `db_kwargs` → DBAPI connection.
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install sqlalchemy-adbc
|
|
63
|
+
|
|
64
|
+
# With a driver extra:
|
|
65
|
+
pip install "sqlalchemy-adbc[flightsql]"
|
|
66
|
+
pip install "sqlalchemy-adbc[postgresql]"
|
|
67
|
+
pip install "sqlalchemy-adbc[sqlite]"
|
|
68
|
+
pip install "sqlalchemy-adbc[snowflake]"
|
|
69
|
+
pip install "sqlalchemy-adbc[bigquery]"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Quickstart
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import sqlalchemy
|
|
76
|
+
|
|
77
|
+
# Flight SQL
|
|
78
|
+
engine = sqlalchemy.create_engine(
|
|
79
|
+
"adbc+flightsql://flight-sql.example.com:443?tls=true",
|
|
80
|
+
connect_args={"db_kwargs": {
|
|
81
|
+
"adbc.flight.sql.authorization_header": f"Bearer {token}",
|
|
82
|
+
}},
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# SQLite
|
|
86
|
+
engine = sqlalchemy.create_engine("adbc+sqlite:///path/to/db.sqlite")
|
|
87
|
+
|
|
88
|
+
# PostgreSQL
|
|
89
|
+
engine = sqlalchemy.create_engine(
|
|
90
|
+
"adbc+postgresql://user:pass@host:5432/mydb"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# Works with pandas, Polars, marimo SQL cells, etc.
|
|
94
|
+
import pandas as pd
|
|
95
|
+
df = pd.read_sql("SELECT 1 AS n", engine)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## URL forms
|
|
99
|
+
|
|
100
|
+
| Driver | URL |
|
|
101
|
+
|--------------|------------------------------------------------------------|
|
|
102
|
+
| Flight SQL | `adbc+flightsql://host:port?tls=true&authorization=...` |
|
|
103
|
+
| Flight SQL | `adbc+flightsql://user:TOKEN@host:port?tls=true` (bearer) |
|
|
104
|
+
| PostgreSQL | `adbc+postgresql://user:pass@host:port/database` |
|
|
105
|
+
| SQLite | `adbc+sqlite:///path/to/db` or `adbc+sqlite:///:memory:` |
|
|
106
|
+
| Snowflake | `adbc+snowflake://user:pass@account/db/schema?warehouse=W` |
|
|
107
|
+
| BigQuery | `adbc+bigquery:///my-project?dataset=my_dataset` |
|
|
108
|
+
|
|
109
|
+
### Flight SQL query-string options
|
|
110
|
+
|
|
111
|
+
| Key | Meaning |
|
|
112
|
+
|---------------------|----------------------------------------------------|
|
|
113
|
+
| `tls=true` | Use `grpc+tls://` instead of `grpc://` |
|
|
114
|
+
| `authorization=...` | Sets the ADBC `AUTHORIZATION_HEADER` db_kwarg |
|
|
115
|
+
| `header.<name>=<v>` | Forwarded via ADBC's `RPC_CALL_HEADER_PREFIX` |
|
|
116
|
+
| (any other key) | Passed through as a db_kwarg verbatim |
|
|
117
|
+
|
|
118
|
+
## Status
|
|
119
|
+
|
|
120
|
+
Alpha — the core dialect machinery works for simple `SELECT` / `INSERT` /
|
|
121
|
+
`CREATE TABLE` use. More advanced SQLAlchemy features (table reflection,
|
|
122
|
+
dialect-specific types, DDL compilers per backend) are still to come. PRs
|
|
123
|
+
welcome.
|
|
124
|
+
|
|
125
|
+
Ship tests: 11 passing against ADBC SQLite on Python 3.9–3.13.
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
git clone https://github.com/drls-io/sqlalchemy-adbc
|
|
131
|
+
cd sqlalchemy-adbc
|
|
132
|
+
python3 -m venv .venv && source .venv/bin/activate
|
|
133
|
+
pip install -e ".[dev]"
|
|
134
|
+
pytest
|
|
135
|
+
ruff check src/ tests/
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Releasing
|
|
139
|
+
|
|
140
|
+
Publishing is automated via [PyPI trusted publishing](https://docs.pypi.org/trusted-publishers/)
|
|
141
|
+
(OIDC, no API tokens). One-time setup on pypi.org: add a *pending publisher*
|
|
142
|
+
for project `sqlalchemy-adbc`, owner `drls-io`, repository `sqlalchemy-adbc`,
|
|
143
|
+
workflow `publish.yml`, environment `pypi`. Same for TestPyPI if you want
|
|
144
|
+
dry-runs.
|
|
145
|
+
|
|
146
|
+
Cutting a release:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# 1. Bump version in pyproject.toml
|
|
150
|
+
# 2. Commit, tag, push
|
|
151
|
+
git commit -am "chore: release v0.1.1"
|
|
152
|
+
git tag v0.1.1
|
|
153
|
+
git push && git push --tags
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The `Publish to PyPI` workflow fires on the tag, builds sdist+wheel, and
|
|
157
|
+
uploads to pypi.org. For TestPyPI dry-runs use `workflow_dispatch` with
|
|
158
|
+
target `testpypi`.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# sqlalchemy-adbc
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/sqlalchemy-adbc/)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
Generic [SQLAlchemy](https://www.sqlalchemy.org/) dialect for any
|
|
7
|
+
[Apache Arrow ADBC](https://arrow.apache.org/adbc/) driver — so any tool that
|
|
8
|
+
speaks SQLAlchemy (pandas, marimo, Superset, dbt, Polars) can read and write
|
|
9
|
+
against Flight SQL, PostgreSQL, SQLite, Snowflake, and BigQuery through the
|
|
10
|
+
Arrow-native wire path.
|
|
11
|
+
|
|
12
|
+
## Why this exists
|
|
13
|
+
|
|
14
|
+
ADBC drivers speak Python DBAPI and return results as Arrow record batches —
|
|
15
|
+
zero per-row materialization, no driver-specific JDBC/ODBC install. But most
|
|
16
|
+
of the Python ecosystem wires into databases through SQLAlchemy, and ADBC
|
|
17
|
+
doesn't ship a dialect. This package is a thin translation layer: SQLAlchemy
|
|
18
|
+
URL → ADBC `db_kwargs` → DBAPI connection.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install sqlalchemy-adbc
|
|
24
|
+
|
|
25
|
+
# With a driver extra:
|
|
26
|
+
pip install "sqlalchemy-adbc[flightsql]"
|
|
27
|
+
pip install "sqlalchemy-adbc[postgresql]"
|
|
28
|
+
pip install "sqlalchemy-adbc[sqlite]"
|
|
29
|
+
pip install "sqlalchemy-adbc[snowflake]"
|
|
30
|
+
pip install "sqlalchemy-adbc[bigquery]"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quickstart
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import sqlalchemy
|
|
37
|
+
|
|
38
|
+
# Flight SQL
|
|
39
|
+
engine = sqlalchemy.create_engine(
|
|
40
|
+
"adbc+flightsql://flight-sql.example.com:443?tls=true",
|
|
41
|
+
connect_args={"db_kwargs": {
|
|
42
|
+
"adbc.flight.sql.authorization_header": f"Bearer {token}",
|
|
43
|
+
}},
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# SQLite
|
|
47
|
+
engine = sqlalchemy.create_engine("adbc+sqlite:///path/to/db.sqlite")
|
|
48
|
+
|
|
49
|
+
# PostgreSQL
|
|
50
|
+
engine = sqlalchemy.create_engine(
|
|
51
|
+
"adbc+postgresql://user:pass@host:5432/mydb"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# Works with pandas, Polars, marimo SQL cells, etc.
|
|
55
|
+
import pandas as pd
|
|
56
|
+
df = pd.read_sql("SELECT 1 AS n", engine)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## URL forms
|
|
60
|
+
|
|
61
|
+
| Driver | URL |
|
|
62
|
+
|--------------|------------------------------------------------------------|
|
|
63
|
+
| Flight SQL | `adbc+flightsql://host:port?tls=true&authorization=...` |
|
|
64
|
+
| Flight SQL | `adbc+flightsql://user:TOKEN@host:port?tls=true` (bearer) |
|
|
65
|
+
| PostgreSQL | `adbc+postgresql://user:pass@host:port/database` |
|
|
66
|
+
| SQLite | `adbc+sqlite:///path/to/db` or `adbc+sqlite:///:memory:` |
|
|
67
|
+
| Snowflake | `adbc+snowflake://user:pass@account/db/schema?warehouse=W` |
|
|
68
|
+
| BigQuery | `adbc+bigquery:///my-project?dataset=my_dataset` |
|
|
69
|
+
|
|
70
|
+
### Flight SQL query-string options
|
|
71
|
+
|
|
72
|
+
| Key | Meaning |
|
|
73
|
+
|---------------------|----------------------------------------------------|
|
|
74
|
+
| `tls=true` | Use `grpc+tls://` instead of `grpc://` |
|
|
75
|
+
| `authorization=...` | Sets the ADBC `AUTHORIZATION_HEADER` db_kwarg |
|
|
76
|
+
| `header.<name>=<v>` | Forwarded via ADBC's `RPC_CALL_HEADER_PREFIX` |
|
|
77
|
+
| (any other key) | Passed through as a db_kwarg verbatim |
|
|
78
|
+
|
|
79
|
+
## Status
|
|
80
|
+
|
|
81
|
+
Alpha — the core dialect machinery works for simple `SELECT` / `INSERT` /
|
|
82
|
+
`CREATE TABLE` use. More advanced SQLAlchemy features (table reflection,
|
|
83
|
+
dialect-specific types, DDL compilers per backend) are still to come. PRs
|
|
84
|
+
welcome.
|
|
85
|
+
|
|
86
|
+
Ship tests: 11 passing against ADBC SQLite on Python 3.9–3.13.
|
|
87
|
+
|
|
88
|
+
## Development
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
git clone https://github.com/drls-io/sqlalchemy-adbc
|
|
92
|
+
cd sqlalchemy-adbc
|
|
93
|
+
python3 -m venv .venv && source .venv/bin/activate
|
|
94
|
+
pip install -e ".[dev]"
|
|
95
|
+
pytest
|
|
96
|
+
ruff check src/ tests/
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Releasing
|
|
100
|
+
|
|
101
|
+
Publishing is automated via [PyPI trusted publishing](https://docs.pypi.org/trusted-publishers/)
|
|
102
|
+
(OIDC, no API tokens). One-time setup on pypi.org: add a *pending publisher*
|
|
103
|
+
for project `sqlalchemy-adbc`, owner `drls-io`, repository `sqlalchemy-adbc`,
|
|
104
|
+
workflow `publish.yml`, environment `pypi`. Same for TestPyPI if you want
|
|
105
|
+
dry-runs.
|
|
106
|
+
|
|
107
|
+
Cutting a release:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# 1. Bump version in pyproject.toml
|
|
111
|
+
# 2. Commit, tag, push
|
|
112
|
+
git commit -am "chore: release v0.1.1"
|
|
113
|
+
git tag v0.1.1
|
|
114
|
+
git push && git push --tags
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The `Publish to PyPI` workflow fires on the tag, builds sdist+wheel, and
|
|
118
|
+
uploads to pypi.org. For TestPyPI dry-runs use `workflow_dispatch` with
|
|
119
|
+
target `testpypi`.
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sqlalchemy-adbc"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Generic SQLAlchemy dialect for any ADBC driver (Flight SQL, PostgreSQL, SQLite, Snowflake, BigQuery)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "Apache-2.0" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [{ name = "DRLS Contributors" }]
|
|
13
|
+
keywords = ["sqlalchemy", "adbc", "arrow", "flight-sql", "dialect"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: Apache Software License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Topic :: Database",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"sqlalchemy>=2.0",
|
|
24
|
+
"adbc-driver-manager>=1.0",
|
|
25
|
+
# ADBC returns results as Arrow record batches; the driver-manager
|
|
26
|
+
# needs a PyArrow (or equivalent) backend installed to materialize
|
|
27
|
+
# them through DBAPI. Without it, `cursor.fetchall()` raises a
|
|
28
|
+
# ProgrammingError.
|
|
29
|
+
"pyarrow>=14.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
flightsql = ["adbc-driver-flightsql>=1.0"]
|
|
34
|
+
postgresql = ["adbc-driver-postgresql>=1.0"]
|
|
35
|
+
sqlite = ["adbc-driver-sqlite>=1.0"]
|
|
36
|
+
snowflake = ["adbc-driver-snowflake>=1.0"]
|
|
37
|
+
bigquery = ["adbc-driver-bigquery>=1.0"]
|
|
38
|
+
dev = [
|
|
39
|
+
"pytest>=8.0",
|
|
40
|
+
"pytest-cov>=5.0",
|
|
41
|
+
"ruff>=0.6",
|
|
42
|
+
"mypy>=1.10",
|
|
43
|
+
"adbc-driver-sqlite>=1.0",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[project.urls]
|
|
47
|
+
Homepage = "https://github.com/drls-io/sqlalchemy-adbc"
|
|
48
|
+
Repository = "https://github.com/drls-io/sqlalchemy-adbc"
|
|
49
|
+
Issues = "https://github.com/drls-io/sqlalchemy-adbc/issues"
|
|
50
|
+
|
|
51
|
+
# SQLAlchemy discovers dialects via the `sqlalchemy.dialects` entry point
|
|
52
|
+
# group. The name form is `<name>` or `<name>.<driver>` — the second is what
|
|
53
|
+
# lets us write `adbc+flightsql://` etc.
|
|
54
|
+
[project.entry-points."sqlalchemy.dialects"]
|
|
55
|
+
"adbc" = "sqlalchemy_adbc.base:ADBCDialect"
|
|
56
|
+
"adbc.flightsql" = "sqlalchemy_adbc.flightsql:ADBCFlightSQLDialect"
|
|
57
|
+
"adbc.sqlite" = "sqlalchemy_adbc.sqlite:ADBCSQLiteDialect"
|
|
58
|
+
"adbc.postgresql" = "sqlalchemy_adbc.postgresql:ADBCPostgreSQLDialect"
|
|
59
|
+
"adbc.snowflake" = "sqlalchemy_adbc.snowflake:ADBCSnowflakeDialect"
|
|
60
|
+
"adbc.bigquery" = "sqlalchemy_adbc.bigquery:ADBCBigQueryDialect"
|
|
61
|
+
|
|
62
|
+
[tool.hatch.build.targets.wheel]
|
|
63
|
+
packages = ["src/sqlalchemy_adbc"]
|
|
64
|
+
|
|
65
|
+
[tool.ruff]
|
|
66
|
+
line-length = 100
|
|
67
|
+
target-version = "py39"
|
|
68
|
+
|
|
69
|
+
[tool.ruff.lint]
|
|
70
|
+
select = ["E", "F", "W", "I", "B", "UP"]
|
|
71
|
+
ignore = ["E501"]
|
|
72
|
+
|
|
73
|
+
[tool.pytest.ini_options]
|
|
74
|
+
testpaths = ["tests"]
|
|
75
|
+
addopts = "-v"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""sqlalchemy-adbc — Generic SQLAlchemy dialect for any ADBC driver.
|
|
2
|
+
|
|
3
|
+
Register dialects via the ``sqlalchemy.dialects`` entry-point group (see
|
|
4
|
+
pyproject.toml). URL forms::
|
|
5
|
+
|
|
6
|
+
adbc+flightsql://host:port/...?tls=true
|
|
7
|
+
adbc+sqlite:///path/to/db.sqlite
|
|
8
|
+
adbc+postgresql://user:pass@host:port/db
|
|
9
|
+
adbc+snowflake://user:pass@account/db/schema?warehouse=WH
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from sqlalchemy_adbc.base import ADBCDialect
|
|
13
|
+
|
|
14
|
+
__all__ = ["ADBCDialect", "__version__"]
|
|
15
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Base ADBC dialect.
|
|
2
|
+
|
|
3
|
+
ADBC exposes a DBAPI 2.0 interface via ``adbc_driver_manager.dbapi``.
|
|
4
|
+
Each concrete driver (flightsql, postgresql, sqlite, ...) is a thin
|
|
5
|
+
subclass that tells the base dialect which driver module to load and
|
|
6
|
+
how to translate a SQLAlchemy URL into the ``db_kwargs`` that driver
|
|
7
|
+
expects.
|
|
8
|
+
|
|
9
|
+
Subclasses implement:
|
|
10
|
+
- ``driver_module`` — dotted path to the driver's dbapi module
|
|
11
|
+
(e.g., ``"adbc_driver_flightsql.dbapi"``).
|
|
12
|
+
- ``build_connect_args(url)`` — returns ``(args, kwargs)`` passed to
|
|
13
|
+
``driver.connect(*args, **kwargs)``.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import importlib
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
from sqlalchemy.engine.default import DefaultDialect
|
|
22
|
+
from sqlalchemy.engine.url import URL
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ADBCDialect(DefaultDialect):
|
|
26
|
+
"""Base class for SQLAlchemy dialects backed by ADBC drivers.
|
|
27
|
+
|
|
28
|
+
This class is registered as the plain ``adbc://`` scheme. In practice
|
|
29
|
+
callers should use a driver-specific variant like ``adbc+flightsql://``;
|
|
30
|
+
the plain scheme requires ``adbc_driver_name`` in the URL query string.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
name = "adbc"
|
|
34
|
+
driver = "adbc"
|
|
35
|
+
supports_statement_cache = True
|
|
36
|
+
supports_sane_rowcount = False
|
|
37
|
+
supports_sane_multi_rowcount = False
|
|
38
|
+
|
|
39
|
+
# ADBC drivers speak Python DBAPI, so the SQL dialect defaults are
|
|
40
|
+
# close to "generic SQL-92". Subclasses override as needed.
|
|
41
|
+
paramstyle = "qmark"
|
|
42
|
+
|
|
43
|
+
driver_module: str | None = None
|
|
44
|
+
"""Dotted path to the concrete ADBC driver's ``.dbapi`` module.
|
|
45
|
+
|
|
46
|
+
Must be set by subclasses (e.g., ``adbc_driver_flightsql.dbapi``).
|
|
47
|
+
The base class reads ``adbc_driver_name`` from the URL query string
|
|
48
|
+
when this is None — useful for generic ``adbc://`` URLs.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
@classmethod
|
|
52
|
+
def import_dbapi(cls) -> Any:
|
|
53
|
+
"""Return the DBAPI module for this dialect."""
|
|
54
|
+
module_name = cls.driver_module
|
|
55
|
+
if module_name is None:
|
|
56
|
+
raise RuntimeError(
|
|
57
|
+
"ADBCDialect subclass must set driver_module, "
|
|
58
|
+
"or URL must specify ?adbc_driver_name=... (not yet implemented)"
|
|
59
|
+
)
|
|
60
|
+
return importlib.import_module(module_name)
|
|
61
|
+
|
|
62
|
+
def create_connect_args(self, url: URL) -> tuple[list[Any], dict[str, Any]]:
|
|
63
|
+
"""Translate a SQLAlchemy URL into ``(args, kwargs)`` for ADBC.
|
|
64
|
+
|
|
65
|
+
Subclasses should override ``build_connect_args`` instead of this.
|
|
66
|
+
"""
|
|
67
|
+
return self.build_connect_args(url)
|
|
68
|
+
|
|
69
|
+
def build_connect_args(self, url: URL) -> tuple[list[Any], dict[str, Any]]:
|
|
70
|
+
"""Hook for subclasses to translate a URL to driver connect args.
|
|
71
|
+
|
|
72
|
+
Default implementation forwards ``url.query`` as ``db_kwargs`` and
|
|
73
|
+
uses ``url.database`` (plus host/port when present) as the URI —
|
|
74
|
+
the shape ADBC drivers like ``adbc_driver_flightsql`` expect.
|
|
75
|
+
"""
|
|
76
|
+
db_kwargs = dict(url.query)
|
|
77
|
+
uri = self._format_uri(url)
|
|
78
|
+
args: list[Any] = [uri] if uri else []
|
|
79
|
+
kwargs: dict[str, Any] = {}
|
|
80
|
+
if db_kwargs:
|
|
81
|
+
kwargs["db_kwargs"] = db_kwargs
|
|
82
|
+
return args, kwargs
|
|
83
|
+
|
|
84
|
+
def _format_uri(self, url: URL) -> str | None:
|
|
85
|
+
"""Default URI formatter — joins host/port/database.
|
|
86
|
+
|
|
87
|
+
Subclasses (FlightSQL, Snowflake) override to inject scheme-specific
|
|
88
|
+
prefixes like ``grpc+tls://``.
|
|
89
|
+
"""
|
|
90
|
+
if url.host and url.port:
|
|
91
|
+
base = f"{url.host}:{url.port}"
|
|
92
|
+
elif url.host:
|
|
93
|
+
base = url.host
|
|
94
|
+
elif url.database:
|
|
95
|
+
return url.database
|
|
96
|
+
else:
|
|
97
|
+
return None
|
|
98
|
+
if url.database:
|
|
99
|
+
return f"{base}/{url.database}"
|
|
100
|
+
return base
|
|
101
|
+
|
|
102
|
+
def do_ping(self, dbapi_connection: Any) -> bool:
|
|
103
|
+
"""Liveness probe — run a trivial statement on the connection."""
|
|
104
|
+
cursor = dbapi_connection.cursor()
|
|
105
|
+
try:
|
|
106
|
+
cursor.execute("SELECT 1")
|
|
107
|
+
cursor.fetchall()
|
|
108
|
+
finally:
|
|
109
|
+
cursor.close()
|
|
110
|
+
return True
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""ADBC BigQuery dialect.
|
|
2
|
+
|
|
3
|
+
URL form::
|
|
4
|
+
|
|
5
|
+
adbc+bigquery:///<project>?dataset=<dataset>&credentials_path=/path/to/sa.json
|
|
6
|
+
|
|
7
|
+
adbc_driver_bigquery reads the GCP project and optional dataset via
|
|
8
|
+
db_kwargs; we pass the URL query string through verbatim.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from sqlalchemy.engine.url import URL
|
|
16
|
+
|
|
17
|
+
from sqlalchemy_adbc.base import ADBCDialect
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ADBCBigQueryDialect(ADBCDialect):
|
|
21
|
+
name = "adbc"
|
|
22
|
+
driver = "bigquery"
|
|
23
|
+
driver_module = "adbc_driver_bigquery.dbapi"
|
|
24
|
+
supports_statement_cache = True
|
|
25
|
+
|
|
26
|
+
def build_connect_args(self, url: URL) -> tuple[list[Any], dict[str, Any]]:
|
|
27
|
+
db_kwargs: dict[str, Any] = dict(url.query)
|
|
28
|
+
if url.database:
|
|
29
|
+
db_kwargs.setdefault("adbc.bigquery.sql.project_id", url.database)
|
|
30
|
+
return [], {"db_kwargs": db_kwargs} if db_kwargs else {}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""ADBC Flight SQL dialect.
|
|
2
|
+
|
|
3
|
+
URL form::
|
|
4
|
+
|
|
5
|
+
adbc+flightsql://host:port?tls=true&authorization=Bearer%20...
|
|
6
|
+
|
|
7
|
+
All query-string keys are forwarded to the driver as ``db_kwargs``. The
|
|
8
|
+
dialect also understands a few shorthands:
|
|
9
|
+
|
|
10
|
+
- ``tls=true`` → use ``grpc+tls://`` scheme (default is ``grpc://``)
|
|
11
|
+
- ``authorization=...`` → canonicalised to the ADBC ``AUTHORIZATION_HEADER``
|
|
12
|
+
db_kwarg (matches ``adbc_driver_flightsql.DatabaseOptions``).
|
|
13
|
+
- ``header.<name>=<value>`` → forwarded via the RPC header prefix.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from sqlalchemy.engine.url import URL
|
|
21
|
+
|
|
22
|
+
from sqlalchemy_adbc.base import ADBCDialect
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ADBCFlightSQLDialect(ADBCDialect):
|
|
26
|
+
name = "adbc"
|
|
27
|
+
driver = "flightsql"
|
|
28
|
+
driver_module = "adbc_driver_flightsql.dbapi"
|
|
29
|
+
supports_statement_cache = True
|
|
30
|
+
|
|
31
|
+
def build_connect_args(self, url: URL) -> tuple[list[Any], dict[str, Any]]:
|
|
32
|
+
query = dict(url.query)
|
|
33
|
+
|
|
34
|
+
scheme = "grpc+tls" if _pop_bool(query, "tls", default=False) else "grpc"
|
|
35
|
+
host = url.host or "localhost"
|
|
36
|
+
port = url.port or 443
|
|
37
|
+
uri = f"{scheme}://{host}:{port}"
|
|
38
|
+
|
|
39
|
+
db_kwargs: dict[str, str] = {}
|
|
40
|
+
|
|
41
|
+
# Lazy import keeps the package installable without the driver
|
|
42
|
+
# extra — tests and IDE tooling shouldn't have to pull the
|
|
43
|
+
# flightsql wheel.
|
|
44
|
+
try:
|
|
45
|
+
from adbc_driver_flightsql import DatabaseOptions # type: ignore[import-not-found]
|
|
46
|
+
|
|
47
|
+
auth_key = DatabaseOptions.AUTHORIZATION_HEADER.value
|
|
48
|
+
header_prefix = DatabaseOptions.RPC_CALL_HEADER_PREFIX.value
|
|
49
|
+
except ImportError: # pragma: no cover - hit only without extra
|
|
50
|
+
auth_key = "adbc.flight.sql.authorization_header"
|
|
51
|
+
header_prefix = "adbc.flight.sql.rpc.call_header."
|
|
52
|
+
|
|
53
|
+
if "authorization" in query:
|
|
54
|
+
db_kwargs[auth_key] = query.pop("authorization")
|
|
55
|
+
|
|
56
|
+
# Caller can also set the bearer via SQLAlchemy URL password:
|
|
57
|
+
# adbc+flightsql://user:<token>@host:443?tls=true
|
|
58
|
+
# The "user" part is ignored by Flight SQL; we just read the
|
|
59
|
+
# password into the Authorization header.
|
|
60
|
+
if url.password:
|
|
61
|
+
db_kwargs[auth_key] = f"Bearer {url.password}"
|
|
62
|
+
|
|
63
|
+
# header.x-workspace-id=abc → <prefix>x-workspace-id: abc
|
|
64
|
+
for key in list(query.keys()):
|
|
65
|
+
if key.startswith("header."):
|
|
66
|
+
db_kwargs[f"{header_prefix}{key[len('header.') :]}"] = query.pop(key)
|
|
67
|
+
|
|
68
|
+
# Anything left in the query string is passed through verbatim —
|
|
69
|
+
# useful for driver-specific options we don't know about.
|
|
70
|
+
db_kwargs.update(query)
|
|
71
|
+
|
|
72
|
+
return [uri], {"db_kwargs": db_kwargs} if db_kwargs else {}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _pop_bool(d: dict[str, Any], key: str, *, default: bool) -> bool:
|
|
76
|
+
if key not in d:
|
|
77
|
+
return default
|
|
78
|
+
v = d.pop(key)
|
|
79
|
+
return str(v).lower() in {"1", "true", "yes", "on"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""ADBC PostgreSQL dialect."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from sqlalchemy.engine.url import URL
|
|
8
|
+
|
|
9
|
+
from sqlalchemy_adbc.base import ADBCDialect
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ADBCPostgreSQLDialect(ADBCDialect):
|
|
13
|
+
name = "adbc"
|
|
14
|
+
driver = "postgresql"
|
|
15
|
+
driver_module = "adbc_driver_postgresql.dbapi"
|
|
16
|
+
supports_statement_cache = True
|
|
17
|
+
|
|
18
|
+
def build_connect_args(self, url: URL) -> tuple[list[Any], dict[str, Any]]:
|
|
19
|
+
# adbc_driver_postgresql expects a standard libpq URI.
|
|
20
|
+
user = url.username or ""
|
|
21
|
+
password = f":{url.password}" if url.password else ""
|
|
22
|
+
auth = f"{user}{password}@" if user else ""
|
|
23
|
+
host = url.host or "localhost"
|
|
24
|
+
port = f":{url.port}" if url.port else ""
|
|
25
|
+
database = f"/{url.database}" if url.database else ""
|
|
26
|
+
uri = f"postgresql://{auth}{host}{port}{database}"
|
|
27
|
+
|
|
28
|
+
kwargs: dict[str, Any] = {}
|
|
29
|
+
if url.query:
|
|
30
|
+
kwargs["db_kwargs"] = dict(url.query)
|
|
31
|
+
return [uri], kwargs
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""ADBC Snowflake dialect.
|
|
2
|
+
|
|
3
|
+
URL form::
|
|
4
|
+
|
|
5
|
+
adbc+snowflake://user:password@account/database/schema?warehouse=WH&role=R
|
|
6
|
+
|
|
7
|
+
adbc_driver_snowflake expects a DSN of the form
|
|
8
|
+
``user:password@account/database/schema?warehouse=...``.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from sqlalchemy.engine.url import URL
|
|
16
|
+
|
|
17
|
+
from sqlalchemy_adbc.base import ADBCDialect
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ADBCSnowflakeDialect(ADBCDialect):
|
|
21
|
+
name = "adbc"
|
|
22
|
+
driver = "snowflake"
|
|
23
|
+
driver_module = "adbc_driver_snowflake.dbapi"
|
|
24
|
+
supports_statement_cache = True
|
|
25
|
+
|
|
26
|
+
def build_connect_args(self, url: URL) -> tuple[list[Any], dict[str, Any]]:
|
|
27
|
+
user = url.username or ""
|
|
28
|
+
password = f":{url.password}" if url.password else ""
|
|
29
|
+
auth = f"{user}{password}@" if user else ""
|
|
30
|
+
account = url.host or ""
|
|
31
|
+
path = ""
|
|
32
|
+
if url.database:
|
|
33
|
+
path = f"/{url.database}"
|
|
34
|
+
query_str = ""
|
|
35
|
+
if url.query:
|
|
36
|
+
query_str = "?" + "&".join(f"{k}={v}" for k, v in url.query.items())
|
|
37
|
+
dsn = f"{auth}{account}{path}{query_str}"
|
|
38
|
+
return [dsn], {}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""ADBC SQLite dialect — mostly useful for tests and local prototyping."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from sqlalchemy.engine.url import URL
|
|
8
|
+
|
|
9
|
+
from sqlalchemy_adbc.base import ADBCDialect
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ADBCSQLiteDialect(ADBCDialect):
|
|
13
|
+
name = "adbc"
|
|
14
|
+
driver = "sqlite"
|
|
15
|
+
driver_module = "adbc_driver_sqlite.dbapi"
|
|
16
|
+
supports_statement_cache = True
|
|
17
|
+
|
|
18
|
+
# SQLite's DBAPI is qmark; matches our base default.
|
|
19
|
+
paramstyle = "qmark"
|
|
20
|
+
|
|
21
|
+
def build_connect_args(self, url: URL) -> tuple[list[Any], dict[str, Any]]:
|
|
22
|
+
# adbc_driver_sqlite.dbapi.connect(uri=":memory:") — takes a filename.
|
|
23
|
+
database = url.database or ":memory:"
|
|
24
|
+
kwargs: dict[str, Any] = {"uri": database}
|
|
25
|
+
if url.query:
|
|
26
|
+
kwargs["db_kwargs"] = dict(url.query)
|
|
27
|
+
return [], kwargs
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Unit tests for the Flight SQL URL → ADBC kwargs translation.
|
|
2
|
+
|
|
3
|
+
These tests do not open a connection, so they don't require an
|
|
4
|
+
``adbc_driver_flightsql`` install — they just verify we translate
|
|
5
|
+
SQLAlchemy URLs to the expected driver args.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from sqlalchemy.engine.url import make_url
|
|
11
|
+
|
|
12
|
+
from sqlalchemy_adbc.flightsql import ADBCFlightSQLDialect
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _build(url_str: str):
|
|
16
|
+
return ADBCFlightSQLDialect().build_connect_args(make_url(url_str))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_plain_grpc():
|
|
20
|
+
args, kwargs = _build("adbc+flightsql://localhost:50051")
|
|
21
|
+
assert args == ["grpc://localhost:50051"]
|
|
22
|
+
assert "db_kwargs" not in kwargs
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_tls_scheme():
|
|
26
|
+
args, _ = _build("adbc+flightsql://flight-sql.example.com:443?tls=true")
|
|
27
|
+
assert args == ["grpc+tls://flight-sql.example.com:443"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_bearer_from_password():
|
|
31
|
+
args, kwargs = _build("adbc+flightsql://user:TOKEN@host:443?tls=true")
|
|
32
|
+
assert args == ["grpc+tls://host:443"]
|
|
33
|
+
# We can't assert on the exact key name without the driver installed —
|
|
34
|
+
# the flightsql dialect has a fallback constant for this case.
|
|
35
|
+
db = kwargs["db_kwargs"]
|
|
36
|
+
assert any(v == "Bearer TOKEN" for v in db.values())
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_authorization_passthrough():
|
|
40
|
+
args, kwargs = _build("adbc+flightsql://host:443?tls=true&authorization=Bearer%20abc")
|
|
41
|
+
db = kwargs["db_kwargs"]
|
|
42
|
+
assert any(v == "Bearer abc" for v in db.values())
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_custom_headers():
|
|
46
|
+
_, kwargs = _build("adbc+flightsql://host:443?tls=true&header.x-workspace-id=ws-1")
|
|
47
|
+
db = kwargs["db_kwargs"]
|
|
48
|
+
# Header keys use the RPC_CALL_HEADER_PREFIX; just check the value made
|
|
49
|
+
# it through.
|
|
50
|
+
assert any(v == "ws-1" for v in db.values())
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_unknown_query_passthrough():
|
|
54
|
+
_, kwargs = _build("adbc+flightsql://host:443?tls=true&some_opt=value")
|
|
55
|
+
assert kwargs["db_kwargs"]["some_opt"] == "value"
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""End-to-end smoke tests using adbc_driver_sqlite (installable in CI)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
import sqlalchemy
|
|
7
|
+
from sqlalchemy import text
|
|
8
|
+
|
|
9
|
+
pytest.importorskip("adbc_driver_sqlite")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_engine_created():
|
|
13
|
+
engine = sqlalchemy.create_engine("adbc+sqlite:///:memory:")
|
|
14
|
+
assert engine.dialect.name == "adbc"
|
|
15
|
+
assert engine.dialect.driver == "sqlite"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_select_one():
|
|
19
|
+
engine = sqlalchemy.create_engine("adbc+sqlite:///:memory:")
|
|
20
|
+
with engine.connect() as conn:
|
|
21
|
+
result = conn.execute(text("SELECT 1 AS n"))
|
|
22
|
+
row = result.fetchone()
|
|
23
|
+
assert row is not None
|
|
24
|
+
assert row[0] == 1
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_create_insert_select():
|
|
28
|
+
engine = sqlalchemy.create_engine("adbc+sqlite:///:memory:")
|
|
29
|
+
with engine.begin() as conn:
|
|
30
|
+
conn.execute(text("CREATE TABLE t (id INTEGER, name TEXT)"))
|
|
31
|
+
conn.execute(text("INSERT INTO t VALUES (1, 'a'), (2, 'b'), (3, 'c')"))
|
|
32
|
+
result = conn.execute(text("SELECT COUNT(*) FROM t"))
|
|
33
|
+
assert result.scalar() == 3
|
|
34
|
+
|
|
35
|
+
result = conn.execute(text("SELECT name FROM t WHERE id = 2"))
|
|
36
|
+
assert result.scalar() == "b"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_file_backed(tmp_path):
|
|
40
|
+
db_path = tmp_path / "test.db"
|
|
41
|
+
engine = sqlalchemy.create_engine(f"adbc+sqlite:///{db_path}")
|
|
42
|
+
with engine.begin() as conn:
|
|
43
|
+
conn.execute(text("CREATE TABLE kv (k TEXT PRIMARY KEY, v TEXT)"))
|
|
44
|
+
conn.execute(text("INSERT INTO kv VALUES ('hello', 'world')"))
|
|
45
|
+
# Reconnect to confirm the file persisted and is readable.
|
|
46
|
+
with engine.connect() as conn:
|
|
47
|
+
result = conn.execute(text("SELECT v FROM kv WHERE k = 'hello'"))
|
|
48
|
+
assert result.scalar() == "world"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_do_ping():
|
|
52
|
+
engine = sqlalchemy.create_engine("adbc+sqlite:///:memory:")
|
|
53
|
+
with engine.connect() as conn:
|
|
54
|
+
# pool_pre_ping path exercises dialect.do_ping
|
|
55
|
+
raw = conn.connection.dbapi_connection
|
|
56
|
+
assert engine.dialect.do_ping(raw) is True
|