sqlspec 0.36.0__cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
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.
- ac8f31065839703b4e70__mypyc.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/__init__.py +140 -0
- sqlspec/__main__.py +12 -0
- sqlspec/__metadata__.py +14 -0
- sqlspec/_serialization.py +315 -0
- sqlspec/_typing.py +700 -0
- sqlspec/adapters/__init__.py +0 -0
- sqlspec/adapters/adbc/__init__.py +5 -0
- sqlspec/adapters/adbc/_typing.py +82 -0
- sqlspec/adapters/adbc/adk/__init__.py +5 -0
- sqlspec/adapters/adbc/adk/store.py +1273 -0
- sqlspec/adapters/adbc/config.py +295 -0
- sqlspec/adapters/adbc/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/adbc/core.py +735 -0
- sqlspec/adapters/adbc/data_dictionary.py +334 -0
- sqlspec/adapters/adbc/driver.py +529 -0
- sqlspec/adapters/adbc/events/__init__.py +5 -0
- sqlspec/adapters/adbc/events/store.py +285 -0
- sqlspec/adapters/adbc/litestar/__init__.py +5 -0
- sqlspec/adapters/adbc/litestar/store.py +502 -0
- sqlspec/adapters/adbc/type_converter.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/adbc/type_converter.py +140 -0
- sqlspec/adapters/aiosqlite/__init__.py +25 -0
- sqlspec/adapters/aiosqlite/_typing.py +82 -0
- sqlspec/adapters/aiosqlite/adk/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/adk/store.py +818 -0
- sqlspec/adapters/aiosqlite/config.py +334 -0
- sqlspec/adapters/aiosqlite/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/aiosqlite/core.py +315 -0
- sqlspec/adapters/aiosqlite/data_dictionary.py +208 -0
- sqlspec/adapters/aiosqlite/driver.py +313 -0
- sqlspec/adapters/aiosqlite/events/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/events/store.py +20 -0
- sqlspec/adapters/aiosqlite/litestar/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/litestar/store.py +279 -0
- sqlspec/adapters/aiosqlite/pool.py +533 -0
- sqlspec/adapters/asyncmy/__init__.py +21 -0
- sqlspec/adapters/asyncmy/_typing.py +87 -0
- sqlspec/adapters/asyncmy/adk/__init__.py +5 -0
- sqlspec/adapters/asyncmy/adk/store.py +703 -0
- sqlspec/adapters/asyncmy/config.py +302 -0
- sqlspec/adapters/asyncmy/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/asyncmy/core.py +360 -0
- sqlspec/adapters/asyncmy/data_dictionary.py +124 -0
- sqlspec/adapters/asyncmy/driver.py +383 -0
- sqlspec/adapters/asyncmy/events/__init__.py +5 -0
- sqlspec/adapters/asyncmy/events/store.py +104 -0
- sqlspec/adapters/asyncmy/litestar/__init__.py +5 -0
- sqlspec/adapters/asyncmy/litestar/store.py +296 -0
- sqlspec/adapters/asyncpg/__init__.py +19 -0
- sqlspec/adapters/asyncpg/_typing.py +88 -0
- sqlspec/adapters/asyncpg/adk/__init__.py +5 -0
- sqlspec/adapters/asyncpg/adk/store.py +748 -0
- sqlspec/adapters/asyncpg/config.py +569 -0
- sqlspec/adapters/asyncpg/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/asyncpg/core.py +367 -0
- sqlspec/adapters/asyncpg/data_dictionary.py +162 -0
- sqlspec/adapters/asyncpg/driver.py +487 -0
- sqlspec/adapters/asyncpg/events/__init__.py +6 -0
- sqlspec/adapters/asyncpg/events/backend.py +286 -0
- sqlspec/adapters/asyncpg/events/store.py +40 -0
- sqlspec/adapters/asyncpg/litestar/__init__.py +5 -0
- sqlspec/adapters/asyncpg/litestar/store.py +251 -0
- sqlspec/adapters/bigquery/__init__.py +14 -0
- sqlspec/adapters/bigquery/_typing.py +86 -0
- sqlspec/adapters/bigquery/adk/__init__.py +5 -0
- sqlspec/adapters/bigquery/adk/store.py +827 -0
- sqlspec/adapters/bigquery/config.py +353 -0
- sqlspec/adapters/bigquery/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/bigquery/core.py +715 -0
- sqlspec/adapters/bigquery/data_dictionary.py +128 -0
- sqlspec/adapters/bigquery/driver.py +548 -0
- sqlspec/adapters/bigquery/events/__init__.py +5 -0
- sqlspec/adapters/bigquery/events/store.py +139 -0
- sqlspec/adapters/bigquery/litestar/__init__.py +5 -0
- sqlspec/adapters/bigquery/litestar/store.py +325 -0
- sqlspec/adapters/bigquery/type_converter.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/bigquery/type_converter.py +107 -0
- sqlspec/adapters/cockroach_asyncpg/__init__.py +24 -0
- sqlspec/adapters/cockroach_asyncpg/_typing.py +72 -0
- sqlspec/adapters/cockroach_asyncpg/adk/__init__.py +3 -0
- sqlspec/adapters/cockroach_asyncpg/adk/store.py +410 -0
- sqlspec/adapters/cockroach_asyncpg/config.py +238 -0
- sqlspec/adapters/cockroach_asyncpg/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/cockroach_asyncpg/core.py +55 -0
- sqlspec/adapters/cockroach_asyncpg/data_dictionary.py +107 -0
- sqlspec/adapters/cockroach_asyncpg/driver.py +144 -0
- sqlspec/adapters/cockroach_asyncpg/events/__init__.py +3 -0
- sqlspec/adapters/cockroach_asyncpg/events/store.py +20 -0
- sqlspec/adapters/cockroach_asyncpg/litestar/__init__.py +3 -0
- sqlspec/adapters/cockroach_asyncpg/litestar/store.py +142 -0
- sqlspec/adapters/cockroach_psycopg/__init__.py +38 -0
- sqlspec/adapters/cockroach_psycopg/_typing.py +129 -0
- sqlspec/adapters/cockroach_psycopg/adk/__init__.py +13 -0
- sqlspec/adapters/cockroach_psycopg/adk/store.py +868 -0
- sqlspec/adapters/cockroach_psycopg/config.py +484 -0
- sqlspec/adapters/cockroach_psycopg/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/cockroach_psycopg/core.py +63 -0
- sqlspec/adapters/cockroach_psycopg/data_dictionary.py +215 -0
- sqlspec/adapters/cockroach_psycopg/driver.py +284 -0
- sqlspec/adapters/cockroach_psycopg/events/__init__.py +6 -0
- sqlspec/adapters/cockroach_psycopg/events/store.py +34 -0
- sqlspec/adapters/cockroach_psycopg/litestar/__init__.py +3 -0
- sqlspec/adapters/cockroach_psycopg/litestar/store.py +325 -0
- sqlspec/adapters/duckdb/__init__.py +25 -0
- sqlspec/adapters/duckdb/_typing.py +81 -0
- sqlspec/adapters/duckdb/adk/__init__.py +14 -0
- sqlspec/adapters/duckdb/adk/store.py +850 -0
- sqlspec/adapters/duckdb/config.py +463 -0
- sqlspec/adapters/duckdb/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/duckdb/core.py +257 -0
- sqlspec/adapters/duckdb/data_dictionary.py +140 -0
- sqlspec/adapters/duckdb/driver.py +430 -0
- sqlspec/adapters/duckdb/events/__init__.py +5 -0
- sqlspec/adapters/duckdb/events/store.py +57 -0
- sqlspec/adapters/duckdb/litestar/__init__.py +5 -0
- sqlspec/adapters/duckdb/litestar/store.py +330 -0
- sqlspec/adapters/duckdb/pool.py +293 -0
- sqlspec/adapters/duckdb/type_converter.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/duckdb/type_converter.py +118 -0
- sqlspec/adapters/mock/__init__.py +72 -0
- sqlspec/adapters/mock/_typing.py +147 -0
- sqlspec/adapters/mock/config.py +483 -0
- sqlspec/adapters/mock/core.py +319 -0
- sqlspec/adapters/mock/data_dictionary.py +366 -0
- sqlspec/adapters/mock/driver.py +721 -0
- sqlspec/adapters/mysqlconnector/__init__.py +36 -0
- sqlspec/adapters/mysqlconnector/_typing.py +141 -0
- sqlspec/adapters/mysqlconnector/adk/__init__.py +15 -0
- sqlspec/adapters/mysqlconnector/adk/store.py +1060 -0
- sqlspec/adapters/mysqlconnector/config.py +394 -0
- sqlspec/adapters/mysqlconnector/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/mysqlconnector/core.py +303 -0
- sqlspec/adapters/mysqlconnector/data_dictionary.py +235 -0
- sqlspec/adapters/mysqlconnector/driver.py +483 -0
- sqlspec/adapters/mysqlconnector/events/__init__.py +8 -0
- sqlspec/adapters/mysqlconnector/events/store.py +98 -0
- sqlspec/adapters/mysqlconnector/litestar/__init__.py +5 -0
- sqlspec/adapters/mysqlconnector/litestar/store.py +426 -0
- sqlspec/adapters/oracledb/__init__.py +60 -0
- sqlspec/adapters/oracledb/_numpy_handlers.py +141 -0
- sqlspec/adapters/oracledb/_typing.py +182 -0
- sqlspec/adapters/oracledb/_uuid_handlers.py +166 -0
- sqlspec/adapters/oracledb/adk/__init__.py +10 -0
- sqlspec/adapters/oracledb/adk/store.py +2369 -0
- sqlspec/adapters/oracledb/config.py +550 -0
- sqlspec/adapters/oracledb/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/oracledb/core.py +543 -0
- sqlspec/adapters/oracledb/data_dictionary.py +536 -0
- sqlspec/adapters/oracledb/driver.py +1229 -0
- sqlspec/adapters/oracledb/events/__init__.py +16 -0
- sqlspec/adapters/oracledb/events/backend.py +347 -0
- sqlspec/adapters/oracledb/events/store.py +420 -0
- sqlspec/adapters/oracledb/litestar/__init__.py +5 -0
- sqlspec/adapters/oracledb/litestar/store.py +781 -0
- sqlspec/adapters/oracledb/migrations.py +535 -0
- sqlspec/adapters/oracledb/type_converter.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/oracledb/type_converter.py +211 -0
- sqlspec/adapters/psqlpy/__init__.py +17 -0
- sqlspec/adapters/psqlpy/_typing.py +79 -0
- sqlspec/adapters/psqlpy/adk/__init__.py +5 -0
- sqlspec/adapters/psqlpy/adk/store.py +766 -0
- sqlspec/adapters/psqlpy/config.py +304 -0
- sqlspec/adapters/psqlpy/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/psqlpy/core.py +480 -0
- sqlspec/adapters/psqlpy/data_dictionary.py +126 -0
- sqlspec/adapters/psqlpy/driver.py +438 -0
- sqlspec/adapters/psqlpy/events/__init__.py +6 -0
- sqlspec/adapters/psqlpy/events/backend.py +310 -0
- sqlspec/adapters/psqlpy/events/store.py +20 -0
- sqlspec/adapters/psqlpy/litestar/__init__.py +5 -0
- sqlspec/adapters/psqlpy/litestar/store.py +270 -0
- sqlspec/adapters/psqlpy/type_converter.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/psqlpy/type_converter.py +113 -0
- sqlspec/adapters/psycopg/__init__.py +32 -0
- sqlspec/adapters/psycopg/_typing.py +164 -0
- sqlspec/adapters/psycopg/adk/__init__.py +10 -0
- sqlspec/adapters/psycopg/adk/store.py +1387 -0
- sqlspec/adapters/psycopg/config.py +576 -0
- sqlspec/adapters/psycopg/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/psycopg/core.py +450 -0
- sqlspec/adapters/psycopg/data_dictionary.py +289 -0
- sqlspec/adapters/psycopg/driver.py +975 -0
- sqlspec/adapters/psycopg/events/__init__.py +20 -0
- sqlspec/adapters/psycopg/events/backend.py +458 -0
- sqlspec/adapters/psycopg/events/store.py +42 -0
- sqlspec/adapters/psycopg/litestar/__init__.py +5 -0
- sqlspec/adapters/psycopg/litestar/store.py +552 -0
- sqlspec/adapters/psycopg/type_converter.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/psycopg/type_converter.py +93 -0
- sqlspec/adapters/pymysql/__init__.py +21 -0
- sqlspec/adapters/pymysql/_typing.py +71 -0
- sqlspec/adapters/pymysql/adk/__init__.py +5 -0
- sqlspec/adapters/pymysql/adk/store.py +540 -0
- sqlspec/adapters/pymysql/config.py +195 -0
- sqlspec/adapters/pymysql/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/pymysql/core.py +299 -0
- sqlspec/adapters/pymysql/data_dictionary.py +122 -0
- sqlspec/adapters/pymysql/driver.py +259 -0
- sqlspec/adapters/pymysql/events/__init__.py +5 -0
- sqlspec/adapters/pymysql/events/store.py +50 -0
- sqlspec/adapters/pymysql/litestar/__init__.py +5 -0
- sqlspec/adapters/pymysql/litestar/store.py +232 -0
- sqlspec/adapters/pymysql/pool.py +137 -0
- sqlspec/adapters/spanner/__init__.py +40 -0
- sqlspec/adapters/spanner/_typing.py +86 -0
- sqlspec/adapters/spanner/adk/__init__.py +5 -0
- sqlspec/adapters/spanner/adk/store.py +732 -0
- sqlspec/adapters/spanner/config.py +352 -0
- sqlspec/adapters/spanner/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/spanner/core.py +188 -0
- sqlspec/adapters/spanner/data_dictionary.py +120 -0
- sqlspec/adapters/spanner/dialect/__init__.py +6 -0
- sqlspec/adapters/spanner/dialect/_spangres.py +57 -0
- sqlspec/adapters/spanner/dialect/_spanner.py +130 -0
- sqlspec/adapters/spanner/driver.py +373 -0
- sqlspec/adapters/spanner/events/__init__.py +5 -0
- sqlspec/adapters/spanner/events/store.py +187 -0
- sqlspec/adapters/spanner/litestar/__init__.py +5 -0
- sqlspec/adapters/spanner/litestar/store.py +291 -0
- sqlspec/adapters/spanner/type_converter.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/spanner/type_converter.py +331 -0
- sqlspec/adapters/sqlite/__init__.py +19 -0
- sqlspec/adapters/sqlite/_typing.py +80 -0
- sqlspec/adapters/sqlite/adk/__init__.py +5 -0
- sqlspec/adapters/sqlite/adk/store.py +958 -0
- sqlspec/adapters/sqlite/config.py +280 -0
- sqlspec/adapters/sqlite/core.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/sqlite/core.py +312 -0
- sqlspec/adapters/sqlite/data_dictionary.py +202 -0
- sqlspec/adapters/sqlite/driver.py +359 -0
- sqlspec/adapters/sqlite/events/__init__.py +5 -0
- sqlspec/adapters/sqlite/events/store.py +20 -0
- sqlspec/adapters/sqlite/litestar/__init__.py +5 -0
- sqlspec/adapters/sqlite/litestar/store.py +316 -0
- sqlspec/adapters/sqlite/pool.py +198 -0
- sqlspec/adapters/sqlite/type_converter.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/adapters/sqlite/type_converter.py +114 -0
- sqlspec/base.py +747 -0
- sqlspec/builder/__init__.py +179 -0
- sqlspec/builder/_base.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_base.py +1022 -0
- sqlspec/builder/_column.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_column.py +521 -0
- sqlspec/builder/_ddl.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_ddl.py +1642 -0
- sqlspec/builder/_delete.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_delete.py +95 -0
- sqlspec/builder/_dml.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_dml.py +365 -0
- sqlspec/builder/_explain.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_explain.py +579 -0
- sqlspec/builder/_expression_wrappers.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_expression_wrappers.py +46 -0
- sqlspec/builder/_factory.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_factory.py +1697 -0
- sqlspec/builder/_insert.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_insert.py +328 -0
- sqlspec/builder/_join.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_join.py +499 -0
- sqlspec/builder/_merge.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_merge.py +821 -0
- sqlspec/builder/_parsing_utils.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_parsing_utils.py +297 -0
- sqlspec/builder/_select.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_select.py +1660 -0
- sqlspec/builder/_temporal.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_temporal.py +139 -0
- sqlspec/builder/_update.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/builder/_update.py +173 -0
- sqlspec/builder/_vector_expressions.py +267 -0
- sqlspec/cli.py +911 -0
- sqlspec/config.py +1755 -0
- sqlspec/core/__init__.py +374 -0
- sqlspec/core/_correlation.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/_correlation.py +176 -0
- sqlspec/core/cache.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/cache.py +1069 -0
- sqlspec/core/compiler.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/compiler.py +954 -0
- sqlspec/core/explain.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/explain.py +275 -0
- sqlspec/core/filters.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/filters.py +952 -0
- sqlspec/core/hashing.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/hashing.py +262 -0
- sqlspec/core/metrics.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/metrics.py +83 -0
- sqlspec/core/parameters/__init__.py +71 -0
- sqlspec/core/parameters/_alignment.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/parameters/_alignment.py +270 -0
- sqlspec/core/parameters/_converter.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/parameters/_converter.py +543 -0
- sqlspec/core/parameters/_processor.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/parameters/_processor.py +505 -0
- sqlspec/core/parameters/_registry.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/parameters/_registry.py +206 -0
- sqlspec/core/parameters/_transformers.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/parameters/_transformers.py +292 -0
- sqlspec/core/parameters/_types.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/parameters/_types.py +499 -0
- sqlspec/core/parameters/_validator.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/parameters/_validator.py +180 -0
- sqlspec/core/pipeline.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/pipeline.py +319 -0
- sqlspec/core/query_modifiers.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/query_modifiers.py +437 -0
- sqlspec/core/result/__init__.py +23 -0
- sqlspec/core/result/_base.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/result/_base.py +1121 -0
- sqlspec/core/result/_io.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/result/_io.py +28 -0
- sqlspec/core/splitter.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/splitter.py +966 -0
- sqlspec/core/stack.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/stack.py +163 -0
- sqlspec/core/statement.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/statement.py +1503 -0
- sqlspec/core/type_converter.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/core/type_converter.py +339 -0
- sqlspec/data_dictionary/__init__.py +22 -0
- sqlspec/data_dictionary/_loader.py +123 -0
- sqlspec/data_dictionary/_registry.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/data_dictionary/_registry.py +74 -0
- sqlspec/data_dictionary/_types.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/data_dictionary/_types.py +121 -0
- sqlspec/data_dictionary/dialects/__init__.py +21 -0
- sqlspec/data_dictionary/dialects/bigquery.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/data_dictionary/dialects/bigquery.py +49 -0
- sqlspec/data_dictionary/dialects/cockroachdb.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/data_dictionary/dialects/cockroachdb.py +43 -0
- sqlspec/data_dictionary/dialects/duckdb.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/data_dictionary/dialects/duckdb.py +47 -0
- sqlspec/data_dictionary/dialects/mysql.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/data_dictionary/dialects/mysql.py +42 -0
- sqlspec/data_dictionary/dialects/oracle.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/data_dictionary/dialects/oracle.py +34 -0
- sqlspec/data_dictionary/dialects/postgres.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/data_dictionary/dialects/postgres.py +46 -0
- sqlspec/data_dictionary/dialects/spanner.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/data_dictionary/dialects/spanner.py +37 -0
- sqlspec/data_dictionary/dialects/sqlite.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/data_dictionary/dialects/sqlite.py +42 -0
- sqlspec/data_dictionary/sql/.gitkeep +0 -0
- sqlspec/data_dictionary/sql/bigquery/columns.sql +23 -0
- sqlspec/data_dictionary/sql/bigquery/foreign_keys.sql +34 -0
- sqlspec/data_dictionary/sql/bigquery/indexes.sql +19 -0
- sqlspec/data_dictionary/sql/bigquery/tables.sql +33 -0
- sqlspec/data_dictionary/sql/bigquery/version.sql +3 -0
- sqlspec/data_dictionary/sql/cockroachdb/columns.sql +34 -0
- sqlspec/data_dictionary/sql/cockroachdb/foreign_keys.sql +40 -0
- sqlspec/data_dictionary/sql/cockroachdb/indexes.sql +32 -0
- sqlspec/data_dictionary/sql/cockroachdb/tables.sql +44 -0
- sqlspec/data_dictionary/sql/cockroachdb/version.sql +3 -0
- sqlspec/data_dictionary/sql/duckdb/columns.sql +23 -0
- sqlspec/data_dictionary/sql/duckdb/foreign_keys.sql +36 -0
- sqlspec/data_dictionary/sql/duckdb/indexes.sql +19 -0
- sqlspec/data_dictionary/sql/duckdb/tables.sql +38 -0
- sqlspec/data_dictionary/sql/duckdb/version.sql +3 -0
- sqlspec/data_dictionary/sql/mysql/columns.sql +23 -0
- sqlspec/data_dictionary/sql/mysql/foreign_keys.sql +28 -0
- sqlspec/data_dictionary/sql/mysql/indexes.sql +26 -0
- sqlspec/data_dictionary/sql/mysql/tables.sql +33 -0
- sqlspec/data_dictionary/sql/mysql/version.sql +3 -0
- sqlspec/data_dictionary/sql/oracle/columns.sql +23 -0
- sqlspec/data_dictionary/sql/oracle/foreign_keys.sql +48 -0
- sqlspec/data_dictionary/sql/oracle/indexes.sql +44 -0
- sqlspec/data_dictionary/sql/oracle/tables.sql +25 -0
- sqlspec/data_dictionary/sql/oracle/version.sql +20 -0
- sqlspec/data_dictionary/sql/postgres/columns.sql +34 -0
- sqlspec/data_dictionary/sql/postgres/foreign_keys.sql +40 -0
- sqlspec/data_dictionary/sql/postgres/indexes.sql +56 -0
- sqlspec/data_dictionary/sql/postgres/tables.sql +44 -0
- sqlspec/data_dictionary/sql/postgres/version.sql +3 -0
- sqlspec/data_dictionary/sql/spanner/columns.sql +23 -0
- sqlspec/data_dictionary/sql/spanner/foreign_keys.sql +70 -0
- sqlspec/data_dictionary/sql/spanner/indexes.sql +30 -0
- sqlspec/data_dictionary/sql/spanner/tables.sql +9 -0
- sqlspec/data_dictionary/sql/spanner/version.sql +3 -0
- sqlspec/data_dictionary/sql/sqlite/columns.sql +23 -0
- sqlspec/data_dictionary/sql/sqlite/foreign_keys.sql +22 -0
- sqlspec/data_dictionary/sql/sqlite/indexes.sql +7 -0
- sqlspec/data_dictionary/sql/sqlite/tables.sql +28 -0
- sqlspec/data_dictionary/sql/sqlite/version.sql +3 -0
- sqlspec/driver/__init__.py +32 -0
- sqlspec/driver/_async.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/driver/_async.py +1737 -0
- sqlspec/driver/_common.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/driver/_common.py +1478 -0
- sqlspec/driver/_sql_helpers.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/driver/_sql_helpers.py +148 -0
- sqlspec/driver/_storage_helpers.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/driver/_storage_helpers.py +144 -0
- sqlspec/driver/_sync.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/driver/_sync.py +1710 -0
- sqlspec/exceptions.py +338 -0
- sqlspec/extensions/__init__.py +0 -0
- sqlspec/extensions/adk/__init__.py +70 -0
- sqlspec/extensions/adk/_types.py +51 -0
- sqlspec/extensions/adk/converters.py +172 -0
- sqlspec/extensions/adk/memory/__init__.py +69 -0
- sqlspec/extensions/adk/memory/_types.py +30 -0
- sqlspec/extensions/adk/memory/converters.py +149 -0
- sqlspec/extensions/adk/memory/service.py +217 -0
- sqlspec/extensions/adk/memory/store.py +569 -0
- sqlspec/extensions/adk/migrations/0001_create_adk_tables.py +246 -0
- sqlspec/extensions/adk/migrations/__init__.py +0 -0
- sqlspec/extensions/adk/service.py +225 -0
- sqlspec/extensions/adk/store.py +567 -0
- sqlspec/extensions/events/__init__.py +51 -0
- sqlspec/extensions/events/_channel.py +703 -0
- sqlspec/extensions/events/_hints.py +45 -0
- sqlspec/extensions/events/_models.py +23 -0
- sqlspec/extensions/events/_payload.py +69 -0
- sqlspec/extensions/events/_protocols.py +134 -0
- sqlspec/extensions/events/_queue.py +461 -0
- sqlspec/extensions/events/_store.py +209 -0
- sqlspec/extensions/events/migrations/0001_create_event_queue.py +59 -0
- sqlspec/extensions/events/migrations/__init__.py +3 -0
- sqlspec/extensions/fastapi/__init__.py +19 -0
- sqlspec/extensions/fastapi/extension.py +351 -0
- sqlspec/extensions/fastapi/providers.py +607 -0
- sqlspec/extensions/flask/__init__.py +37 -0
- sqlspec/extensions/flask/_state.py +76 -0
- sqlspec/extensions/flask/_utils.py +71 -0
- sqlspec/extensions/flask/extension.py +519 -0
- sqlspec/extensions/litestar/__init__.py +28 -0
- sqlspec/extensions/litestar/_utils.py +52 -0
- sqlspec/extensions/litestar/channels.py +165 -0
- sqlspec/extensions/litestar/cli.py +102 -0
- sqlspec/extensions/litestar/config.py +90 -0
- sqlspec/extensions/litestar/handlers.py +316 -0
- sqlspec/extensions/litestar/migrations/0001_create_session_table.py +137 -0
- sqlspec/extensions/litestar/migrations/__init__.py +3 -0
- sqlspec/extensions/litestar/plugin.py +671 -0
- sqlspec/extensions/litestar/providers.py +526 -0
- sqlspec/extensions/litestar/store.py +296 -0
- sqlspec/extensions/otel/__init__.py +58 -0
- sqlspec/extensions/prometheus/__init__.py +113 -0
- sqlspec/extensions/starlette/__init__.py +19 -0
- sqlspec/extensions/starlette/_state.py +30 -0
- sqlspec/extensions/starlette/_utils.py +96 -0
- sqlspec/extensions/starlette/extension.py +346 -0
- sqlspec/extensions/starlette/middleware.py +235 -0
- sqlspec/loader.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/loader.py +702 -0
- sqlspec/migrations/__init__.py +36 -0
- sqlspec/migrations/base.py +731 -0
- sqlspec/migrations/commands.py +1232 -0
- sqlspec/migrations/context.py +157 -0
- sqlspec/migrations/fix.py +204 -0
- sqlspec/migrations/loaders.py +443 -0
- sqlspec/migrations/runner.py +1172 -0
- sqlspec/migrations/templates.py +234 -0
- sqlspec/migrations/tracker.py +611 -0
- sqlspec/migrations/utils.py +256 -0
- sqlspec/migrations/validation.py +207 -0
- sqlspec/migrations/version.py +446 -0
- sqlspec/observability/__init__.py +55 -0
- sqlspec/observability/_common.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_common.py +77 -0
- sqlspec/observability/_config.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_config.py +348 -0
- sqlspec/observability/_diagnostics.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_diagnostics.py +74 -0
- sqlspec/observability/_dispatcher.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_dispatcher.py +152 -0
- sqlspec/observability/_formatters/__init__.py +13 -0
- sqlspec/observability/_formatters/_aws.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_formatters/_aws.py +102 -0
- sqlspec/observability/_formatters/_azure.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_formatters/_azure.py +96 -0
- sqlspec/observability/_formatters/_base.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_formatters/_base.py +57 -0
- sqlspec/observability/_formatters/_gcp.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_formatters/_gcp.py +131 -0
- sqlspec/observability/_formatting.py +58 -0
- sqlspec/observability/_observer.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_observer.py +357 -0
- sqlspec/observability/_runtime.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_runtime.py +420 -0
- sqlspec/observability/_sampling.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_sampling.py +188 -0
- sqlspec/observability/_spans.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/observability/_spans.py +161 -0
- sqlspec/protocols.py +916 -0
- sqlspec/py.typed +0 -0
- sqlspec/storage/__init__.py +48 -0
- sqlspec/storage/_utils.py +104 -0
- sqlspec/storage/backends/__init__.py +1 -0
- sqlspec/storage/backends/base.py +253 -0
- sqlspec/storage/backends/fsspec.py +529 -0
- sqlspec/storage/backends/local.py +441 -0
- sqlspec/storage/backends/obstore.py +916 -0
- sqlspec/storage/errors.py +104 -0
- sqlspec/storage/pipeline.py +582 -0
- sqlspec/storage/registry.py +301 -0
- sqlspec/typing.py +395 -0
- sqlspec/utils/__init__.py +7 -0
- sqlspec/utils/arrow_helpers.py +318 -0
- sqlspec/utils/config_tools.py +332 -0
- sqlspec/utils/correlation.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/correlation.py +134 -0
- sqlspec/utils/deprecation.py +190 -0
- sqlspec/utils/fixtures.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/fixtures.py +258 -0
- sqlspec/utils/logging.py +222 -0
- sqlspec/utils/module_loader.py +306 -0
- sqlspec/utils/portal.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/portal.py +375 -0
- sqlspec/utils/schema.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/schema.py +485 -0
- sqlspec/utils/serializers.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/serializers.py +408 -0
- sqlspec/utils/singleton.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/singleton.py +41 -0
- sqlspec/utils/sync_tools.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/sync_tools.py +311 -0
- sqlspec/utils/text.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/text.py +108 -0
- sqlspec/utils/type_converters.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/type_converters.py +128 -0
- sqlspec/utils/type_guards.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/type_guards.py +1360 -0
- sqlspec/utils/uuids.cpython-310-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/uuids.py +225 -0
- sqlspec-0.36.0.dist-info/METADATA +205 -0
- sqlspec-0.36.0.dist-info/RECORD +531 -0
- sqlspec-0.36.0.dist-info/WHEEL +7 -0
- sqlspec-0.36.0.dist-info/entry_points.txt +2 -0
- sqlspec-0.36.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
"""ADBC adapter compiled helpers."""
|
|
2
|
+
|
|
3
|
+
import datetime
|
|
4
|
+
import decimal
|
|
5
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
6
|
+
|
|
7
|
+
from sqlspec.adapters.adbc.type_converter import ADBCOutputConverter
|
|
8
|
+
from sqlspec.core import (
|
|
9
|
+
DriverParameterProfile,
|
|
10
|
+
ParameterStyle,
|
|
11
|
+
StatementConfig,
|
|
12
|
+
build_null_pruning_transform,
|
|
13
|
+
build_statement_config_from_profile,
|
|
14
|
+
)
|
|
15
|
+
from sqlspec.exceptions import (
|
|
16
|
+
CheckViolationError,
|
|
17
|
+
DatabaseConnectionError,
|
|
18
|
+
DataError,
|
|
19
|
+
ForeignKeyViolationError,
|
|
20
|
+
ImproperConfigurationError,
|
|
21
|
+
IntegrityError,
|
|
22
|
+
NotNullViolationError,
|
|
23
|
+
SQLParsingError,
|
|
24
|
+
SQLSpecError,
|
|
25
|
+
TransactionError,
|
|
26
|
+
UniqueViolationError,
|
|
27
|
+
)
|
|
28
|
+
from sqlspec.typing import Empty
|
|
29
|
+
from sqlspec.utils.module_loader import import_string
|
|
30
|
+
from sqlspec.utils.serializers import to_json
|
|
31
|
+
from sqlspec.utils.type_guards import has_rowcount, has_sqlstate
|
|
32
|
+
|
|
33
|
+
if TYPE_CHECKING:
|
|
34
|
+
from collections.abc import Callable, Mapping
|
|
35
|
+
|
|
36
|
+
from sqlspec.core import SQL
|
|
37
|
+
|
|
38
|
+
__all__ = (
|
|
39
|
+
"apply_driver_features",
|
|
40
|
+
"build_connection_config",
|
|
41
|
+
"build_profile",
|
|
42
|
+
"collect_rows",
|
|
43
|
+
"create_mapped_exception",
|
|
44
|
+
"detect_dialect",
|
|
45
|
+
"driver_from_uri",
|
|
46
|
+
"driver_kind_from_driver_name",
|
|
47
|
+
"driver_kind_from_uri",
|
|
48
|
+
"driver_profile",
|
|
49
|
+
"get_statement_config",
|
|
50
|
+
"handle_postgres_rollback",
|
|
51
|
+
"is_postgres_dialect",
|
|
52
|
+
"normalize_driver_path",
|
|
53
|
+
"normalize_postgres_empty_parameters",
|
|
54
|
+
"normalize_script_rowcount",
|
|
55
|
+
"prepare_parameters_with_casts",
|
|
56
|
+
"prepare_postgres_parameters",
|
|
57
|
+
"resolve_dialect_from_config",
|
|
58
|
+
"resolve_dialect_from_driver_path",
|
|
59
|
+
"resolve_dialect_name",
|
|
60
|
+
"resolve_driver_connect_func",
|
|
61
|
+
"resolve_driver_name",
|
|
62
|
+
"resolve_driver_name_from_config",
|
|
63
|
+
"resolve_parameter_casts",
|
|
64
|
+
"resolve_parameter_styles",
|
|
65
|
+
"resolve_rowcount",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
DIALECT_PATTERNS: "dict[str, tuple[str, ...]]" = {
|
|
69
|
+
"postgres": ("postgres", "postgresql"),
|
|
70
|
+
"bigquery": ("bigquery",),
|
|
71
|
+
"sqlite": ("sqlite", "flight", "flightsql"),
|
|
72
|
+
"duckdb": ("duckdb", "gizmosql", "gizmo"),
|
|
73
|
+
"mysql": ("mysql",),
|
|
74
|
+
"snowflake": ("snowflake",),
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
DIALECT_PARAMETER_STYLES: "dict[str, tuple[ParameterStyle, list[ParameterStyle]]]" = {
|
|
79
|
+
"postgres": (ParameterStyle.NUMERIC, [ParameterStyle.NUMERIC]),
|
|
80
|
+
"postgresql": (ParameterStyle.NUMERIC, [ParameterStyle.NUMERIC]),
|
|
81
|
+
"bigquery": (ParameterStyle.NAMED_AT, [ParameterStyle.NAMED_AT]),
|
|
82
|
+
"sqlite": (ParameterStyle.QMARK, [ParameterStyle.QMARK]),
|
|
83
|
+
"duckdb": (ParameterStyle.QMARK, [ParameterStyle.QMARK, ParameterStyle.NUMERIC, ParameterStyle.NAMED_DOLLAR]),
|
|
84
|
+
"mysql": (ParameterStyle.POSITIONAL_PYFORMAT, [ParameterStyle.POSITIONAL_PYFORMAT, ParameterStyle.NAMED_PYFORMAT]),
|
|
85
|
+
"snowflake": (ParameterStyle.QMARK, [ParameterStyle.QMARK, ParameterStyle.NUMERIC]),
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
_DRIVER_ALIASES: "dict[str, str]" = {
|
|
89
|
+
"sqlite": "adbc_driver_sqlite.dbapi.connect",
|
|
90
|
+
"sqlite3": "adbc_driver_sqlite.dbapi.connect",
|
|
91
|
+
"duckdb": "adbc_driver_duckdb.dbapi.connect",
|
|
92
|
+
"postgres": "adbc_driver_postgresql.dbapi.connect",
|
|
93
|
+
"postgresql": "adbc_driver_postgresql.dbapi.connect",
|
|
94
|
+
"pg": "adbc_driver_postgresql.dbapi.connect",
|
|
95
|
+
"snowflake": "adbc_driver_snowflake.dbapi.connect",
|
|
96
|
+
"sf": "adbc_driver_snowflake.dbapi.connect",
|
|
97
|
+
"bigquery": "adbc_driver_bigquery.dbapi.connect",
|
|
98
|
+
"bq": "adbc_driver_bigquery.dbapi.connect",
|
|
99
|
+
"flightsql": "adbc_driver_flightsql.dbapi.connect",
|
|
100
|
+
"grpc": "adbc_driver_flightsql.dbapi.connect",
|
|
101
|
+
"gizmosql": "adbc_driver_flightsql.dbapi.connect",
|
|
102
|
+
"gizmo": "adbc_driver_flightsql.dbapi.connect",
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
_URI_PREFIX_DRIVER: "tuple[tuple[str, str], ...]" = (
|
|
106
|
+
("postgresql://", "adbc_driver_postgresql.dbapi.connect"),
|
|
107
|
+
("postgres://", "adbc_driver_postgresql.dbapi.connect"),
|
|
108
|
+
("sqlite://", "adbc_driver_sqlite.dbapi.connect"),
|
|
109
|
+
("duckdb://", "adbc_driver_duckdb.dbapi.connect"),
|
|
110
|
+
("grpc://", "adbc_driver_flightsql.dbapi.connect"),
|
|
111
|
+
("grpc+tls://", "adbc_driver_flightsql.dbapi.connect"),
|
|
112
|
+
("gizmosql://", "adbc_driver_flightsql.dbapi.connect"),
|
|
113
|
+
("gizmo://", "adbc_driver_flightsql.dbapi.connect"),
|
|
114
|
+
("snowflake://", "adbc_driver_snowflake.dbapi.connect"),
|
|
115
|
+
("bigquery://", "adbc_driver_bigquery.dbapi.connect"),
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
_DRIVER_PATH_KEYWORDS_TO_DIALECT: "tuple[tuple[str, str], ...]" = (
|
|
119
|
+
("postgresql", "postgres"),
|
|
120
|
+
("sqlite", "sqlite"),
|
|
121
|
+
("duckdb", "duckdb"),
|
|
122
|
+
("bigquery", "bigquery"),
|
|
123
|
+
("snowflake", "snowflake"),
|
|
124
|
+
("gizmosql", "duckdb"),
|
|
125
|
+
("flightsql", "sqlite"),
|
|
126
|
+
("grpc", "sqlite"),
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
_PARAMETER_STYLES_BY_KEYWORD: "tuple[tuple[str, tuple[tuple[str, ...], str]], ...]" = (
|
|
130
|
+
("postgresql", (("numeric",), "numeric")),
|
|
131
|
+
("sqlite", (("qmark", "named_colon"), "qmark")),
|
|
132
|
+
("duckdb", (("qmark", "numeric"), "qmark")),
|
|
133
|
+
("gizmosql", (("qmark", "numeric"), "qmark")),
|
|
134
|
+
("bigquery", (("named_at",), "named_at")),
|
|
135
|
+
("snowflake", (("qmark", "numeric"), "qmark")),
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
_BIGQUERY_DB_KWARGS_FIELDS: "tuple[str, ...]" = ("project_id", "dataset_id", "token")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def detect_dialect(connection: Any, logger: Any | None = None) -> str:
|
|
142
|
+
"""Detect database dialect from ADBC driver information.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
connection: ADBC connection with driver metadata.
|
|
146
|
+
logger: Optional logger for diagnostics.
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
Detected dialect name, defaulting to ``postgres``.
|
|
150
|
+
"""
|
|
151
|
+
try:
|
|
152
|
+
driver_info = connection.adbc_get_info()
|
|
153
|
+
vendor_name = driver_info.get("vendor_name", "").lower()
|
|
154
|
+
driver_name = driver_info.get("driver_name", "").lower()
|
|
155
|
+
|
|
156
|
+
for dialect, patterns in DIALECT_PATTERNS.items():
|
|
157
|
+
for pattern in patterns:
|
|
158
|
+
if pattern in vendor_name or pattern in driver_name:
|
|
159
|
+
if logger is not None:
|
|
160
|
+
logger.debug("Dialect detected: %s (from %s/%s)", dialect, vendor_name, driver_name)
|
|
161
|
+
return dialect
|
|
162
|
+
except Exception as exc:
|
|
163
|
+
if logger is not None:
|
|
164
|
+
logger.debug("Dialect detection failed: %s", exc)
|
|
165
|
+
|
|
166
|
+
if logger is not None:
|
|
167
|
+
logger.warning("Could not determine dialect from driver info. Defaulting to 'postgres'.")
|
|
168
|
+
return "postgres"
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def normalize_driver_path(driver_name: str) -> str:
|
|
172
|
+
"""Normalize a driver name to an importable connect function path."""
|
|
173
|
+
stripped = driver_name.strip()
|
|
174
|
+
if stripped.endswith(".dbapi.connect"):
|
|
175
|
+
return stripped
|
|
176
|
+
if stripped.endswith(".dbapi"):
|
|
177
|
+
return f"{stripped}.connect"
|
|
178
|
+
if "." in stripped:
|
|
179
|
+
return stripped
|
|
180
|
+
return f"{stripped}.dbapi.connect"
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def driver_from_uri(uri: str) -> "str | None":
|
|
184
|
+
"""Resolve a default driver connect path from a URI."""
|
|
185
|
+
for prefix, driver_path in _URI_PREFIX_DRIVER:
|
|
186
|
+
if uri.startswith(prefix):
|
|
187
|
+
return driver_path
|
|
188
|
+
return None
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def driver_kind_from_driver_name(driver_name: str) -> "str | None":
|
|
192
|
+
"""Return a canonical driver kind based on driver name content."""
|
|
193
|
+
lowered_name = driver_name.lower()
|
|
194
|
+
if lowered_name in {"gizmosql", "gizmo"}:
|
|
195
|
+
return "gizmosql"
|
|
196
|
+
resolved = _DRIVER_ALIASES.get(driver_name.lower(), driver_name)
|
|
197
|
+
lowered = resolved.lower()
|
|
198
|
+
for keyword, _dialect in _DRIVER_PATH_KEYWORDS_TO_DIALECT:
|
|
199
|
+
if keyword in lowered:
|
|
200
|
+
return keyword
|
|
201
|
+
return None
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def driver_kind_from_uri(uri: str) -> "str | None":
|
|
205
|
+
"""Return a canonical driver kind based on URI scheme."""
|
|
206
|
+
lowered = uri.lower()
|
|
207
|
+
if lowered.startswith(("gizmosql://", "gizmo://", "grpc+tls://")):
|
|
208
|
+
return "gizmosql"
|
|
209
|
+
for prefix, driver_path in _URI_PREFIX_DRIVER:
|
|
210
|
+
if uri.startswith(prefix):
|
|
211
|
+
return driver_kind_from_driver_name(driver_path)
|
|
212
|
+
return None
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def resolve_driver_name(driver_name: str | None, uri: str | None) -> str:
|
|
216
|
+
"""Resolve and normalize the driver name."""
|
|
217
|
+
if isinstance(driver_name, str):
|
|
218
|
+
lowered_driver = driver_name.lower()
|
|
219
|
+
alias = _DRIVER_ALIASES.get(lowered_driver)
|
|
220
|
+
if alias is not None:
|
|
221
|
+
return alias
|
|
222
|
+
return normalize_driver_path(driver_name)
|
|
223
|
+
|
|
224
|
+
if isinstance(uri, str):
|
|
225
|
+
resolved = driver_from_uri(uri)
|
|
226
|
+
if resolved is not None:
|
|
227
|
+
return resolved
|
|
228
|
+
|
|
229
|
+
return "adbc_driver_sqlite.dbapi.connect"
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def resolve_driver_name_from_config(connection_config: "Mapping[str, Any]") -> str:
|
|
233
|
+
"""Resolve and normalize the driver name from a connection config mapping."""
|
|
234
|
+
return resolve_driver_name(connection_config.get("driver_name"), connection_config.get("uri"))
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def resolve_driver_connect_func(driver_name: str | None, uri: str | None) -> "Callable[..., Any]":
|
|
238
|
+
"""Resolve the driver connect function.
|
|
239
|
+
|
|
240
|
+
Raises:
|
|
241
|
+
ImproperConfigurationError: If driver cannot be loaded.
|
|
242
|
+
"""
|
|
243
|
+
driver_path = resolve_driver_name(driver_name, uri)
|
|
244
|
+
try:
|
|
245
|
+
connect_func = import_string(driver_path)
|
|
246
|
+
except ImportError as exc:
|
|
247
|
+
msg = f"Failed to import connect function from '{driver_path}'. Is the driver installed? Error: {exc}"
|
|
248
|
+
raise ImproperConfigurationError(msg) from exc
|
|
249
|
+
|
|
250
|
+
if not callable(connect_func):
|
|
251
|
+
msg = f"The path '{driver_path}' did not resolve to a callable function."
|
|
252
|
+
raise ImproperConfigurationError(msg)
|
|
253
|
+
|
|
254
|
+
return cast("Callable[..., Any]", connect_func)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def resolve_dialect_from_driver_path(driver_path: str) -> str:
|
|
258
|
+
"""Get the SQL dialect type based on the driver path."""
|
|
259
|
+
for keyword, dialect in _DRIVER_PATH_KEYWORDS_TO_DIALECT:
|
|
260
|
+
if keyword in driver_path:
|
|
261
|
+
return dialect
|
|
262
|
+
return "sqlite"
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def resolve_dialect_from_config(connection_config: "Mapping[str, Any]") -> str:
|
|
266
|
+
"""Resolve dialect using ADBC connection configuration.
|
|
267
|
+
|
|
268
|
+
GizmoSQL connections default to DuckDB unless the backend is explicitly overridden.
|
|
269
|
+
"""
|
|
270
|
+
backend = connection_config.get("gizmosql_backend")
|
|
271
|
+
if isinstance(backend, str):
|
|
272
|
+
lowered_backend = backend.lower()
|
|
273
|
+
if lowered_backend in {"duckdb", "sqlite"}:
|
|
274
|
+
return lowered_backend
|
|
275
|
+
|
|
276
|
+
driver_name = connection_config.get("driver_name")
|
|
277
|
+
if isinstance(driver_name, str) and driver_name.lower() in {"gizmosql", "gizmo"}:
|
|
278
|
+
return "duckdb"
|
|
279
|
+
|
|
280
|
+
uri = connection_config.get("uri")
|
|
281
|
+
if isinstance(uri, str):
|
|
282
|
+
lowered_uri = uri.lower()
|
|
283
|
+
if lowered_uri.startswith(("gizmosql://", "gizmo://", "grpc+tls://")):
|
|
284
|
+
return "duckdb"
|
|
285
|
+
|
|
286
|
+
return resolve_dialect_from_driver_path(resolve_driver_name_from_config(connection_config))
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def resolve_parameter_styles(driver_path: str | None, logger: Any | None = None) -> "tuple[tuple[str, ...], str]":
|
|
290
|
+
"""Resolve supported and default parameter styles from a driver path.
|
|
291
|
+
|
|
292
|
+
Args:
|
|
293
|
+
driver_path: Import path for the ADBC driver connect function.
|
|
294
|
+
logger: Optional logger for diagnostics.
|
|
295
|
+
|
|
296
|
+
Returns:
|
|
297
|
+
Tuple of (supported_parameter_styles, default_parameter_style)
|
|
298
|
+
"""
|
|
299
|
+
if isinstance(driver_path, str):
|
|
300
|
+
lowered = driver_path.lower()
|
|
301
|
+
for keyword, styles in _PARAMETER_STYLES_BY_KEYWORD:
|
|
302
|
+
if keyword in lowered:
|
|
303
|
+
return styles
|
|
304
|
+
if logger is not None:
|
|
305
|
+
logger.debug("Error resolving parameter styles, using defaults")
|
|
306
|
+
return (("qmark",), "qmark")
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def build_connection_config(connection_config: "Mapping[str, Any]") -> "dict[str, Any]":
|
|
310
|
+
"""Build a normalized connection configuration dictionary.
|
|
311
|
+
|
|
312
|
+
Args:
|
|
313
|
+
connection_config: Raw connection configuration mapping.
|
|
314
|
+
|
|
315
|
+
Returns:
|
|
316
|
+
Normalized connection configuration dictionary.
|
|
317
|
+
"""
|
|
318
|
+
config = dict(connection_config)
|
|
319
|
+
|
|
320
|
+
driver_name = config.get("driver_name")
|
|
321
|
+
uri = config.get("uri")
|
|
322
|
+
driver_kind: str | None = None
|
|
323
|
+
if isinstance(driver_name, str):
|
|
324
|
+
driver_kind = driver_kind_from_driver_name(driver_name)
|
|
325
|
+
if driver_kind is None and isinstance(uri, str):
|
|
326
|
+
driver_kind = driver_kind_from_uri(uri)
|
|
327
|
+
|
|
328
|
+
if isinstance(uri, str) and driver_kind == "sqlite" and uri.startswith("sqlite://"):
|
|
329
|
+
config["uri"] = uri[9:]
|
|
330
|
+
if isinstance(uri, str) and driver_kind == "duckdb" and uri.startswith("duckdb://"):
|
|
331
|
+
config["path"] = uri[9:]
|
|
332
|
+
config.pop("uri", None)
|
|
333
|
+
|
|
334
|
+
if isinstance(driver_name, str) and driver_kind == "bigquery":
|
|
335
|
+
db_kwargs = config.get("db_kwargs")
|
|
336
|
+
db_kwargs_dict: dict[str, Any] = dict(db_kwargs) if isinstance(db_kwargs, dict) else {}
|
|
337
|
+
for param in _BIGQUERY_DB_KWARGS_FIELDS:
|
|
338
|
+
if param in config:
|
|
339
|
+
db_kwargs_dict[param] = config.pop(param)
|
|
340
|
+
if db_kwargs_dict:
|
|
341
|
+
config["db_kwargs"] = db_kwargs_dict
|
|
342
|
+
elif isinstance(driver_name, str) and "db_kwargs" in config and driver_kind != "bigquery":
|
|
343
|
+
db_kwargs = config.pop("db_kwargs")
|
|
344
|
+
if isinstance(db_kwargs, dict):
|
|
345
|
+
config.update(db_kwargs)
|
|
346
|
+
|
|
347
|
+
config.pop("driver_name", None)
|
|
348
|
+
|
|
349
|
+
return config
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def resolve_dialect_name(dialect: Any) -> str:
|
|
353
|
+
"""Return the normalized dialect name string."""
|
|
354
|
+
if dialect is None:
|
|
355
|
+
return ""
|
|
356
|
+
return str(dialect)
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def is_postgres_dialect(dialect_name: str) -> bool:
|
|
360
|
+
"""Return True when the dialect indicates PostgreSQL."""
|
|
361
|
+
return dialect_name in {"postgres", "postgresql"}
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def handle_postgres_rollback(dialect: str, cursor: Any, logger: Any | None = None) -> None:
|
|
365
|
+
"""Execute rollback for PostgreSQL after transaction failure.
|
|
366
|
+
|
|
367
|
+
Args:
|
|
368
|
+
dialect: Active dialect identifier.
|
|
369
|
+
cursor: Database cursor to execute rollback.
|
|
370
|
+
logger: Optional logger for diagnostics.
|
|
371
|
+
"""
|
|
372
|
+
if dialect != "postgres":
|
|
373
|
+
return
|
|
374
|
+
try:
|
|
375
|
+
cursor.execute("ROLLBACK")
|
|
376
|
+
except Exception:
|
|
377
|
+
return
|
|
378
|
+
if logger is not None:
|
|
379
|
+
logger.debug("PostgreSQL rollback executed after transaction failure")
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def normalize_postgres_empty_parameters(dialect: str, parameters: Any) -> Any:
|
|
383
|
+
"""Normalize empty parameter payloads for PostgreSQL drivers.
|
|
384
|
+
|
|
385
|
+
Args:
|
|
386
|
+
dialect: Active dialect identifier.
|
|
387
|
+
parameters: Parameter payload in any supported shape.
|
|
388
|
+
|
|
389
|
+
Returns:
|
|
390
|
+
Normalized parameter payload.
|
|
391
|
+
"""
|
|
392
|
+
if dialect == "postgres" and isinstance(parameters, dict) and not parameters:
|
|
393
|
+
return None
|
|
394
|
+
return parameters
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def prepare_postgres_parameters(
|
|
398
|
+
parameters: Any,
|
|
399
|
+
parameter_casts: "dict[int, str]",
|
|
400
|
+
statement_config: "StatementConfig",
|
|
401
|
+
*,
|
|
402
|
+
dialect: str,
|
|
403
|
+
json_serializer: "Callable[[Any], str]",
|
|
404
|
+
) -> Any:
|
|
405
|
+
"""Prepare Postgres parameters with cast-aware coercion."""
|
|
406
|
+
postgres_compatible = normalize_postgres_empty_parameters(dialect, parameters)
|
|
407
|
+
return prepare_parameters_with_casts(
|
|
408
|
+
postgres_compatible, parameter_casts, statement_config, dialect=dialect, json_serializer=json_serializer
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def _create_adbc_error(error: Any, error_class: type[SQLSpecError], description: str) -> SQLSpecError:
|
|
413
|
+
"""Create an ADBC error instance without raising it."""
|
|
414
|
+
msg = f"ADBC {description}: {error}"
|
|
415
|
+
exc = error_class(msg)
|
|
416
|
+
exc.__cause__ = error
|
|
417
|
+
return exc
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def create_mapped_exception(error: Any) -> SQLSpecError:
|
|
421
|
+
"""Map ADBC errors to SQLSpec exceptions.
|
|
422
|
+
|
|
423
|
+
This is a factory function that returns an exception instance rather than
|
|
424
|
+
raising. This pattern is more robust for use in __exit__ handlers and
|
|
425
|
+
avoids issues with exception control flow in different Python versions.
|
|
426
|
+
|
|
427
|
+
Args:
|
|
428
|
+
error: The ADBC exception to map
|
|
429
|
+
|
|
430
|
+
Returns:
|
|
431
|
+
A SQLSpec exception that wraps the original error
|
|
432
|
+
"""
|
|
433
|
+
sqlstate = error.sqlstate if has_sqlstate(error) and error.sqlstate is not None else None
|
|
434
|
+
|
|
435
|
+
if sqlstate:
|
|
436
|
+
if sqlstate == "23505":
|
|
437
|
+
return _create_adbc_error(error, UniqueViolationError, "unique constraint violation")
|
|
438
|
+
if sqlstate == "23503":
|
|
439
|
+
return _create_adbc_error(error, ForeignKeyViolationError, "foreign key constraint violation")
|
|
440
|
+
if sqlstate == "23502":
|
|
441
|
+
return _create_adbc_error(error, NotNullViolationError, "not-null constraint violation")
|
|
442
|
+
if sqlstate == "23514":
|
|
443
|
+
return _create_adbc_error(error, CheckViolationError, "check constraint violation")
|
|
444
|
+
if sqlstate.startswith("23"):
|
|
445
|
+
return _create_adbc_error(error, IntegrityError, "integrity constraint violation")
|
|
446
|
+
if sqlstate.startswith("42"):
|
|
447
|
+
return _create_adbc_error(error, SQLParsingError, "SQL parsing error")
|
|
448
|
+
if sqlstate.startswith("08"):
|
|
449
|
+
return _create_adbc_error(error, DatabaseConnectionError, "connection error")
|
|
450
|
+
if sqlstate.startswith("40"):
|
|
451
|
+
return _create_adbc_error(error, TransactionError, "transaction error")
|
|
452
|
+
if sqlstate.startswith("22"):
|
|
453
|
+
return _create_adbc_error(error, DataError, "data error")
|
|
454
|
+
return _create_adbc_error(error, SQLSpecError, "database error")
|
|
455
|
+
|
|
456
|
+
error_msg = str(error).lower()
|
|
457
|
+
|
|
458
|
+
if "unique" in error_msg or "duplicate" in error_msg:
|
|
459
|
+
return _create_adbc_error(error, UniqueViolationError, "unique constraint violation")
|
|
460
|
+
if "foreign key" in error_msg:
|
|
461
|
+
return _create_adbc_error(error, ForeignKeyViolationError, "foreign key constraint violation")
|
|
462
|
+
if "not null" in error_msg or "null value" in error_msg:
|
|
463
|
+
return _create_adbc_error(error, NotNullViolationError, "not-null constraint violation")
|
|
464
|
+
if "check constraint" in error_msg:
|
|
465
|
+
return _create_adbc_error(error, CheckViolationError, "check constraint violation")
|
|
466
|
+
if "constraint" in error_msg:
|
|
467
|
+
return _create_adbc_error(error, IntegrityError, "integrity constraint violation")
|
|
468
|
+
if "syntax" in error_msg:
|
|
469
|
+
return _create_adbc_error(error, SQLParsingError, "SQL parsing error")
|
|
470
|
+
if "connection" in error_msg or "connect" in error_msg:
|
|
471
|
+
return _create_adbc_error(error, DatabaseConnectionError, "connection error")
|
|
472
|
+
return _create_adbc_error(error, SQLSpecError, "database error")
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
def _identity(value: Any) -> Any:
|
|
476
|
+
return value
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def _convert_array_for_postgres_adbc(value: Any) -> Any:
|
|
480
|
+
"""Convert array values for PostgreSQL compatibility."""
|
|
481
|
+
|
|
482
|
+
if isinstance(value, tuple):
|
|
483
|
+
return list(value)
|
|
484
|
+
return value
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
def _get_type_coercion_map(dialect: str) -> "dict[type, Any]":
|
|
488
|
+
"""Return dialect-aware type coercion mapping for Arrow parameter handling."""
|
|
489
|
+
|
|
490
|
+
return {
|
|
491
|
+
datetime.datetime: _identity,
|
|
492
|
+
datetime.date: _identity,
|
|
493
|
+
datetime.time: _identity,
|
|
494
|
+
decimal.Decimal: float,
|
|
495
|
+
bool: _identity,
|
|
496
|
+
int: _identity,
|
|
497
|
+
float: _identity,
|
|
498
|
+
bytes: _identity,
|
|
499
|
+
tuple: _convert_array_for_postgres_adbc,
|
|
500
|
+
list: _convert_array_for_postgres_adbc,
|
|
501
|
+
dict: _identity,
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
def build_profile() -> "DriverParameterProfile":
|
|
506
|
+
"""Create the ADBC driver parameter profile."""
|
|
507
|
+
|
|
508
|
+
return DriverParameterProfile(
|
|
509
|
+
name="ADBC",
|
|
510
|
+
default_style=ParameterStyle.QMARK,
|
|
511
|
+
supported_styles={ParameterStyle.QMARK},
|
|
512
|
+
default_execution_style=ParameterStyle.QMARK,
|
|
513
|
+
supported_execution_styles={ParameterStyle.QMARK},
|
|
514
|
+
has_native_list_expansion=True,
|
|
515
|
+
preserve_parameter_format=True,
|
|
516
|
+
needs_static_script_compilation=False,
|
|
517
|
+
allow_mixed_parameter_styles=False,
|
|
518
|
+
preserve_original_params_for_many=False,
|
|
519
|
+
json_serializer_strategy="helper",
|
|
520
|
+
custom_type_coercions={
|
|
521
|
+
datetime.datetime: _identity,
|
|
522
|
+
datetime.date: _identity,
|
|
523
|
+
datetime.time: _identity,
|
|
524
|
+
decimal.Decimal: float,
|
|
525
|
+
bool: _identity,
|
|
526
|
+
int: _identity,
|
|
527
|
+
float: _identity,
|
|
528
|
+
bytes: _identity,
|
|
529
|
+
tuple: _convert_array_for_postgres_adbc,
|
|
530
|
+
list: _convert_array_for_postgres_adbc,
|
|
531
|
+
dict: _identity,
|
|
532
|
+
},
|
|
533
|
+
extras={
|
|
534
|
+
"type_coercion_overrides": {list: _convert_array_for_postgres_adbc, tuple: _convert_array_for_postgres_adbc}
|
|
535
|
+
},
|
|
536
|
+
)
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
driver_profile = build_profile()
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
def get_statement_config(detected_dialect: str) -> StatementConfig:
|
|
543
|
+
"""Create statement configuration for the specified dialect."""
|
|
544
|
+
default_style, supported_styles = DIALECT_PARAMETER_STYLES.get(
|
|
545
|
+
detected_dialect, (ParameterStyle.QMARK, [ParameterStyle.QMARK])
|
|
546
|
+
)
|
|
547
|
+
|
|
548
|
+
type_map = _get_type_coercion_map(detected_dialect)
|
|
549
|
+
|
|
550
|
+
sqlglot_dialect = "postgres" if detected_dialect == "postgresql" else detected_dialect
|
|
551
|
+
profile = driver_profile
|
|
552
|
+
|
|
553
|
+
parameter_overrides: dict[str, Any] = {
|
|
554
|
+
"default_parameter_style": default_style,
|
|
555
|
+
"supported_parameter_styles": set(supported_styles),
|
|
556
|
+
"default_execution_parameter_style": default_style,
|
|
557
|
+
"supported_execution_parameter_styles": set(supported_styles),
|
|
558
|
+
"type_coercion_map": type_map,
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if detected_dialect == "duckdb":
|
|
562
|
+
parameter_overrides["preserve_parameter_format"] = False
|
|
563
|
+
parameter_overrides["supported_execution_parameter_styles"] = {ParameterStyle.QMARK, ParameterStyle.NUMERIC}
|
|
564
|
+
|
|
565
|
+
if detected_dialect in {"postgres", "postgresql"}:
|
|
566
|
+
parameter_overrides["ast_transformer"] = build_null_pruning_transform(dialect=sqlglot_dialect)
|
|
567
|
+
|
|
568
|
+
return build_statement_config_from_profile(
|
|
569
|
+
profile, parameter_overrides=parameter_overrides, statement_overrides={"dialect": sqlglot_dialect}
|
|
570
|
+
)
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def _normalize_adbc_driver_features(processed_features: "dict[str, Any]") -> "dict[str, Any]":
|
|
574
|
+
if "strict_type_coercion" in processed_features and "enable_strict_type_coercion" not in processed_features:
|
|
575
|
+
processed_features["enable_strict_type_coercion"] = processed_features["strict_type_coercion"]
|
|
576
|
+
if "enable_strict_type_coercion" in processed_features and "strict_type_coercion" not in processed_features:
|
|
577
|
+
processed_features["strict_type_coercion"] = processed_features["enable_strict_type_coercion"]
|
|
578
|
+
|
|
579
|
+
if "arrow_extension_types" in processed_features and "enable_arrow_extension_types" not in processed_features:
|
|
580
|
+
processed_features["enable_arrow_extension_types"] = processed_features["arrow_extension_types"]
|
|
581
|
+
if "enable_arrow_extension_types" in processed_features and "arrow_extension_types" not in processed_features:
|
|
582
|
+
processed_features["arrow_extension_types"] = processed_features["enable_arrow_extension_types"]
|
|
583
|
+
|
|
584
|
+
return processed_features
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
def _apply_adbc_json_serializer(
|
|
588
|
+
statement_config: "StatementConfig", json_serializer: "Callable[[Any], str]"
|
|
589
|
+
) -> "StatementConfig":
|
|
590
|
+
"""Apply a JSON serializer to statement config while preserving list/tuple converters.
|
|
591
|
+
|
|
592
|
+
Args:
|
|
593
|
+
statement_config: Base statement configuration to update.
|
|
594
|
+
json_serializer: JSON serializer function.
|
|
595
|
+
|
|
596
|
+
Returns:
|
|
597
|
+
Updated statement configuration.
|
|
598
|
+
"""
|
|
599
|
+
parameter_config = statement_config.parameter_config
|
|
600
|
+
previous_list_converter = parameter_config.type_coercion_map.get(list)
|
|
601
|
+
previous_tuple_converter = parameter_config.type_coercion_map.get(tuple)
|
|
602
|
+
|
|
603
|
+
updated_parameter_config = parameter_config.with_json_serializers(json_serializer)
|
|
604
|
+
updated_map = dict(updated_parameter_config.type_coercion_map)
|
|
605
|
+
|
|
606
|
+
if previous_list_converter is not None:
|
|
607
|
+
updated_map[list] = previous_list_converter
|
|
608
|
+
if previous_tuple_converter is not None:
|
|
609
|
+
updated_map[tuple] = previous_tuple_converter
|
|
610
|
+
|
|
611
|
+
return statement_config.replace(parameter_config=updated_parameter_config.replace(type_coercion_map=updated_map))
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
def apply_driver_features(
|
|
615
|
+
statement_config: "StatementConfig", driver_features: "Mapping[str, Any] | None"
|
|
616
|
+
) -> "tuple[StatementConfig, dict[str, Any]]":
|
|
617
|
+
"""Apply ADBC driver feature defaults to the statement config.
|
|
618
|
+
|
|
619
|
+
Args:
|
|
620
|
+
statement_config: Base statement configuration.
|
|
621
|
+
driver_features: Optional driver feature overrides.
|
|
622
|
+
|
|
623
|
+
Returns:
|
|
624
|
+
Updated statement configuration and normalized driver features.
|
|
625
|
+
"""
|
|
626
|
+
processed_features: dict[str, Any] = dict(driver_features) if driver_features else {}
|
|
627
|
+
processed_features = _normalize_adbc_driver_features(processed_features)
|
|
628
|
+
|
|
629
|
+
json_serializer = cast("Callable[[Any], str] | None", processed_features.setdefault("json_serializer", to_json))
|
|
630
|
+
processed_features.setdefault("enable_cast_detection", True)
|
|
631
|
+
processed_features.setdefault("strict_type_coercion", False)
|
|
632
|
+
processed_features.setdefault("enable_strict_type_coercion", processed_features["strict_type_coercion"])
|
|
633
|
+
processed_features.setdefault("arrow_extension_types", True)
|
|
634
|
+
processed_features.setdefault("enable_arrow_extension_types", processed_features["arrow_extension_types"])
|
|
635
|
+
|
|
636
|
+
if json_serializer is not None:
|
|
637
|
+
statement_config = _apply_adbc_json_serializer(statement_config, json_serializer)
|
|
638
|
+
|
|
639
|
+
return statement_config, processed_features
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
def collect_rows(
|
|
643
|
+
fetched_data: "list[Any] | None", description: "list[Any] | None"
|
|
644
|
+
) -> "tuple[list[dict[str, Any]], list[str]]":
|
|
645
|
+
"""Collect ADBC rows into dictionaries with column names.
|
|
646
|
+
|
|
647
|
+
Args:
|
|
648
|
+
fetched_data: Rows returned from cursor.fetchall().
|
|
649
|
+
description: Cursor description metadata.
|
|
650
|
+
|
|
651
|
+
Returns:
|
|
652
|
+
Tuple of (rows, column_names).
|
|
653
|
+
"""
|
|
654
|
+
if not description:
|
|
655
|
+
return [], []
|
|
656
|
+
column_names = [col[0] for col in description]
|
|
657
|
+
if not fetched_data:
|
|
658
|
+
return [], column_names
|
|
659
|
+
if isinstance(fetched_data[0], tuple):
|
|
660
|
+
dict_rows = [dict(zip(column_names, row, strict=False)) for row in fetched_data]
|
|
661
|
+
return dict_rows, column_names
|
|
662
|
+
return cast("list[dict[str, Any]]", fetched_data), column_names
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
def resolve_rowcount(cursor: Any) -> int:
|
|
666
|
+
"""Resolve rowcount from an ADBC cursor.
|
|
667
|
+
|
|
668
|
+
Args:
|
|
669
|
+
cursor: ADBC cursor with optional rowcount metadata.
|
|
670
|
+
|
|
671
|
+
Returns:
|
|
672
|
+
Rowcount value or -1 when unavailable.
|
|
673
|
+
"""
|
|
674
|
+
if not has_rowcount(cursor):
|
|
675
|
+
return -1
|
|
676
|
+
rowcount = cursor.rowcount
|
|
677
|
+
if isinstance(rowcount, int):
|
|
678
|
+
return rowcount
|
|
679
|
+
return -1
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
def normalize_script_rowcount(previous: int, cursor: Any) -> int:
|
|
683
|
+
"""Normalize script rowcount using the latest cursor value when present.
|
|
684
|
+
|
|
685
|
+
Args:
|
|
686
|
+
previous: Previously recorded rowcount.
|
|
687
|
+
cursor: ADBC cursor with optional rowcount metadata.
|
|
688
|
+
|
|
689
|
+
Returns:
|
|
690
|
+
Updated rowcount value.
|
|
691
|
+
"""
|
|
692
|
+
rowcount = resolve_rowcount(cursor)
|
|
693
|
+
return rowcount if rowcount != -1 else previous
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
def resolve_parameter_casts(statement: "SQL") -> "dict[int, str]":
|
|
697
|
+
"""Return parameter cast mapping from a compiled SQL statement."""
|
|
698
|
+
processed_state = statement.get_processed_state()
|
|
699
|
+
if processed_state is not Empty:
|
|
700
|
+
return processed_state.parameter_casts or {}
|
|
701
|
+
return {}
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
def prepare_parameters_with_casts(
|
|
705
|
+
parameters: Any,
|
|
706
|
+
parameter_casts: "dict[int, str]",
|
|
707
|
+
statement_config: "StatementConfig",
|
|
708
|
+
*,
|
|
709
|
+
dialect: str,
|
|
710
|
+
json_serializer: "Callable[[Any], str]",
|
|
711
|
+
) -> Any:
|
|
712
|
+
"""Prepare parameters with cast-aware type coercion for ADBC."""
|
|
713
|
+
json_encoder = statement_config.parameter_config.json_serializer or json_serializer
|
|
714
|
+
|
|
715
|
+
if isinstance(parameters, (list, tuple)):
|
|
716
|
+
result: list[Any] = []
|
|
717
|
+
converter = ADBCOutputConverter(dialect)
|
|
718
|
+
for idx, param in enumerate(parameters, start=1):
|
|
719
|
+
cast_type = parameter_casts.get(idx, "").upper()
|
|
720
|
+
if cast_type in {"JSON", "JSONB", "TYPE.JSON", "TYPE.JSONB"}:
|
|
721
|
+
if isinstance(param, dict):
|
|
722
|
+
result.append(json_encoder(param))
|
|
723
|
+
else:
|
|
724
|
+
result.append(param)
|
|
725
|
+
elif isinstance(param, dict):
|
|
726
|
+
result.append(converter.convert_dict(param))
|
|
727
|
+
else:
|
|
728
|
+
if statement_config.parameter_config.type_coercion_map:
|
|
729
|
+
for type_check, converter_func in statement_config.parameter_config.type_coercion_map.items():
|
|
730
|
+
if type_check is not dict and isinstance(param, type_check):
|
|
731
|
+
param = converter_func(param)
|
|
732
|
+
break
|
|
733
|
+
result.append(param)
|
|
734
|
+
return tuple(result) if isinstance(parameters, tuple) else result
|
|
735
|
+
return parameters
|