sqlspec 0.47.0__cp314-cp314-win_amd64.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.
- f68e0789eb443ecb1c2c__mypyc.cp314-win_amd64.pyd +0 -0
- sqlspec/__init__.py +167 -0
- sqlspec/__main__.py +12 -0
- sqlspec/__metadata__.py +14 -0
- sqlspec/_typing.py +714 -0
- sqlspec/adapters/__init__.py +0 -0
- sqlspec/adapters/adbc/__init__.py +13 -0
- sqlspec/adapters/adbc/_typing.py +106 -0
- sqlspec/adapters/adbc/adk/__init__.py +5 -0
- sqlspec/adapters/adbc/adk/store.py +1280 -0
- sqlspec/adapters/adbc/config.py +378 -0
- sqlspec/adapters/adbc/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/core.py +922 -0
- sqlspec/adapters/adbc/data_dictionary.py +339 -0
- sqlspec/adapters/adbc/driver.py +534 -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 +534 -0
- sqlspec/adapters/adbc/type_converter.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/type_converter.py +142 -0
- sqlspec/adapters/aiomysql/__init__.py +21 -0
- sqlspec/adapters/aiomysql/_typing.py +137 -0
- sqlspec/adapters/aiomysql/adk/__init__.py +5 -0
- sqlspec/adapters/aiomysql/adk/store.py +678 -0
- sqlspec/adapters/aiomysql/config.py +305 -0
- sqlspec/adapters/aiomysql/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/aiomysql/core.py +536 -0
- sqlspec/adapters/aiomysql/data_dictionary.py +121 -0
- sqlspec/adapters/aiomysql/driver.py +386 -0
- sqlspec/adapters/aiomysql/events/__init__.py +5 -0
- sqlspec/adapters/aiomysql/events/store.py +104 -0
- sqlspec/adapters/aiomysql/litestar/__init__.py +5 -0
- sqlspec/adapters/aiomysql/litestar/store.py +314 -0
- sqlspec/adapters/aiosqlite/__init__.py +26 -0
- sqlspec/adapters/aiosqlite/_typing.py +109 -0
- sqlspec/adapters/aiosqlite/adk/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/adk/store.py +829 -0
- sqlspec/adapters/aiosqlite/config.py +315 -0
- sqlspec/adapters/aiosqlite/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/core.py +315 -0
- sqlspec/adapters/aiosqlite/data_dictionary.py +202 -0
- sqlspec/adapters/aiosqlite/driver.py +311 -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.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/pool.py +734 -0
- sqlspec/adapters/asyncmy/__init__.py +21 -0
- sqlspec/adapters/asyncmy/_typing.py +113 -0
- sqlspec/adapters/asyncmy/adk/__init__.py +5 -0
- sqlspec/adapters/asyncmy/adk/store.py +644 -0
- sqlspec/adapters/asyncmy/config.py +307 -0
- sqlspec/adapters/asyncmy/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncmy/core.py +538 -0
- sqlspec/adapters/asyncmy/data_dictionary.py +122 -0
- sqlspec/adapters/asyncmy/driver.py +391 -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 +26 -0
- sqlspec/adapters/asyncpg/_typing.py +103 -0
- sqlspec/adapters/asyncpg/adk/__init__.py +5 -0
- sqlspec/adapters/asyncpg/adk/store.py +483 -0
- sqlspec/adapters/asyncpg/config.py +575 -0
- sqlspec/adapters/asyncpg/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/core.py +480 -0
- sqlspec/adapters/asyncpg/data_dictionary.py +157 -0
- sqlspec/adapters/asyncpg/driver.py +487 -0
- sqlspec/adapters/asyncpg/events/__init__.py +6 -0
- sqlspec/adapters/asyncpg/events/_hub.py +181 -0
- sqlspec/adapters/asyncpg/events/backend.py +210 -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 +15 -0
- sqlspec/adapters/bigquery/_typing.py +108 -0
- sqlspec/adapters/bigquery/config.py +362 -0
- sqlspec/adapters/bigquery/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/bigquery/core.py +768 -0
- sqlspec/adapters/bigquery/data_dictionary.py +120 -0
- sqlspec/adapters/bigquery/driver.py +542 -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.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/bigquery/type_converter.py +107 -0
- sqlspec/adapters/cockroach_asyncpg/__init__.py +26 -0
- sqlspec/adapters/cockroach_asyncpg/_typing.py +73 -0
- sqlspec/adapters/cockroach_asyncpg/adk/__init__.py +3 -0
- sqlspec/adapters/cockroach_asyncpg/adk/store.py +465 -0
- sqlspec/adapters/cockroach_asyncpg/config.py +248 -0
- sqlspec/adapters/cockroach_asyncpg/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_asyncpg/core.py +55 -0
- sqlspec/adapters/cockroach_asyncpg/data_dictionary.py +110 -0
- sqlspec/adapters/cockroach_asyncpg/driver.py +142 -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 +39 -0
- sqlspec/adapters/cockroach_psycopg/_typing.py +137 -0
- sqlspec/adapters/cockroach_psycopg/adk/__init__.py +13 -0
- sqlspec/adapters/cockroach_psycopg/adk/store.py +1039 -0
- sqlspec/adapters/cockroach_psycopg/config.py +511 -0
- sqlspec/adapters/cockroach_psycopg/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_psycopg/core.py +63 -0
- sqlspec/adapters/cockroach_psycopg/data_dictionary.py +220 -0
- sqlspec/adapters/cockroach_psycopg/driver.py +273 -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 +327 -0
- sqlspec/adapters/duckdb/__init__.py +29 -0
- sqlspec/adapters/duckdb/_typing.py +104 -0
- sqlspec/adapters/duckdb/adk/__init__.py +14 -0
- sqlspec/adapters/duckdb/adk/store.py +935 -0
- sqlspec/adapters/duckdb/config.py +386 -0
- sqlspec/adapters/duckdb/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/core.py +332 -0
- sqlspec/adapters/duckdb/data_dictionary.py +140 -0
- sqlspec/adapters/duckdb/driver.py +426 -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.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/pool.py +350 -0
- sqlspec/adapters/duckdb/type_converter.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/type_converter.py +118 -0
- sqlspec/adapters/mysqlconnector/__init__.py +39 -0
- sqlspec/adapters/mysqlconnector/_typing.py +186 -0
- sqlspec/adapters/mysqlconnector/adk/__init__.py +15 -0
- sqlspec/adapters/mysqlconnector/adk/store.py +1183 -0
- sqlspec/adapters/mysqlconnector/config.py +421 -0
- sqlspec/adapters/mysqlconnector/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/mysqlconnector/core.py +472 -0
- sqlspec/adapters/mysqlconnector/data_dictionary.py +230 -0
- sqlspec/adapters/mysqlconnector/driver.py +516 -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 +39 -0
- sqlspec/adapters/oracledb/_json_handlers.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_json_handlers.py +196 -0
- sqlspec/adapters/oracledb/_param_types.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_param_types.py +46 -0
- sqlspec/adapters/oracledb/_typing.py +258 -0
- sqlspec/adapters/oracledb/_uuid_handlers.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_uuid_handlers.py +163 -0
- sqlspec/adapters/oracledb/_vector_handlers.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_vector_handlers.py +228 -0
- sqlspec/adapters/oracledb/adk/__init__.py +21 -0
- sqlspec/adapters/oracledb/adk/store.py +2453 -0
- sqlspec/adapters/oracledb/config.py +575 -0
- sqlspec/adapters/oracledb/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/core.py +820 -0
- sqlspec/adapters/oracledb/data_dictionary.py +404 -0
- sqlspec/adapters/oracledb/driver.py +1277 -0
- sqlspec/adapters/oracledb/events/__init__.py +16 -0
- sqlspec/adapters/oracledb/events/_hub.py +345 -0
- sqlspec/adapters/oracledb/events/backend.py +300 -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 +539 -0
- sqlspec/adapters/oracledb/type_converter.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/type_converter.py +211 -0
- sqlspec/adapters/psqlpy/__init__.py +18 -0
- sqlspec/adapters/psqlpy/_typing.py +121 -0
- sqlspec/adapters/psqlpy/adk/__init__.py +5 -0
- sqlspec/adapters/psqlpy/adk/store.py +591 -0
- sqlspec/adapters/psqlpy/config.py +376 -0
- sqlspec/adapters/psqlpy/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/core.py +694 -0
- sqlspec/adapters/psqlpy/data_dictionary.py +121 -0
- sqlspec/adapters/psqlpy/driver.py +411 -0
- sqlspec/adapters/psqlpy/events/__init__.py +6 -0
- sqlspec/adapters/psqlpy/events/_hub.py +204 -0
- sqlspec/adapters/psqlpy/events/backend.py +210 -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.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/type_converter.py +113 -0
- sqlspec/adapters/psycopg/__init__.py +38 -0
- sqlspec/adapters/psycopg/_typing.py +218 -0
- sqlspec/adapters/psycopg/adk/__init__.py +10 -0
- sqlspec/adapters/psycopg/adk/store.py +1106 -0
- sqlspec/adapters/psycopg/config.py +695 -0
- sqlspec/adapters/psycopg/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/core.py +520 -0
- sqlspec/adapters/psycopg/data_dictionary.py +278 -0
- sqlspec/adapters/psycopg/driver.py +1033 -0
- sqlspec/adapters/psycopg/events/__init__.py +20 -0
- sqlspec/adapters/psycopg/events/_hub.py +388 -0
- sqlspec/adapters/psycopg/events/backend.py +398 -0
- sqlspec/adapters/psycopg/events/store.py +42 -0
- sqlspec/adapters/psycopg/litestar/__init__.py +5 -0
- sqlspec/adapters/psycopg/litestar/store.py +554 -0
- sqlspec/adapters/psycopg/type_converter.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/type_converter.py +93 -0
- sqlspec/adapters/pymysql/__init__.py +21 -0
- sqlspec/adapters/pymysql/_typing.py +92 -0
- sqlspec/adapters/pymysql/adk/__init__.py +5 -0
- sqlspec/adapters/pymysql/adk/store.py +657 -0
- sqlspec/adapters/pymysql/config.py +176 -0
- sqlspec/adapters/pymysql/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/pymysql/core.py +469 -0
- sqlspec/adapters/pymysql/data_dictionary.py +120 -0
- sqlspec/adapters/pymysql/driver.py +271 -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.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/pymysql/pool.py +184 -0
- sqlspec/adapters/spanner/__init__.py +33 -0
- sqlspec/adapters/spanner/_typing.py +102 -0
- sqlspec/adapters/spanner/adk/__init__.py +5 -0
- sqlspec/adapters/spanner/adk/store.py +758 -0
- sqlspec/adapters/spanner/config.py +355 -0
- sqlspec/adapters/spanner/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/spanner/core.py +263 -0
- sqlspec/adapters/spanner/data_dictionary.py +120 -0
- sqlspec/adapters/spanner/driver.py +407 -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.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/spanner/type_converter.py +342 -0
- sqlspec/adapters/sqlite/__init__.py +19 -0
- sqlspec/adapters/sqlite/_typing.py +123 -0
- sqlspec/adapters/sqlite/adk/__init__.py +5 -0
- sqlspec/adapters/sqlite/adk/store.py +992 -0
- sqlspec/adapters/sqlite/config.py +240 -0
- sqlspec/adapters/sqlite/core.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/core.py +357 -0
- sqlspec/adapters/sqlite/data_dictionary.py +198 -0
- sqlspec/adapters/sqlite/driver.py +527 -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.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/pool.py +237 -0
- sqlspec/adapters/sqlite/type_converter.cp314-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/type_converter.py +114 -0
- sqlspec/base.py +832 -0
- sqlspec/builder/__init__.py +181 -0
- sqlspec/builder/_base.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_base.py +1071 -0
- sqlspec/builder/_column.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_column.py +521 -0
- sqlspec/builder/_ddl.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_ddl.py +1691 -0
- sqlspec/builder/_delete.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_delete.py +95 -0
- sqlspec/builder/_dml.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_dml.py +386 -0
- sqlspec/builder/_explain.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_explain.py +579 -0
- sqlspec/builder/_expression_wrappers.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_expression_wrappers.py +46 -0
- sqlspec/builder/_factory.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_factory.py +1884 -0
- sqlspec/builder/_insert.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_insert.py +405 -0
- sqlspec/builder/_join.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_join.py +489 -0
- sqlspec/builder/_merge.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_merge.py +823 -0
- sqlspec/builder/_parsing_utils.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_parsing_utils.py +295 -0
- sqlspec/builder/_select.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_select.py +1666 -0
- sqlspec/builder/_temporal.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_temporal.py +167 -0
- sqlspec/builder/_update.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_update.py +173 -0
- sqlspec/builder/_vector_distance.cp314-win_amd64.pyd +0 -0
- sqlspec/builder/_vector_distance.py +330 -0
- sqlspec/cli.py +1095 -0
- sqlspec/config.py +2383 -0
- sqlspec/core/__init__.py +372 -0
- sqlspec/core/_correlation.cp314-win_amd64.pyd +0 -0
- sqlspec/core/_correlation.py +176 -0
- sqlspec/core/_pagination.py +42 -0
- sqlspec/core/_pool.cp314-win_amd64.pyd +0 -0
- sqlspec/core/_pool.py +76 -0
- sqlspec/core/cache.cp314-win_amd64.pyd +0 -0
- sqlspec/core/cache.py +1085 -0
- sqlspec/core/compiler.cp314-win_amd64.pyd +0 -0
- sqlspec/core/compiler.py +1090 -0
- sqlspec/core/config_runtime.cp314-win_amd64.pyd +0 -0
- sqlspec/core/config_runtime.py +174 -0
- sqlspec/core/explain.cp314-win_amd64.pyd +0 -0
- sqlspec/core/explain.py +275 -0
- sqlspec/core/filters.cp314-win_amd64.pyd +0 -0
- sqlspec/core/filters.py +969 -0
- sqlspec/core/hashing.cp314-win_amd64.pyd +0 -0
- sqlspec/core/hashing.py +266 -0
- sqlspec/core/metrics.cp314-win_amd64.pyd +0 -0
- sqlspec/core/metrics.py +83 -0
- sqlspec/core/parameters/__init__.py +72 -0
- sqlspec/core/parameters/_alignment.cp314-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_alignment.py +283 -0
- sqlspec/core/parameters/_converter.cp314-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_converter.py +554 -0
- sqlspec/core/parameters/_processor.cp314-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_processor.py +1182 -0
- sqlspec/core/parameters/_registry.cp314-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_registry.py +206 -0
- sqlspec/core/parameters/_transformers.cp314-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_transformers.py +324 -0
- sqlspec/core/parameters/_types.cp314-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_types.py +536 -0
- sqlspec/core/parameters/_validator.cp314-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_validator.py +171 -0
- sqlspec/core/pipeline.cp314-win_amd64.pyd +0 -0
- sqlspec/core/pipeline.py +333 -0
- sqlspec/core/query_modifiers.cp314-win_amd64.pyd +0 -0
- sqlspec/core/query_modifiers.py +508 -0
- sqlspec/core/result/__init__.py +25 -0
- sqlspec/core/result/_base.cp314-win_amd64.pyd +0 -0
- sqlspec/core/result/_base.py +1232 -0
- sqlspec/core/result/_io.cp314-win_amd64.pyd +0 -0
- sqlspec/core/result/_io.py +28 -0
- sqlspec/core/splitter.cp314-win_amd64.pyd +0 -0
- sqlspec/core/splitter.py +1021 -0
- sqlspec/core/sqlcommenter.cp314-win_amd64.pyd +0 -0
- sqlspec/core/sqlcommenter.py +249 -0
- sqlspec/core/stack.cp314-win_amd64.pyd +0 -0
- sqlspec/core/stack.py +163 -0
- sqlspec/core/statement.cp314-win_amd64.pyd +0 -0
- sqlspec/core/statement.py +1865 -0
- sqlspec/core/type_converter.cp314-win_amd64.pyd +0 -0
- sqlspec/core/type_converter.py +340 -0
- sqlspec/data_dictionary/__init__.py +22 -0
- sqlspec/data_dictionary/_loader.cp314-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_loader.py +138 -0
- sqlspec/data_dictionary/_registry.cp314-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_registry.py +74 -0
- sqlspec/data_dictionary/_types.cp314-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_types.py +121 -0
- sqlspec/data_dictionary/dialects/__init__.py +21 -0
- sqlspec/data_dictionary/dialects/bigquery.cp314-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/bigquery.py +81 -0
- sqlspec/data_dictionary/dialects/cockroachdb.cp314-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/cockroachdb.py +54 -0
- sqlspec/data_dictionary/dialects/duckdb.cp314-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/duckdb.py +47 -0
- sqlspec/data_dictionary/dialects/mysql.cp314-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/mysql.py +53 -0
- sqlspec/data_dictionary/dialects/oracle.cp314-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/oracle.py +197 -0
- sqlspec/data_dictionary/dialects/postgres.cp314-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/postgres.py +69 -0
- sqlspec/data_dictionary/dialects/spanner.cp314-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/spanner.py +37 -0
- sqlspec/data_dictionary/dialects/sqlite.cp314-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/sqlite.py +59 -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/dialects/__init__.py +22 -0
- sqlspec/dialects/_compat.cp314-win_amd64.pyd +0 -0
- sqlspec/dialects/_compat.py +14 -0
- sqlspec/dialects/postgres/__init__.py +9 -0
- sqlspec/dialects/postgres/_generators.cp314-win_amd64.pyd +0 -0
- sqlspec/dialects/postgres/_generators.py +57 -0
- sqlspec/dialects/postgres/_operators.cp314-win_amd64.pyd +0 -0
- sqlspec/dialects/postgres/_operators.py +81 -0
- sqlspec/dialects/postgres/_paradedb.py +50 -0
- sqlspec/dialects/postgres/_pgvector.py +36 -0
- sqlspec/dialects/spanner/__init__.py +6 -0
- sqlspec/dialects/spanner/_generators.cp314-win_amd64.pyd +0 -0
- sqlspec/dialects/spanner/_generators.py +206 -0
- sqlspec/dialects/spanner/_spangres.py +77 -0
- sqlspec/dialects/spanner/_spanner.py +179 -0
- sqlspec/driver/__init__.py +49 -0
- sqlspec/driver/_async.cp314-win_amd64.pyd +0 -0
- sqlspec/driver/_async.py +1830 -0
- sqlspec/driver/_common.cp314-win_amd64.pyd +0 -0
- sqlspec/driver/_common.py +2292 -0
- sqlspec/driver/_exception_handler.cp314-win_amd64.pyd +0 -0
- sqlspec/driver/_exception_handler.py +108 -0
- sqlspec/driver/_query_cache.cp314-win_amd64.pyd +0 -0
- sqlspec/driver/_query_cache.py +96 -0
- sqlspec/driver/_sql_helpers.cp314-win_amd64.pyd +0 -0
- sqlspec/driver/_sql_helpers.py +139 -0
- sqlspec/driver/_storage_helpers.cp314-win_amd64.pyd +0 -0
- sqlspec/driver/_storage_helpers.py +153 -0
- sqlspec/driver/_sync.cp314-win_amd64.pyd +0 -0
- sqlspec/driver/_sync.py +1817 -0
- sqlspec/exceptions.cp314-win_amd64.pyd +0 -0
- sqlspec/exceptions.py +480 -0
- sqlspec/extensions/__init__.py +0 -0
- sqlspec/extensions/adk/__init__.py +84 -0
- sqlspec/extensions/adk/_config_utils.py +199 -0
- sqlspec/extensions/adk/_types.cp314-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/_types.py +41 -0
- sqlspec/extensions/adk/artifact/__init__.py +57 -0
- sqlspec/extensions/adk/artifact/_types.cp314-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/artifact/_types.py +32 -0
- sqlspec/extensions/adk/artifact/service.py +508 -0
- sqlspec/extensions/adk/artifact/store.py +361 -0
- sqlspec/extensions/adk/converters.py +212 -0
- sqlspec/extensions/adk/memory/__init__.py +69 -0
- sqlspec/extensions/adk/memory/_types.cp314-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/memory/_types.py +30 -0
- sqlspec/extensions/adk/memory/converters.py +225 -0
- sqlspec/extensions/adk/memory/service.py +316 -0
- sqlspec/extensions/adk/memory/store.py +525 -0
- sqlspec/extensions/adk/migrations/0001_create_adk_tables.py +184 -0
- sqlspec/extensions/adk/migrations/__init__.py +0 -0
- sqlspec/extensions/adk/service.py +279 -0
- sqlspec/extensions/adk/store.py +590 -0
- sqlspec/extensions/events/__init__.py +51 -0
- sqlspec/extensions/events/_channel.py +703 -0
- sqlspec/extensions/events/_hints.cp314-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_hints.py +45 -0
- sqlspec/extensions/events/_models.py +23 -0
- sqlspec/extensions/events/_payload.cp314-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_payload.py +69 -0
- sqlspec/extensions/events/_protocols.py +134 -0
- sqlspec/extensions/events/_queue.py +462 -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 +22 -0
- sqlspec/extensions/fastapi/extension.py +391 -0
- sqlspec/extensions/fastapi/providers.cp314-win_amd64.pyd +0 -0
- sqlspec/extensions/fastapi/providers.py +712 -0
- sqlspec/extensions/flask/__init__.py +38 -0
- sqlspec/extensions/flask/_state.py +87 -0
- sqlspec/extensions/flask/_utils.py +71 -0
- sqlspec/extensions/flask/extension.py +539 -0
- sqlspec/extensions/litestar/__init__.py +31 -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 +1066 -0
- sqlspec/extensions/litestar/providers.cp314-win_amd64.pyd +0 -0
- sqlspec/extensions/litestar/providers.py +784 -0
- sqlspec/extensions/litestar/store.py +298 -0
- sqlspec/extensions/otel/__init__.py +58 -0
- sqlspec/extensions/prometheus/__init__.py +113 -0
- sqlspec/extensions/sanic/__init__.py +19 -0
- sqlspec/extensions/sanic/_state.py +43 -0
- sqlspec/extensions/sanic/_utils.py +127 -0
- sqlspec/extensions/sanic/extension.py +647 -0
- sqlspec/extensions/starlette/__init__.py +22 -0
- sqlspec/extensions/starlette/_state.py +42 -0
- sqlspec/extensions/starlette/_utils.py +96 -0
- sqlspec/extensions/starlette/extension.py +374 -0
- sqlspec/extensions/starlette/middleware.py +281 -0
- sqlspec/loader.cp314-win_amd64.pyd +0 -0
- sqlspec/loader.py +727 -0
- sqlspec/migrations/__init__.py +39 -0
- sqlspec/migrations/base.cp314-win_amd64.pyd +0 -0
- sqlspec/migrations/base.py +862 -0
- sqlspec/migrations/commands.py +2151 -0
- sqlspec/migrations/context.cp314-win_amd64.pyd +0 -0
- sqlspec/migrations/context.py +157 -0
- sqlspec/migrations/fix.cp314-win_amd64.pyd +0 -0
- sqlspec/migrations/fix.py +204 -0
- sqlspec/migrations/loaders.cp314-win_amd64.pyd +0 -0
- sqlspec/migrations/loaders.py +443 -0
- sqlspec/migrations/runner.cp314-win_amd64.pyd +0 -0
- sqlspec/migrations/runner.py +1195 -0
- sqlspec/migrations/squash.cp314-win_amd64.pyd +0 -0
- sqlspec/migrations/squash.py +490 -0
- sqlspec/migrations/templates.cp314-win_amd64.pyd +0 -0
- sqlspec/migrations/templates.py +234 -0
- sqlspec/migrations/tracker.cp314-win_amd64.pyd +0 -0
- sqlspec/migrations/tracker.py +792 -0
- sqlspec/migrations/utils.cp314-win_amd64.pyd +0 -0
- sqlspec/migrations/utils.py +256 -0
- sqlspec/migrations/validation.cp314-win_amd64.pyd +0 -0
- sqlspec/migrations/validation.py +359 -0
- sqlspec/migrations/version.cp314-win_amd64.pyd +0 -0
- sqlspec/migrations/version.py +446 -0
- sqlspec/observability/__init__.py +57 -0
- sqlspec/observability/_common.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_common.py +77 -0
- sqlspec/observability/_config.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_config.py +364 -0
- sqlspec/observability/_diagnostics.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_diagnostics.py +74 -0
- sqlspec/observability/_dispatcher.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_dispatcher.py +200 -0
- sqlspec/observability/_formatters/__init__.py +13 -0
- sqlspec/observability/_formatters/_aws.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_aws.py +102 -0
- sqlspec/observability/_formatters/_azure.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_azure.py +96 -0
- sqlspec/observability/_formatters/_base.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_base.py +57 -0
- sqlspec/observability/_formatters/_gcp.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_gcp.py +131 -0
- sqlspec/observability/_formatting.py +58 -0
- sqlspec/observability/_observer.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_observer.py +361 -0
- sqlspec/observability/_runtime.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_runtime.py +461 -0
- sqlspec/observability/_sampling.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_sampling.py +188 -0
- sqlspec/observability/_spans.cp314-win_amd64.pyd +0 -0
- sqlspec/observability/_spans.py +161 -0
- sqlspec/protocols.py +955 -0
- sqlspec/py.typed +0 -0
- sqlspec/service.py +433 -0
- sqlspec/storage/__init__.py +48 -0
- sqlspec/storage/_arrow_payload.py +68 -0
- sqlspec/storage/_paths.cp314-win_amd64.pyd +0 -0
- sqlspec/storage/_paths.py +58 -0
- sqlspec/storage/_utils.py +46 -0
- sqlspec/storage/backends/__init__.py +1 -0
- sqlspec/storage/backends/base.cp314-win_amd64.pyd +0 -0
- sqlspec/storage/backends/base.py +374 -0
- sqlspec/storage/backends/fsspec.py +574 -0
- sqlspec/storage/backends/local.py +468 -0
- sqlspec/storage/backends/obstore.py +956 -0
- sqlspec/storage/errors.cp314-win_amd64.pyd +0 -0
- sqlspec/storage/errors.py +102 -0
- sqlspec/storage/pipeline.cp314-win_amd64.pyd +0 -0
- sqlspec/storage/pipeline.py +628 -0
- sqlspec/storage/registry.cp314-win_amd64.pyd +0 -0
- sqlspec/storage/registry.py +329 -0
- sqlspec/typing.py +405 -0
- sqlspec/utils/__init__.py +7 -0
- sqlspec/utils/arrow_helpers.py +384 -0
- sqlspec/utils/config_tools.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/config_tools.py +314 -0
- sqlspec/utils/correlation.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/correlation.py +134 -0
- sqlspec/utils/deprecation.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/deprecation.py +157 -0
- sqlspec/utils/dispatch.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/dispatch.py +101 -0
- sqlspec/utils/fixtures.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/fixtures.py +260 -0
- sqlspec/utils/logging.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/logging.py +251 -0
- sqlspec/utils/module_loader.py +306 -0
- sqlspec/utils/portal.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/portal.py +377 -0
- sqlspec/utils/schema.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/schema.py +1040 -0
- sqlspec/utils/serializers/__init__.py +30 -0
- sqlspec/utils/serializers/_json.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_json.py +415 -0
- sqlspec/utils/serializers/_numpy.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_numpy.py +65 -0
- sqlspec/utils/serializers/_schema.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_schema.py +285 -0
- sqlspec/utils/singleton.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/singleton.py +41 -0
- sqlspec/utils/sync_tools.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/sync_tools.py +316 -0
- sqlspec/utils/text.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/text.py +109 -0
- sqlspec/utils/type_converters.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/type_converters.py +216 -0
- sqlspec/utils/type_guards.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/type_guards.py +1508 -0
- sqlspec/utils/uuids.cp314-win_amd64.pyd +0 -0
- sqlspec/utils/uuids.py +241 -0
- sqlspec-0.47.0.dist-info/METADATA +202 -0
- sqlspec-0.47.0.dist-info/RECORD +621 -0
- sqlspec-0.47.0.dist-info/WHEEL +4 -0
- sqlspec-0.47.0.dist-info/entry_points.txt +6 -0
- sqlspec-0.47.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
"""AsyncPG PostgreSQL driver implementation for async PostgreSQL operations."""
|
|
2
|
+
|
|
3
|
+
from collections import OrderedDict
|
|
4
|
+
from io import BytesIO
|
|
5
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
6
|
+
|
|
7
|
+
import asyncpg
|
|
8
|
+
|
|
9
|
+
from sqlspec.adapters.asyncpg._typing import AsyncpgCursor, AsyncpgSessionContext
|
|
10
|
+
from sqlspec.adapters.asyncpg.core import (
|
|
11
|
+
PREPARED_STATEMENT_CACHE_SIZE,
|
|
12
|
+
NormalizedStackOperation,
|
|
13
|
+
collect_rows,
|
|
14
|
+
create_mapped_exception,
|
|
15
|
+
default_statement_config,
|
|
16
|
+
driver_profile,
|
|
17
|
+
invoke_prepared_statement,
|
|
18
|
+
parse_status,
|
|
19
|
+
resolve_many_rowcount,
|
|
20
|
+
)
|
|
21
|
+
from sqlspec.adapters.asyncpg.data_dictionary import AsyncpgDataDictionary
|
|
22
|
+
from sqlspec.core import (
|
|
23
|
+
SQL,
|
|
24
|
+
StackResult,
|
|
25
|
+
StatementStack,
|
|
26
|
+
create_sql_result,
|
|
27
|
+
get_cache_config,
|
|
28
|
+
is_copy_from_operation,
|
|
29
|
+
is_copy_operation,
|
|
30
|
+
register_driver_profile,
|
|
31
|
+
)
|
|
32
|
+
from sqlspec.driver import (
|
|
33
|
+
AsyncDriverAdapterBase,
|
|
34
|
+
BaseAsyncExceptionHandler,
|
|
35
|
+
StackExecutionObserver,
|
|
36
|
+
describe_stack_statement,
|
|
37
|
+
)
|
|
38
|
+
from sqlspec.exceptions import SQLSpecError, StackExecutionError
|
|
39
|
+
from sqlspec.utils.logging import get_logger
|
|
40
|
+
from sqlspec.utils.type_guards import has_sqlstate
|
|
41
|
+
|
|
42
|
+
if TYPE_CHECKING:
|
|
43
|
+
from collections.abc import Sequence
|
|
44
|
+
|
|
45
|
+
from sqlspec.adapters.asyncpg._typing import AsyncpgConnection, AsyncpgPreparedStatement
|
|
46
|
+
from sqlspec.core import ArrowResult, SQLResult, StatementConfig
|
|
47
|
+
from sqlspec.driver import ExecutionResult
|
|
48
|
+
from sqlspec.storage import StorageBridgeJob, StorageDestination, StorageFormat, StorageTelemetry
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
__all__ = ("AsyncpgCursor", "AsyncpgDriver", "AsyncpgExceptionHandler", "AsyncpgSessionContext")
|
|
52
|
+
|
|
53
|
+
logger = get_logger("sqlspec.adapters.asyncpg")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class AsyncpgExceptionHandler(BaseAsyncExceptionHandler):
|
|
57
|
+
"""Async context manager for handling AsyncPG database exceptions.
|
|
58
|
+
|
|
59
|
+
Maps PostgreSQL SQLSTATE error codes to specific SQLSpec exceptions
|
|
60
|
+
for better error handling in application code.
|
|
61
|
+
|
|
62
|
+
Uses deferred exception pattern for mypyc compatibility: exceptions
|
|
63
|
+
are stored in pending_exception rather than raised from __aexit__
|
|
64
|
+
to avoid ABI boundary violations with compiled code.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
__slots__ = ()
|
|
68
|
+
|
|
69
|
+
def _handle_exception(self, exc_type: "type[BaseException] | None", exc_val: "BaseException") -> bool:
|
|
70
|
+
_ = exc_type
|
|
71
|
+
if isinstance(exc_val, asyncpg.PostgresError) or has_sqlstate(exc_val):
|
|
72
|
+
self.pending_exception = create_mapped_exception(exc_val)
|
|
73
|
+
return True
|
|
74
|
+
return False
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class AsyncpgDriver(AsyncDriverAdapterBase):
|
|
78
|
+
"""AsyncPG PostgreSQL driver for async database operations.
|
|
79
|
+
|
|
80
|
+
Supports COPY operations, numeric parameter style handling, PostgreSQL
|
|
81
|
+
exception handling, transaction management, SQL statement compilation
|
|
82
|
+
and caching, and parameter processing with type coercion.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
__slots__ = ("_data_dictionary", "_prepared_statements")
|
|
86
|
+
dialect = "postgres"
|
|
87
|
+
|
|
88
|
+
def __init__(
|
|
89
|
+
self,
|
|
90
|
+
connection: "AsyncpgConnection",
|
|
91
|
+
statement_config: "StatementConfig | None" = None,
|
|
92
|
+
driver_features: "dict[str, Any] | None" = None,
|
|
93
|
+
) -> None:
|
|
94
|
+
if statement_config is None:
|
|
95
|
+
statement_config = default_statement_config.replace(
|
|
96
|
+
enable_caching=get_cache_config().compiled_cache_enabled
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
super().__init__(connection=connection, statement_config=statement_config, driver_features=driver_features)
|
|
100
|
+
self._data_dictionary: AsyncpgDataDictionary | None = None
|
|
101
|
+
self._prepared_statements: OrderedDict[str, AsyncpgPreparedStatement] = OrderedDict()
|
|
102
|
+
|
|
103
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
104
|
+
# CORE DISPATCH METHODS
|
|
105
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
106
|
+
|
|
107
|
+
async def dispatch_execute(self, cursor: "AsyncpgConnection", statement: "SQL") -> "ExecutionResult":
|
|
108
|
+
"""Execute single SQL statement.
|
|
109
|
+
|
|
110
|
+
Handles both SELECT queries and non-SELECT operations.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
cursor: AsyncPG connection object
|
|
114
|
+
statement: SQL statement to execute
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
ExecutionResult with statement execution details
|
|
118
|
+
"""
|
|
119
|
+
sql, prepared_parameters = self._get_compiled_sql(statement, self.statement_config)
|
|
120
|
+
params: tuple[Any, ...] = cast("tuple[Any, ...]", prepared_parameters) if prepared_parameters else ()
|
|
121
|
+
|
|
122
|
+
if statement.returns_rows():
|
|
123
|
+
records = await cursor.fetch(sql, *params) if params else await cursor.fetch(sql)
|
|
124
|
+
data, column_names = collect_rows(records)
|
|
125
|
+
|
|
126
|
+
return self.create_execution_result(
|
|
127
|
+
cursor,
|
|
128
|
+
selected_data=data,
|
|
129
|
+
column_names=column_names,
|
|
130
|
+
data_row_count=len(data),
|
|
131
|
+
is_select_result=True,
|
|
132
|
+
row_format="record",
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
result = await cursor.execute(sql, *params) if params else await cursor.execute(sql)
|
|
136
|
+
|
|
137
|
+
affected_rows = parse_status(result)
|
|
138
|
+
|
|
139
|
+
return self.create_execution_result(cursor, rowcount_override=affected_rows)
|
|
140
|
+
|
|
141
|
+
async def dispatch_execute_many(self, cursor: "AsyncpgConnection", statement: "SQL") -> "ExecutionResult":
|
|
142
|
+
"""Execute SQL with multiple parameter sets using AsyncPG's executemany.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
cursor: AsyncPG connection object
|
|
146
|
+
statement: SQL statement with multiple parameter sets
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
ExecutionResult with batch execution details
|
|
150
|
+
"""
|
|
151
|
+
sql, prepared_parameters = self._get_compiled_sql(statement, self.statement_config)
|
|
152
|
+
|
|
153
|
+
if prepared_parameters:
|
|
154
|
+
parameter_sets = cast("list[Sequence[object]]", prepared_parameters)
|
|
155
|
+
await cursor.executemany(sql, parameter_sets)
|
|
156
|
+
affected_rows = resolve_many_rowcount(parameter_sets)
|
|
157
|
+
else:
|
|
158
|
+
affected_rows = 0
|
|
159
|
+
|
|
160
|
+
return self.create_execution_result(cursor, rowcount_override=affected_rows, is_many_result=True)
|
|
161
|
+
|
|
162
|
+
async def dispatch_execute_script(self, cursor: "AsyncpgConnection", statement: "SQL") -> "ExecutionResult":
|
|
163
|
+
"""Execute SQL script with statement splitting and parameter handling.
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
cursor: AsyncPG connection object
|
|
167
|
+
statement: SQL statement containing multiple statements
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
ExecutionResult with script execution details
|
|
171
|
+
"""
|
|
172
|
+
sql, _ = self._get_compiled_sql(statement, self.statement_config)
|
|
173
|
+
statements = self.split_script_statements(sql, statement.statement_config, strip_trailing_semicolon=True)
|
|
174
|
+
|
|
175
|
+
successful_count = 0
|
|
176
|
+
last_result = None
|
|
177
|
+
|
|
178
|
+
for stmt in statements:
|
|
179
|
+
result = await cursor.execute(stmt)
|
|
180
|
+
last_result = result
|
|
181
|
+
successful_count += 1
|
|
182
|
+
|
|
183
|
+
return self.create_execution_result(
|
|
184
|
+
last_result, statement_count=len(statements), successful_statements=successful_count, is_script_result=True
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
async def dispatch_special_handling(self, cursor: "AsyncpgConnection", statement: "SQL") -> "SQLResult | None":
|
|
188
|
+
"""Handle PostgreSQL COPY operations and other special cases.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
cursor: AsyncPG connection object
|
|
192
|
+
statement: SQL statement to analyze
|
|
193
|
+
|
|
194
|
+
Returns:
|
|
195
|
+
SQLResult if special operation was handled, None for standard execution
|
|
196
|
+
"""
|
|
197
|
+
if is_copy_operation(statement.operation_type):
|
|
198
|
+
await self._handle_copy_operation(cursor, statement)
|
|
199
|
+
return self.build_statement_result(statement, self.create_execution_result(cursor))
|
|
200
|
+
|
|
201
|
+
return None
|
|
202
|
+
|
|
203
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
204
|
+
# TRANSACTION MANAGEMENT
|
|
205
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
206
|
+
|
|
207
|
+
async def begin(self) -> None:
|
|
208
|
+
"""Begin a database transaction."""
|
|
209
|
+
try:
|
|
210
|
+
await self.connection.execute("BEGIN")
|
|
211
|
+
except asyncpg.PostgresError as e:
|
|
212
|
+
msg = f"Failed to begin async transaction: {e}"
|
|
213
|
+
raise SQLSpecError(msg) from e
|
|
214
|
+
|
|
215
|
+
async def commit(self) -> None:
|
|
216
|
+
"""Commit the current transaction."""
|
|
217
|
+
try:
|
|
218
|
+
await self.connection.execute("COMMIT")
|
|
219
|
+
except asyncpg.PostgresError as e:
|
|
220
|
+
msg = f"Failed to commit async transaction: {e}"
|
|
221
|
+
raise SQLSpecError(msg) from e
|
|
222
|
+
|
|
223
|
+
async def rollback(self) -> None:
|
|
224
|
+
"""Rollback the current transaction."""
|
|
225
|
+
try:
|
|
226
|
+
await self.connection.execute("ROLLBACK")
|
|
227
|
+
except asyncpg.PostgresError as e:
|
|
228
|
+
msg = f"Failed to rollback async transaction: {e}"
|
|
229
|
+
raise SQLSpecError(msg) from e
|
|
230
|
+
|
|
231
|
+
def with_cursor(self, connection: "AsyncpgConnection") -> "AsyncpgCursor":
|
|
232
|
+
"""Create context manager for AsyncPG cursor."""
|
|
233
|
+
return AsyncpgCursor(connection)
|
|
234
|
+
|
|
235
|
+
def handle_database_exceptions(self) -> "AsyncpgExceptionHandler":
|
|
236
|
+
"""Handle database exceptions with PostgreSQL error codes."""
|
|
237
|
+
return AsyncpgExceptionHandler()
|
|
238
|
+
|
|
239
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
240
|
+
# STACK EXECUTION METHODS
|
|
241
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
242
|
+
|
|
243
|
+
async def execute_stack(
|
|
244
|
+
self, stack: "StatementStack", *, continue_on_error: bool = False
|
|
245
|
+
) -> "tuple[StackResult, ...]":
|
|
246
|
+
"""Execute a StatementStack using asyncpg's rapid batching."""
|
|
247
|
+
|
|
248
|
+
if not isinstance(stack, StatementStack) or not stack or self.stack_native_disabled:
|
|
249
|
+
return await super().execute_stack(stack, continue_on_error=continue_on_error)
|
|
250
|
+
|
|
251
|
+
return await self._execute_stack_native(stack, continue_on_error=continue_on_error)
|
|
252
|
+
|
|
253
|
+
async def _execute_stack_native(
|
|
254
|
+
self, stack: "StatementStack", *, continue_on_error: bool
|
|
255
|
+
) -> "tuple[StackResult, ...]":
|
|
256
|
+
results: list[StackResult] = []
|
|
257
|
+
|
|
258
|
+
transaction_cm = None
|
|
259
|
+
if not continue_on_error and not self._connection_in_transaction():
|
|
260
|
+
transaction_cm = self.connection.transaction()
|
|
261
|
+
|
|
262
|
+
with StackExecutionObserver(self, stack, continue_on_error, native_pipeline=True) as observer:
|
|
263
|
+
if transaction_cm is not None:
|
|
264
|
+
async with transaction_cm:
|
|
265
|
+
await self._run_stack_operations(stack, continue_on_error, observer, results)
|
|
266
|
+
else:
|
|
267
|
+
await self._run_stack_operations(stack, continue_on_error, observer, results)
|
|
268
|
+
|
|
269
|
+
return tuple(results)
|
|
270
|
+
|
|
271
|
+
async def _run_stack_operations(
|
|
272
|
+
self,
|
|
273
|
+
stack: "StatementStack",
|
|
274
|
+
continue_on_error: bool,
|
|
275
|
+
observer: "StackExecutionObserver",
|
|
276
|
+
results: "list[StackResult]",
|
|
277
|
+
) -> None:
|
|
278
|
+
"""Run operations for statement stack execution.
|
|
279
|
+
|
|
280
|
+
Extracted from _execute_stack_native to avoid closure compilation issues.
|
|
281
|
+
"""
|
|
282
|
+
for index, operation in enumerate(stack.operations):
|
|
283
|
+
try:
|
|
284
|
+
normalized: NormalizedStackOperation | None = None
|
|
285
|
+
if operation.method == "execute":
|
|
286
|
+
kwargs = dict(operation.keyword_arguments) if operation.keyword_arguments else {}
|
|
287
|
+
statement_config = kwargs.pop("statement_config", None)
|
|
288
|
+
config = statement_config or self.statement_config
|
|
289
|
+
|
|
290
|
+
sql_statement = self.prepare_statement(
|
|
291
|
+
operation.statement, operation.arguments, statement_config=config, kwargs=kwargs
|
|
292
|
+
)
|
|
293
|
+
if not sql_statement.is_script and not sql_statement.is_many:
|
|
294
|
+
sql_text, prepared_parameters = self._get_compiled_sql(sql_statement, config)
|
|
295
|
+
prepared_parameters = cast("tuple[Any, ...] | dict[str, Any] | None", prepared_parameters)
|
|
296
|
+
normalized = NormalizedStackOperation(
|
|
297
|
+
operation=operation, statement=sql_statement, sql=sql_text, parameters=prepared_parameters
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
if normalized is not None:
|
|
301
|
+
stack_result = await self._execute_stack_operation_prepared(normalized)
|
|
302
|
+
else:
|
|
303
|
+
result = await self._execute_stack_operation(operation)
|
|
304
|
+
stack_result = StackResult(result=result)
|
|
305
|
+
except Exception as exc:
|
|
306
|
+
stack_error = StackExecutionError(
|
|
307
|
+
index,
|
|
308
|
+
describe_stack_statement(operation.statement),
|
|
309
|
+
exc,
|
|
310
|
+
adapter=type(self).__name__,
|
|
311
|
+
mode="continue-on-error" if continue_on_error else "fail-fast",
|
|
312
|
+
)
|
|
313
|
+
if continue_on_error:
|
|
314
|
+
observer.record_operation_error(stack_error)
|
|
315
|
+
results.append(StackResult.from_error(stack_error))
|
|
316
|
+
continue
|
|
317
|
+
raise stack_error from exc
|
|
318
|
+
|
|
319
|
+
results.append(stack_result)
|
|
320
|
+
|
|
321
|
+
async def _execute_stack_operation_prepared(self, normalized: "NormalizedStackOperation") -> StackResult:
|
|
322
|
+
prepared = await self._get_prepared_statement(normalized.sql)
|
|
323
|
+
metadata = {"prepared_statement": True}
|
|
324
|
+
|
|
325
|
+
if normalized.statement.returns_rows():
|
|
326
|
+
rows = await invoke_prepared_statement(prepared, normalized.parameters, fetch=True)
|
|
327
|
+
data, _ = collect_rows(rows)
|
|
328
|
+
sql_result = create_sql_result(
|
|
329
|
+
normalized.statement, data=data, rows_affected=len(data), metadata=metadata, row_format="record"
|
|
330
|
+
)
|
|
331
|
+
return StackResult.from_sql_result(sql_result)
|
|
332
|
+
|
|
333
|
+
status = await invoke_prepared_statement(prepared, normalized.parameters, fetch=False)
|
|
334
|
+
rowcount = parse_status(status)
|
|
335
|
+
sql_result = create_sql_result(normalized.statement, rows_affected=rowcount, metadata=metadata)
|
|
336
|
+
return StackResult.from_sql_result(sql_result)
|
|
337
|
+
|
|
338
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
339
|
+
# STORAGE API METHODS
|
|
340
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
341
|
+
|
|
342
|
+
async def select_to_storage(
|
|
343
|
+
self,
|
|
344
|
+
statement: "SQL | str",
|
|
345
|
+
destination: "StorageDestination",
|
|
346
|
+
/,
|
|
347
|
+
*parameters: Any,
|
|
348
|
+
statement_config: "StatementConfig | None" = None,
|
|
349
|
+
partitioner: "dict[str, object] | None" = None,
|
|
350
|
+
format_hint: "StorageFormat | None" = None,
|
|
351
|
+
telemetry: "StorageTelemetry | None" = None,
|
|
352
|
+
**kwargs: Any,
|
|
353
|
+
) -> "StorageBridgeJob":
|
|
354
|
+
"""Execute a query and persist results to storage once native COPY is available."""
|
|
355
|
+
|
|
356
|
+
self._require_capability("arrow_export_enabled")
|
|
357
|
+
arrow_result = await self.select_to_arrow(statement, *parameters, statement_config=statement_config, **kwargs)
|
|
358
|
+
async_pipeline = self._storage_pipeline()
|
|
359
|
+
telemetry_payload = await self._write_result_to_storage_async(
|
|
360
|
+
arrow_result, destination, format_hint=format_hint, pipeline=async_pipeline
|
|
361
|
+
)
|
|
362
|
+
self._attach_partition_telemetry(telemetry_payload, partitioner)
|
|
363
|
+
return self._create_storage_job(telemetry_payload, telemetry)
|
|
364
|
+
|
|
365
|
+
async def load_from_arrow(
|
|
366
|
+
self,
|
|
367
|
+
table: str,
|
|
368
|
+
source: "ArrowResult | Any",
|
|
369
|
+
*,
|
|
370
|
+
partitioner: "dict[str, object] | None" = None,
|
|
371
|
+
overwrite: bool = False,
|
|
372
|
+
telemetry: "StorageTelemetry | None" = None,
|
|
373
|
+
) -> "StorageBridgeJob":
|
|
374
|
+
"""Load Arrow data into a PostgreSQL table via COPY."""
|
|
375
|
+
|
|
376
|
+
self._require_capability("arrow_import_enabled")
|
|
377
|
+
arrow_table = self._coerce_arrow_table(source)
|
|
378
|
+
if overwrite:
|
|
379
|
+
try:
|
|
380
|
+
await self.connection.execute(f"TRUNCATE TABLE {table}")
|
|
381
|
+
except asyncpg.PostgresError as exc:
|
|
382
|
+
msg = f"Failed to truncate table '{table}': {exc}"
|
|
383
|
+
raise SQLSpecError(msg) from exc
|
|
384
|
+
columns, records = self._arrow_table_to_rows(arrow_table)
|
|
385
|
+
if records:
|
|
386
|
+
await self.connection.copy_records_to_table(table, records=records, columns=columns)
|
|
387
|
+
telemetry_payload = self._build_ingest_telemetry(arrow_table)
|
|
388
|
+
telemetry_payload["destination"] = table
|
|
389
|
+
self._attach_partition_telemetry(telemetry_payload, partitioner)
|
|
390
|
+
return self._create_storage_job(telemetry_payload, telemetry)
|
|
391
|
+
|
|
392
|
+
async def load_from_storage(
|
|
393
|
+
self,
|
|
394
|
+
table: str,
|
|
395
|
+
source: "StorageDestination",
|
|
396
|
+
*,
|
|
397
|
+
file_format: "StorageFormat",
|
|
398
|
+
partitioner: "dict[str, object] | None" = None,
|
|
399
|
+
overwrite: bool = False,
|
|
400
|
+
) -> "StorageBridgeJob":
|
|
401
|
+
"""Read an artifact from storage and ingest it via COPY."""
|
|
402
|
+
|
|
403
|
+
arrow_table, inbound = await self._read_arrow_from_storage_async(source, file_format=file_format)
|
|
404
|
+
return await self.load_from_arrow(
|
|
405
|
+
table, arrow_table, partitioner=partitioner, overwrite=overwrite, telemetry=inbound
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
409
|
+
# UTILITY METHODS
|
|
410
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
411
|
+
|
|
412
|
+
@property
|
|
413
|
+
def data_dictionary(self) -> "AsyncpgDataDictionary":
|
|
414
|
+
"""Get the data dictionary for this driver.
|
|
415
|
+
|
|
416
|
+
Returns:
|
|
417
|
+
Data dictionary instance for metadata queries
|
|
418
|
+
"""
|
|
419
|
+
if self._data_dictionary is None:
|
|
420
|
+
self._data_dictionary = AsyncpgDataDictionary()
|
|
421
|
+
return self._data_dictionary
|
|
422
|
+
|
|
423
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
424
|
+
# PRIVATE/INTERNAL METHODS
|
|
425
|
+
# ─────────────────────────────────────────────────────────────────────────────
|
|
426
|
+
|
|
427
|
+
def collect_rows(self, cursor: "AsyncpgConnection", fetched: "list[Any]") -> "tuple[list[Any], list[str], int]":
|
|
428
|
+
"""Collect asyncpg rows for the direct execution path."""
|
|
429
|
+
data, column_names = collect_rows(fetched)
|
|
430
|
+
return data, column_names, len(data)
|
|
431
|
+
|
|
432
|
+
def resolve_rowcount(self, cursor: "AsyncpgConnection") -> int:
|
|
433
|
+
"""Resolve rowcount from asyncpg status for the direct execution path."""
|
|
434
|
+
return parse_status(cursor)
|
|
435
|
+
|
|
436
|
+
def _connection_in_transaction(self) -> bool:
|
|
437
|
+
"""Check if connection is in transaction."""
|
|
438
|
+
return bool(self.connection.is_in_transaction())
|
|
439
|
+
|
|
440
|
+
async def _get_prepared_statement(self, sql: str) -> "AsyncpgPreparedStatement":
|
|
441
|
+
cached = self._prepared_statements.get(sql)
|
|
442
|
+
if cached is not None:
|
|
443
|
+
self._prepared_statements.move_to_end(sql)
|
|
444
|
+
return cached
|
|
445
|
+
|
|
446
|
+
prepared = cast("AsyncpgPreparedStatement", await self.connection.prepare(sql))
|
|
447
|
+
self._prepared_statements[sql] = prepared
|
|
448
|
+
if len(self._prepared_statements) > PREPARED_STATEMENT_CACHE_SIZE:
|
|
449
|
+
self._prepared_statements.popitem(last=False)
|
|
450
|
+
return prepared
|
|
451
|
+
|
|
452
|
+
async def _handle_copy_operation(self, cursor: "AsyncpgConnection", statement: "SQL") -> None:
|
|
453
|
+
"""Handle PostgreSQL COPY operations.
|
|
454
|
+
|
|
455
|
+
Supports both COPY FROM STDIN and COPY TO STDOUT operations.
|
|
456
|
+
|
|
457
|
+
Args:
|
|
458
|
+
cursor: AsyncPG connection object
|
|
459
|
+
statement: SQL statement with COPY operation
|
|
460
|
+
"""
|
|
461
|
+
|
|
462
|
+
execution_args = statement.statement_config.execution_args
|
|
463
|
+
metadata: dict[str, Any] = dict(execution_args) if execution_args else {}
|
|
464
|
+
sql_text, _ = self._get_compiled_sql(statement, statement.statement_config)
|
|
465
|
+
sql_upper = sql_text.upper()
|
|
466
|
+
copy_data = metadata.get("postgres_copy_data")
|
|
467
|
+
|
|
468
|
+
if copy_data and is_copy_from_operation(statement.operation_type) and "FROM STDIN" in sql_upper:
|
|
469
|
+
if isinstance(copy_data, dict):
|
|
470
|
+
data_str = (
|
|
471
|
+
str(next(iter(copy_data.values())))
|
|
472
|
+
if len(copy_data) == 1
|
|
473
|
+
else "\n".join(str(value) for value in copy_data.values())
|
|
474
|
+
)
|
|
475
|
+
elif isinstance(copy_data, (list, tuple)):
|
|
476
|
+
data_str = str(copy_data[0]) if len(copy_data) == 1 else "\n".join(str(value) for value in copy_data)
|
|
477
|
+
else:
|
|
478
|
+
data_str = str(copy_data)
|
|
479
|
+
|
|
480
|
+
data_io = BytesIO(data_str.encode("utf-8"))
|
|
481
|
+
await cursor.copy_from_query(sql_text, output=data_io)
|
|
482
|
+
return
|
|
483
|
+
|
|
484
|
+
await cursor.execute(sql_text)
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
register_driver_profile("asyncpg", driver_profile)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Events helpers for the asyncpg adapter."""
|
|
2
|
+
|
|
3
|
+
from sqlspec.adapters.asyncpg.events.backend import AsyncpgEventsBackend, create_event_backend
|
|
4
|
+
from sqlspec.adapters.asyncpg.events.store import AsyncpgEventQueueStore
|
|
5
|
+
|
|
6
|
+
__all__ = ("AsyncpgEventQueueStore", "AsyncpgEventsBackend", "create_event_backend")
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"""Persistent LISTEN/NOTIFY hub used by asyncpg event backends.
|
|
2
|
+
|
|
3
|
+
Owns a single dedicated asyncpg connection per backend instance. Subscribe /
|
|
4
|
+
unsubscribe are serialized under an asyncio.Lock so concurrent callers cannot
|
|
5
|
+
race on the shared connection (the asyncpg.InterfaceError "another operation
|
|
6
|
+
is in progress" hazard). asyncpg's per-channel add_listener callback fans
|
|
7
|
+
notifications into one queue per consumer task.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
# pyright: reportPrivateUsage=false
|
|
11
|
+
|
|
12
|
+
import asyncio
|
|
13
|
+
import contextlib
|
|
14
|
+
from typing import TYPE_CHECKING, Any
|
|
15
|
+
from weakref import WeakKeyDictionary
|
|
16
|
+
|
|
17
|
+
from sqlspec.exceptions import EventChannelError
|
|
18
|
+
from sqlspec.extensions.events import normalize_event_channel_name
|
|
19
|
+
from sqlspec.utils.logging import get_logger
|
|
20
|
+
from sqlspec.utils.type_guards import has_add_listener
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from collections.abc import Callable
|
|
24
|
+
|
|
25
|
+
from sqlspec.adapters.asyncpg.config import AsyncpgConfig
|
|
26
|
+
|
|
27
|
+
logger = get_logger("sqlspec.adapters.asyncpg.events.hub")
|
|
28
|
+
|
|
29
|
+
__all__ = ("AsyncpgListenerHub",)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class AsyncpgListenerHub:
|
|
33
|
+
"""Per-channel persistent listener for asyncpg-based event backends."""
|
|
34
|
+
|
|
35
|
+
__slots__ = (
|
|
36
|
+
"_callbacks",
|
|
37
|
+
"_config",
|
|
38
|
+
"_connection",
|
|
39
|
+
"_connection_cm",
|
|
40
|
+
"_lock",
|
|
41
|
+
"_pool_destroying_registered",
|
|
42
|
+
"_queues",
|
|
43
|
+
"_shutting_down",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def __init__(self, config: "AsyncpgConfig") -> None:
|
|
47
|
+
self._config = config
|
|
48
|
+
self._lock = asyncio.Lock()
|
|
49
|
+
self._queues: dict[str, WeakKeyDictionary[asyncio.Task[Any], asyncio.Queue[str]]] = {}
|
|
50
|
+
self._callbacks: dict[str, Callable[..., None]] = {}
|
|
51
|
+
self._connection_cm: Any | None = None
|
|
52
|
+
self._connection: Any | None = None
|
|
53
|
+
self._shutting_down = False
|
|
54
|
+
self._pool_destroying_registered = False
|
|
55
|
+
|
|
56
|
+
async def subscribe(self, channel: str) -> None:
|
|
57
|
+
async with self._lock:
|
|
58
|
+
if self._shutting_down:
|
|
59
|
+
msg = "AsyncpgListenerHub is shutting down"
|
|
60
|
+
raise RuntimeError(msg)
|
|
61
|
+
if channel in self._queues:
|
|
62
|
+
return
|
|
63
|
+
await self._ensure_connection_locked()
|
|
64
|
+
validated = normalize_event_channel_name(channel)
|
|
65
|
+
connection = self._connection
|
|
66
|
+
assert connection is not None
|
|
67
|
+
|
|
68
|
+
def _callback(_conn: Any, _pid: int, notified_channel: str, payload: str) -> None:
|
|
69
|
+
self._dispatch(notified_channel, payload)
|
|
70
|
+
|
|
71
|
+
self._queues[channel] = WeakKeyDictionary()
|
|
72
|
+
self._callbacks[channel] = _callback
|
|
73
|
+
try:
|
|
74
|
+
await connection.execute(f"LISTEN {validated}")
|
|
75
|
+
await connection.add_listener(channel, _callback)
|
|
76
|
+
except Exception:
|
|
77
|
+
self._queues.pop(channel, None)
|
|
78
|
+
self._callbacks.pop(channel, None)
|
|
79
|
+
raise
|
|
80
|
+
|
|
81
|
+
async def unsubscribe(self, channel: str) -> None:
|
|
82
|
+
async with self._lock:
|
|
83
|
+
if channel not in self._queues:
|
|
84
|
+
return
|
|
85
|
+
connection = self._connection
|
|
86
|
+
callback = self._callbacks.pop(channel, None)
|
|
87
|
+
self._queues.pop(channel, None)
|
|
88
|
+
if connection is None:
|
|
89
|
+
return
|
|
90
|
+
if callback is not None:
|
|
91
|
+
with contextlib.suppress(Exception):
|
|
92
|
+
await connection.remove_listener(channel, callback)
|
|
93
|
+
validated = normalize_event_channel_name(channel)
|
|
94
|
+
with contextlib.suppress(Exception):
|
|
95
|
+
await connection.execute(f"UNLISTEN {validated}")
|
|
96
|
+
|
|
97
|
+
async def dequeue(self, channel: str, poll_interval: float) -> "str | None":
|
|
98
|
+
if channel not in self._queues:
|
|
99
|
+
await self.subscribe(channel)
|
|
100
|
+
queue = self._get_consumer_queue(channel)
|
|
101
|
+
if queue is None:
|
|
102
|
+
return None
|
|
103
|
+
try:
|
|
104
|
+
return await asyncio.wait_for(queue.get(), timeout=poll_interval)
|
|
105
|
+
except asyncio.TimeoutError:
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
async def shutdown(self) -> None:
|
|
109
|
+
async with self._lock:
|
|
110
|
+
if self._shutting_down:
|
|
111
|
+
return
|
|
112
|
+
self._shutting_down = True
|
|
113
|
+
connection = self._connection
|
|
114
|
+
connection_cm = self._connection_cm
|
|
115
|
+
channels = list(self._queues.keys())
|
|
116
|
+
callbacks = dict(self._callbacks)
|
|
117
|
+
self._queues.clear()
|
|
118
|
+
self._callbacks.clear()
|
|
119
|
+
self._connection = None
|
|
120
|
+
self._connection_cm = None
|
|
121
|
+
if connection is not None:
|
|
122
|
+
for channel in channels:
|
|
123
|
+
callback = callbacks.get(channel)
|
|
124
|
+
if callback is not None:
|
|
125
|
+
with contextlib.suppress(Exception):
|
|
126
|
+
await connection.remove_listener(channel, callback)
|
|
127
|
+
validated = normalize_event_channel_name(channel)
|
|
128
|
+
with contextlib.suppress(Exception):
|
|
129
|
+
await connection.execute(f"UNLISTEN {validated}")
|
|
130
|
+
if connection_cm is not None:
|
|
131
|
+
with contextlib.suppress(Exception):
|
|
132
|
+
await connection_cm.__aexit__(None, None, None)
|
|
133
|
+
self._shutting_down = False
|
|
134
|
+
|
|
135
|
+
def is_subscribed(self, channel: str) -> bool:
|
|
136
|
+
return channel in self._queues
|
|
137
|
+
|
|
138
|
+
def _get_consumer_queue(self, channel: str) -> "asyncio.Queue[str] | None":
|
|
139
|
+
task = asyncio.current_task()
|
|
140
|
+
if task is None: # pragma: no cover - coroutine dequeue calls always run in a task
|
|
141
|
+
msg = "AsyncpgListenerHub.dequeue requires an active asyncio task"
|
|
142
|
+
raise RuntimeError(msg)
|
|
143
|
+
queues = self._queues.get(channel)
|
|
144
|
+
if queues is None:
|
|
145
|
+
return None
|
|
146
|
+
queue = queues.get(task)
|
|
147
|
+
if queue is None:
|
|
148
|
+
queue = asyncio.Queue()
|
|
149
|
+
queues[task] = queue
|
|
150
|
+
return queue
|
|
151
|
+
|
|
152
|
+
async def _ensure_connection_locked(self) -> None:
|
|
153
|
+
if self._connection is not None:
|
|
154
|
+
return
|
|
155
|
+
connection_cm = self._config.provide_connection()
|
|
156
|
+
connection = await connection_cm.__aenter__()
|
|
157
|
+
if connection is None or not has_add_listener(connection):
|
|
158
|
+
with contextlib.suppress(Exception):
|
|
159
|
+
await connection_cm.__aexit__(None, None, None)
|
|
160
|
+
msg = "PostgreSQL connection does not support LISTEN/NOTIFY callbacks"
|
|
161
|
+
raise EventChannelError(msg)
|
|
162
|
+
self._connection_cm = connection_cm
|
|
163
|
+
self._connection = connection
|
|
164
|
+
self._register_pool_destroying()
|
|
165
|
+
|
|
166
|
+
def _register_pool_destroying(self) -> None:
|
|
167
|
+
if self._pool_destroying_registered:
|
|
168
|
+
return
|
|
169
|
+
runtime = self._config.get_observability_runtime()
|
|
170
|
+
runtime.register_lifecycle_hook("on_pool_destroying", self._pool_destroying_hook)
|
|
171
|
+
self._pool_destroying_registered = True
|
|
172
|
+
|
|
173
|
+
def _pool_destroying_hook(self, _context: "dict[str, Any]") -> "Any":
|
|
174
|
+
return self.shutdown()
|
|
175
|
+
|
|
176
|
+
def _dispatch(self, channel: str, payload: str) -> None:
|
|
177
|
+
queues = self._queues.get(channel)
|
|
178
|
+
if queues is None:
|
|
179
|
+
return
|
|
180
|
+
for queue in list(queues.values()):
|
|
181
|
+
queue.put_nowait(payload)
|