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,695 @@
|
|
|
1
|
+
"""Psycopg database configuration with direct field-based configuration."""
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, ClassVar, TypedDict, cast
|
|
4
|
+
|
|
5
|
+
from mypy_extensions import mypyc_attr
|
|
6
|
+
from psycopg_pool import AsyncConnectionPool, ConnectionPool
|
|
7
|
+
from typing_extensions import NotRequired
|
|
8
|
+
|
|
9
|
+
from sqlspec.adapters.psycopg._typing import (
|
|
10
|
+
PsycopgAsyncConnection,
|
|
11
|
+
PsycopgAsyncCursor,
|
|
12
|
+
PsycopgAsyncSessionContext,
|
|
13
|
+
PsycopgSyncConnection,
|
|
14
|
+
PsycopgSyncCursor,
|
|
15
|
+
PsycopgSyncSessionContext,
|
|
16
|
+
)
|
|
17
|
+
from sqlspec.adapters.psycopg.core import (
|
|
18
|
+
apply_driver_features,
|
|
19
|
+
build_postgres_extension_probe_names,
|
|
20
|
+
default_statement_config,
|
|
21
|
+
resolve_postgres_extension_state,
|
|
22
|
+
resolve_runtime_statement_config,
|
|
23
|
+
)
|
|
24
|
+
from sqlspec.adapters.psycopg.driver import (
|
|
25
|
+
PsycopgAsyncDriver,
|
|
26
|
+
PsycopgAsyncExceptionHandler,
|
|
27
|
+
PsycopgSyncDriver,
|
|
28
|
+
PsycopgSyncExceptionHandler,
|
|
29
|
+
)
|
|
30
|
+
from sqlspec.adapters.psycopg.type_converter import register_pgvector_async, register_pgvector_sync
|
|
31
|
+
from sqlspec.config import AsyncDatabaseConfig, ExtensionConfigs, SyncDatabaseConfig
|
|
32
|
+
from sqlspec.driver._async import AsyncPoolConnectionContext, AsyncPoolSessionFactory
|
|
33
|
+
from sqlspec.driver._sync import SyncPoolConnectionContext, SyncPoolSessionFactory
|
|
34
|
+
from sqlspec.exceptions import ImproperConfigurationError
|
|
35
|
+
from sqlspec.extensions.events import EventRuntimeHints
|
|
36
|
+
from sqlspec.utils.config_tools import normalize_connection_config
|
|
37
|
+
|
|
38
|
+
if TYPE_CHECKING:
|
|
39
|
+
from collections.abc import Awaitable, Callable
|
|
40
|
+
from types import TracebackType
|
|
41
|
+
|
|
42
|
+
from sqlspec.core import StatementConfig
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class PsycopgConnectionParams(TypedDict):
|
|
46
|
+
"""Psycopg connection parameters."""
|
|
47
|
+
|
|
48
|
+
conninfo: NotRequired[str]
|
|
49
|
+
host: NotRequired[str]
|
|
50
|
+
port: NotRequired[int]
|
|
51
|
+
user: NotRequired[str]
|
|
52
|
+
password: NotRequired[str]
|
|
53
|
+
dbname: NotRequired[str]
|
|
54
|
+
connect_timeout: NotRequired[int]
|
|
55
|
+
options: NotRequired[str]
|
|
56
|
+
application_name: NotRequired[str]
|
|
57
|
+
sslmode: NotRequired[str]
|
|
58
|
+
sslcert: NotRequired[str]
|
|
59
|
+
sslkey: NotRequired[str]
|
|
60
|
+
sslrootcert: NotRequired[str]
|
|
61
|
+
autocommit: NotRequired[bool]
|
|
62
|
+
extra: NotRequired["dict[str, Any]"]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class PsycopgPoolParams(PsycopgConnectionParams):
|
|
66
|
+
"""Psycopg pool parameters."""
|
|
67
|
+
|
|
68
|
+
min_size: NotRequired[int]
|
|
69
|
+
max_size: NotRequired[int]
|
|
70
|
+
name: NotRequired[str]
|
|
71
|
+
timeout: NotRequired[float]
|
|
72
|
+
max_waiting: NotRequired[int]
|
|
73
|
+
max_lifetime: NotRequired[float]
|
|
74
|
+
max_idle: NotRequired[float]
|
|
75
|
+
reconnect_timeout: NotRequired[float]
|
|
76
|
+
num_workers: NotRequired[int]
|
|
77
|
+
configure: NotRequired["Callable[..., Any]"]
|
|
78
|
+
kwargs: NotRequired["dict[str, Any]"]
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class PsycopgDriverFeatures(TypedDict):
|
|
82
|
+
"""Psycopg driver feature flags.
|
|
83
|
+
|
|
84
|
+
enable_pgvector: Enable automatic pgvector extension support for vector similarity search.
|
|
85
|
+
Requires pgvector-python package (pip install pgvector) and PostgreSQL with pgvector extension.
|
|
86
|
+
Defaults to True when pgvector-python is installed.
|
|
87
|
+
Provides automatic conversion between Python objects and PostgreSQL vector types.
|
|
88
|
+
Enables vector similarity operations and index support.
|
|
89
|
+
Set to False to disable pgvector support even when package is available.
|
|
90
|
+
enable_paradedb: Enable ParadeDB (pg_search) extension detection.
|
|
91
|
+
When enabled and the pg_search extension is detected, the SQL dialect
|
|
92
|
+
switches to "paradedb" which supports search operators (@@@, &&&, etc.)
|
|
93
|
+
and inherits all pgvector distance operators.
|
|
94
|
+
Defaults to True. Independent of enable_pgvector.
|
|
95
|
+
json_serializer: Custom JSON serializer for StatementConfig parameter handling.
|
|
96
|
+
json_deserializer: Custom JSON deserializer reference stored alongside the serializer for parity with asyncpg.
|
|
97
|
+
on_connection_create: Callback executed when a connection is created/acquired from the pool.
|
|
98
|
+
Receives the raw psycopg connection for low-level driver configuration.
|
|
99
|
+
Runs after internal setup (pgvector registration).
|
|
100
|
+
For sync config: Callable[[PsycopgSyncConnection], None]
|
|
101
|
+
For async config: Callable[[PsycopgAsyncConnection], Awaitable[None]]
|
|
102
|
+
enable_events: Enable database event channel support.
|
|
103
|
+
Defaults to True when extension_config["events"] is configured.
|
|
104
|
+
Provides pub/sub capabilities via LISTEN/NOTIFY or table-backed fallback.
|
|
105
|
+
Requires extension_config["events"] for migration setup when using table_queue backend.
|
|
106
|
+
events_backend: Event channel backend selection.
|
|
107
|
+
Options: "listen_notify", "table_queue", "listen_notify_durable"
|
|
108
|
+
- "listen_notify": Zero-copy PostgreSQL LISTEN/NOTIFY (ephemeral, real-time) - coming soon
|
|
109
|
+
- "table_queue": Durable table-backed queue with retries and exactly-once delivery (current default)
|
|
110
|
+
- "listen_notify_durable": Hybrid - real-time + durable (available when native support lands)
|
|
111
|
+
Defaults to "table_queue" until native LISTEN/NOTIFY support is implemented.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
enable_pgvector: NotRequired[bool]
|
|
115
|
+
enable_paradedb: NotRequired[bool]
|
|
116
|
+
json_serializer: NotRequired["Callable[[Any], str]"]
|
|
117
|
+
json_deserializer: NotRequired["Callable[[str], Any]"]
|
|
118
|
+
on_connection_create: NotRequired["Callable[..., Any]"]
|
|
119
|
+
enable_events: NotRequired[bool]
|
|
120
|
+
events_backend: NotRequired[str]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
__all__ = (
|
|
124
|
+
"PsycopgAsyncConfig",
|
|
125
|
+
"PsycopgAsyncCursor",
|
|
126
|
+
"PsycopgConnectionParams",
|
|
127
|
+
"PsycopgDriverFeatures",
|
|
128
|
+
"PsycopgPoolParams",
|
|
129
|
+
"PsycopgSyncConfig",
|
|
130
|
+
"PsycopgSyncCursor",
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class PsycopgSyncConnectionContext(SyncPoolConnectionContext):
|
|
135
|
+
"""Context manager for Psycopg connections."""
|
|
136
|
+
|
|
137
|
+
__slots__ = ()
|
|
138
|
+
|
|
139
|
+
def __init__(self, config: "PsycopgSyncConfig") -> None:
|
|
140
|
+
super().__init__(config)
|
|
141
|
+
|
|
142
|
+
def __enter__(self) -> "PsycopgSyncConnection":
|
|
143
|
+
if self._config.connection_instance:
|
|
144
|
+
self._ctx = self._config.connection_instance.connection()
|
|
145
|
+
return cast("PsycopgSyncConnection", self._ctx.__enter__())
|
|
146
|
+
# Fallback for no pool
|
|
147
|
+
self._ctx = self._config.create_connection()
|
|
148
|
+
return cast("PsycopgSyncConnection", self._ctx)
|
|
149
|
+
|
|
150
|
+
def __exit__(
|
|
151
|
+
self, exc_type: "type[BaseException] | None", exc_val: "BaseException | None", exc_tb: "TracebackType | None"
|
|
152
|
+
) -> bool | None:
|
|
153
|
+
if self._config.connection_instance and self._ctx:
|
|
154
|
+
return cast("bool | None", self._ctx.__exit__(exc_type, exc_val, exc_tb))
|
|
155
|
+
if self._ctx:
|
|
156
|
+
self._ctx.close()
|
|
157
|
+
return None
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class _PsycopgSyncSessionConnectionHandler(SyncPoolSessionFactory):
|
|
161
|
+
__slots__ = ("_conn",)
|
|
162
|
+
|
|
163
|
+
def __init__(self, config: "PsycopgSyncConfig") -> None:
|
|
164
|
+
super().__init__(config)
|
|
165
|
+
self._conn: PsycopgSyncConnection | None = None
|
|
166
|
+
|
|
167
|
+
def acquire_connection(self) -> "PsycopgSyncConnection":
|
|
168
|
+
if self._config.connection_instance:
|
|
169
|
+
self._ctx = self._config.connection_instance.connection()
|
|
170
|
+
return cast("PsycopgSyncConnection", self._ctx.__enter__())
|
|
171
|
+
self._conn = self._config.create_connection()
|
|
172
|
+
return cast("PsycopgSyncConnection", self._conn)
|
|
173
|
+
|
|
174
|
+
def release_connection(self, _conn: "PsycopgSyncConnection", **kwargs: Any) -> None:
|
|
175
|
+
if self._ctx is not None:
|
|
176
|
+
self._ctx.__exit__(None, None, None)
|
|
177
|
+
self._ctx = None
|
|
178
|
+
return
|
|
179
|
+
if self._conn is not None:
|
|
180
|
+
self._conn.close()
|
|
181
|
+
self._conn = None
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class PsycopgSyncConfig(SyncDatabaseConfig[PsycopgSyncConnection, ConnectionPool, PsycopgSyncDriver]):
|
|
185
|
+
"""Configuration for Psycopg synchronous database connections with direct field-based configuration.
|
|
186
|
+
|
|
187
|
+
Example::
|
|
188
|
+
|
|
189
|
+
config = PsycopgSyncConfig(
|
|
190
|
+
connection_config=PsycopgPoolParams(
|
|
191
|
+
conninfo="postgresql://user:pass@localhost/db"
|
|
192
|
+
)
|
|
193
|
+
)
|
|
194
|
+
"""
|
|
195
|
+
|
|
196
|
+
driver_type: "ClassVar[type[PsycopgSyncDriver]]" = PsycopgSyncDriver
|
|
197
|
+
connection_type: "ClassVar[type[PsycopgSyncConnection]]" = PsycopgSyncConnection
|
|
198
|
+
supports_transactional_ddl: "ClassVar[bool]" = True
|
|
199
|
+
supports_native_arrow_export: "ClassVar[bool]" = True
|
|
200
|
+
supports_native_arrow_import: "ClassVar[bool]" = True
|
|
201
|
+
supports_native_parquet_export: "ClassVar[bool]" = True
|
|
202
|
+
supports_native_parquet_import: "ClassVar[bool]" = True
|
|
203
|
+
_connection_context_class: "ClassVar[type[PsycopgSyncConnectionContext]]" = PsycopgSyncConnectionContext
|
|
204
|
+
_session_factory_class: "ClassVar[type[_PsycopgSyncSessionConnectionHandler]]" = (
|
|
205
|
+
_PsycopgSyncSessionConnectionHandler
|
|
206
|
+
)
|
|
207
|
+
_session_context_class: "ClassVar[type[PsycopgSyncSessionContext]]" = PsycopgSyncSessionContext
|
|
208
|
+
_default_statement_config = default_statement_config
|
|
209
|
+
|
|
210
|
+
def __init__(
|
|
211
|
+
self,
|
|
212
|
+
*,
|
|
213
|
+
connection_config: "PsycopgPoolParams | dict[str, Any] | None" = None,
|
|
214
|
+
connection_instance: "ConnectionPool | None" = None,
|
|
215
|
+
migration_config: "dict[str, Any] | None" = None,
|
|
216
|
+
statement_config: "StatementConfig | None" = None,
|
|
217
|
+
driver_features: "PsycopgDriverFeatures | dict[str, Any] | None" = None,
|
|
218
|
+
bind_key: "str | None" = None,
|
|
219
|
+
extension_config: "ExtensionConfigs | None" = None,
|
|
220
|
+
**kwargs: Any,
|
|
221
|
+
) -> None:
|
|
222
|
+
"""Initialize Psycopg synchronous configuration.
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
connection_config: Connection and pool configuration parameters (TypedDict or dict)
|
|
226
|
+
connection_instance: Existing pool instance to use
|
|
227
|
+
migration_config: Migration configuration
|
|
228
|
+
statement_config: Default SQL statement configuration
|
|
229
|
+
driver_features: Optional driver feature configuration
|
|
230
|
+
bind_key: Optional unique identifier for this configuration
|
|
231
|
+
extension_config: Extension-specific configuration (e.g., Litestar plugin settings)
|
|
232
|
+
**kwargs: Additional keyword arguments
|
|
233
|
+
"""
|
|
234
|
+
connection_config = normalize_connection_config(connection_config)
|
|
235
|
+
|
|
236
|
+
statement_config = statement_config or default_statement_config
|
|
237
|
+
statement_config, driver_features = apply_driver_features(statement_config, driver_features)
|
|
238
|
+
|
|
239
|
+
# Extract user connection hook before storing driver_features
|
|
240
|
+
features_dict = dict(driver_features) if driver_features else {}
|
|
241
|
+
self._user_connection_hook: Callable[[PsycopgSyncConnection], None] | None = features_dict.pop(
|
|
242
|
+
"on_connection_create", None
|
|
243
|
+
)
|
|
244
|
+
self._pgvector_available: bool | None = None
|
|
245
|
+
self._paradedb_available: bool | None = None
|
|
246
|
+
|
|
247
|
+
super().__init__(
|
|
248
|
+
connection_config=connection_config,
|
|
249
|
+
connection_instance=connection_instance,
|
|
250
|
+
migration_config=migration_config,
|
|
251
|
+
statement_config=statement_config,
|
|
252
|
+
driver_features=features_dict,
|
|
253
|
+
bind_key=bind_key,
|
|
254
|
+
extension_config=extension_config,
|
|
255
|
+
**kwargs,
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
def _create_pool(self) -> "ConnectionPool":
|
|
259
|
+
"""Create the actual connection pool."""
|
|
260
|
+
all_config = dict(self.connection_config)
|
|
261
|
+
|
|
262
|
+
pool_parameters = {
|
|
263
|
+
"min_size": all_config.pop("min_size", 4),
|
|
264
|
+
"max_size": all_config.pop("max_size", None),
|
|
265
|
+
"name": all_config.pop("name", None),
|
|
266
|
+
"timeout": all_config.pop("timeout", 30.0),
|
|
267
|
+
"max_waiting": all_config.pop("max_waiting", 0),
|
|
268
|
+
"max_lifetime": all_config.pop("max_lifetime", 3600.0),
|
|
269
|
+
"max_idle": all_config.pop("max_idle", 600.0),
|
|
270
|
+
"reconnect_timeout": all_config.pop("reconnect_timeout", 300.0),
|
|
271
|
+
"num_workers": all_config.pop("num_workers", 3),
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
pool_parameters["configure"] = all_config.pop("configure", self._configure_connection)
|
|
275
|
+
|
|
276
|
+
pool_parameters = {k: v for k, v in pool_parameters.items() if v is not None}
|
|
277
|
+
|
|
278
|
+
conninfo = all_config.pop("conninfo", None)
|
|
279
|
+
if conninfo:
|
|
280
|
+
pool = ConnectionPool(conninfo, open=True, **pool_parameters)
|
|
281
|
+
else:
|
|
282
|
+
kwargs = all_config.pop("kwargs", {})
|
|
283
|
+
all_config.update(kwargs)
|
|
284
|
+
pool = ConnectionPool("", kwargs=all_config, open=True, **pool_parameters)
|
|
285
|
+
|
|
286
|
+
return pool
|
|
287
|
+
|
|
288
|
+
def _update_dialect_for_extensions(self) -> None:
|
|
289
|
+
"""Update statement_config dialect based on detected extensions.
|
|
290
|
+
|
|
291
|
+
Priority: paradedb > pgvector > postgres (default).
|
|
292
|
+
"""
|
|
293
|
+
current_dialect = getattr(self.statement_config, "dialect", "postgres")
|
|
294
|
+
if current_dialect != "postgres":
|
|
295
|
+
return
|
|
296
|
+
|
|
297
|
+
if self._paradedb_available:
|
|
298
|
+
self.statement_config = self.statement_config.replace(dialect="paradedb")
|
|
299
|
+
elif self._pgvector_available:
|
|
300
|
+
self.statement_config = self.statement_config.replace(dialect="pgvector")
|
|
301
|
+
|
|
302
|
+
def _configure_connection(self, conn: "PsycopgSyncConnection") -> None:
|
|
303
|
+
autocommit_setting = self.connection_config.get("autocommit")
|
|
304
|
+
if autocommit_setting is not None:
|
|
305
|
+
conn.autocommit = autocommit_setting
|
|
306
|
+
|
|
307
|
+
# Detect extensions on first connection, update dialect
|
|
308
|
+
if self._pgvector_available is None:
|
|
309
|
+
detected_extensions: set[str] = set()
|
|
310
|
+
extensions = build_postgres_extension_probe_names(self.driver_features)
|
|
311
|
+
if extensions:
|
|
312
|
+
try:
|
|
313
|
+
cursor = conn.execute(
|
|
314
|
+
"SELECT extname FROM pg_extension WHERE extname = ANY(%s::text[])", (extensions,)
|
|
315
|
+
)
|
|
316
|
+
results = cursor.fetchall()
|
|
317
|
+
detected_extensions = {r[0] for r in results} # type: ignore[index]
|
|
318
|
+
except Exception:
|
|
319
|
+
detected_extensions = set()
|
|
320
|
+
self.statement_config, self._pgvector_available, self._paradedb_available = (
|
|
321
|
+
resolve_postgres_extension_state(self.statement_config, self.driver_features, detected_extensions)
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
if self._pgvector_available:
|
|
325
|
+
register_pgvector_sync(conn)
|
|
326
|
+
|
|
327
|
+
# Ensure connection is not left in INTRANS state from extension detection or registration
|
|
328
|
+
if not conn.autocommit:
|
|
329
|
+
conn.rollback()
|
|
330
|
+
|
|
331
|
+
# Call user-provided callback after internal setup
|
|
332
|
+
if self._user_connection_hook is not None:
|
|
333
|
+
self._user_connection_hook(conn)
|
|
334
|
+
|
|
335
|
+
def _close_pool(self) -> None:
|
|
336
|
+
"""Close the actual connection pool."""
|
|
337
|
+
if not self.connection_instance:
|
|
338
|
+
return
|
|
339
|
+
|
|
340
|
+
try:
|
|
341
|
+
self.connection_instance.close()
|
|
342
|
+
finally:
|
|
343
|
+
self.connection_instance = None
|
|
344
|
+
|
|
345
|
+
def create_connection(self) -> "PsycopgSyncConnection":
|
|
346
|
+
"""Create a single connection (not from pool).
|
|
347
|
+
|
|
348
|
+
Returns:
|
|
349
|
+
A psycopg Connection instance.
|
|
350
|
+
"""
|
|
351
|
+
if self.connection_instance is None:
|
|
352
|
+
self.connection_instance = self.create_pool()
|
|
353
|
+
return cast("PsycopgSyncConnection", self.connection_instance.getconn()) # pyright: ignore
|
|
354
|
+
|
|
355
|
+
def provide_session(
|
|
356
|
+
self, *_args: Any, statement_config: "StatementConfig | None" = None, **_kwargs: Any
|
|
357
|
+
) -> "PsycopgSyncSessionContext":
|
|
358
|
+
"""Provide a driver session context manager.
|
|
359
|
+
|
|
360
|
+
Args:
|
|
361
|
+
*_args: Additional arguments.
|
|
362
|
+
statement_config: Optional statement configuration override.
|
|
363
|
+
**_kwargs: Additional keyword arguments.
|
|
364
|
+
|
|
365
|
+
Returns:
|
|
366
|
+
A PsycopgSyncDriver session context manager.
|
|
367
|
+
"""
|
|
368
|
+
handler = _PsycopgSyncSessionConnectionHandler(self)
|
|
369
|
+
|
|
370
|
+
return PsycopgSyncSessionContext(
|
|
371
|
+
acquire_connection=handler.acquire_connection,
|
|
372
|
+
release_connection=handler.release_connection,
|
|
373
|
+
statement_config=statement_config
|
|
374
|
+
or (lambda: resolve_runtime_statement_config(None, self.statement_config, default_statement_config)),
|
|
375
|
+
driver_features=self.driver_features,
|
|
376
|
+
prepare_driver=self._prepare_driver,
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
def provide_pool(self, *args: Any, **kwargs: Any) -> "ConnectionPool":
|
|
380
|
+
"""Provide pool instance.
|
|
381
|
+
|
|
382
|
+
Returns:
|
|
383
|
+
The connection pool.
|
|
384
|
+
"""
|
|
385
|
+
if not self.connection_instance:
|
|
386
|
+
self.connection_instance = self.create_pool()
|
|
387
|
+
return self.connection_instance
|
|
388
|
+
|
|
389
|
+
def get_signature_namespace(self) -> "dict[str, Any]":
|
|
390
|
+
"""Get the signature namespace for Psycopg types.
|
|
391
|
+
|
|
392
|
+
This provides all Psycopg-specific types that Litestar needs to recognize
|
|
393
|
+
to avoid serialization attempts.
|
|
394
|
+
|
|
395
|
+
Returns:
|
|
396
|
+
Dictionary mapping type names to types.
|
|
397
|
+
"""
|
|
398
|
+
namespace = super().get_signature_namespace()
|
|
399
|
+
namespace.update({
|
|
400
|
+
"PsycopgConnectionParams": PsycopgConnectionParams,
|
|
401
|
+
"PsycopgPoolParams": PsycopgPoolParams,
|
|
402
|
+
"PsycopgSyncConnectionContext": PsycopgSyncConnectionContext,
|
|
403
|
+
"PsycopgSyncConnection": PsycopgSyncConnection,
|
|
404
|
+
"PsycopgSyncCursor": PsycopgSyncCursor,
|
|
405
|
+
"PsycopgSyncDriver": PsycopgSyncDriver,
|
|
406
|
+
"PsycopgSyncExceptionHandler": PsycopgSyncExceptionHandler,
|
|
407
|
+
"PsycopgSyncSessionContext": PsycopgSyncSessionContext,
|
|
408
|
+
})
|
|
409
|
+
return namespace
|
|
410
|
+
|
|
411
|
+
def get_event_runtime_hints(self) -> "EventRuntimeHints":
|
|
412
|
+
"""Return polling defaults for PostgreSQL queue fallback."""
|
|
413
|
+
|
|
414
|
+
return EventRuntimeHints(poll_interval=0.5, select_for_update=True, skip_locked=True)
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
class PsycopgAsyncConnectionContext(AsyncPoolConnectionContext):
|
|
418
|
+
"""Async context manager for Psycopg connections."""
|
|
419
|
+
|
|
420
|
+
__slots__ = ("_ctx",)
|
|
421
|
+
|
|
422
|
+
def __init__(self, config: "PsycopgAsyncConfig") -> None:
|
|
423
|
+
super().__init__(config)
|
|
424
|
+
self._ctx: Any = None
|
|
425
|
+
|
|
426
|
+
async def __aenter__(self) -> "PsycopgAsyncConnection":
|
|
427
|
+
if self._config.connection_instance is None:
|
|
428
|
+
self._config.connection_instance = await self._config.create_pool()
|
|
429
|
+
# pool.connection() returns an async context manager
|
|
430
|
+
if self._config.connection_instance:
|
|
431
|
+
self._ctx = self._config.connection_instance.connection()
|
|
432
|
+
return cast("PsycopgAsyncConnection", await self._ctx.__aenter__())
|
|
433
|
+
msg = "Connection pool not initialized"
|
|
434
|
+
raise ImproperConfigurationError(msg)
|
|
435
|
+
|
|
436
|
+
async def __aexit__(
|
|
437
|
+
self, exc_type: "type[BaseException] | None", exc_val: "BaseException | None", exc_tb: "TracebackType | None"
|
|
438
|
+
) -> bool | None:
|
|
439
|
+
if self._ctx:
|
|
440
|
+
return cast("bool | None", await self._ctx.__aexit__(exc_type, exc_val, exc_tb))
|
|
441
|
+
return None
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
class _PsycopgAsyncSessionConnectionHandler(AsyncPoolSessionFactory):
|
|
445
|
+
__slots__ = ("_ctx",)
|
|
446
|
+
|
|
447
|
+
def __init__(self, config: "PsycopgAsyncConfig") -> None:
|
|
448
|
+
super().__init__(config)
|
|
449
|
+
self._ctx: Any = None
|
|
450
|
+
|
|
451
|
+
async def acquire_connection(self) -> "PsycopgAsyncConnection":
|
|
452
|
+
if self._config.connection_instance is None:
|
|
453
|
+
self._config.connection_instance = await self._config.create_pool()
|
|
454
|
+
self._ctx = self._config.connection_instance.connection()
|
|
455
|
+
return cast("PsycopgAsyncConnection", await self._ctx.__aenter__())
|
|
456
|
+
|
|
457
|
+
async def release_connection(self, _conn: "PsycopgAsyncConnection", **kwargs: Any) -> None:
|
|
458
|
+
if self._ctx is None:
|
|
459
|
+
return
|
|
460
|
+
await self._ctx.__aexit__(None, None, None)
|
|
461
|
+
self._ctx = None
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
@mypyc_attr(native_class=False)
|
|
465
|
+
class PsycopgAsyncConfig(AsyncDatabaseConfig[PsycopgAsyncConnection, AsyncConnectionPool, PsycopgAsyncDriver]):
|
|
466
|
+
"""Configuration for Psycopg asynchronous database connections with direct field-based configuration.
|
|
467
|
+
|
|
468
|
+
Example::
|
|
469
|
+
|
|
470
|
+
config = PsycopgAsyncConfig(
|
|
471
|
+
connection_config=PsycopgPoolParams(
|
|
472
|
+
conninfo="postgresql://user:pass@localhost/db"
|
|
473
|
+
)
|
|
474
|
+
)
|
|
475
|
+
"""
|
|
476
|
+
|
|
477
|
+
driver_type: ClassVar[type[PsycopgAsyncDriver]] = PsycopgAsyncDriver
|
|
478
|
+
connection_type: "ClassVar[type[PsycopgAsyncConnection]]" = PsycopgAsyncConnection
|
|
479
|
+
supports_transactional_ddl: "ClassVar[bool]" = True
|
|
480
|
+
supports_native_arrow_export: ClassVar[bool] = True
|
|
481
|
+
supports_native_arrow_import: ClassVar[bool] = True
|
|
482
|
+
supports_native_parquet_export: ClassVar[bool] = True
|
|
483
|
+
supports_native_parquet_import: ClassVar[bool] = True
|
|
484
|
+
_connection_context_class: "ClassVar[type[PsycopgAsyncConnectionContext]]" = PsycopgAsyncConnectionContext
|
|
485
|
+
_session_factory_class: "ClassVar[type[_PsycopgAsyncSessionConnectionHandler]]" = (
|
|
486
|
+
_PsycopgAsyncSessionConnectionHandler
|
|
487
|
+
)
|
|
488
|
+
_session_context_class: "ClassVar[type[PsycopgAsyncSessionContext]]" = PsycopgAsyncSessionContext
|
|
489
|
+
_default_statement_config = default_statement_config
|
|
490
|
+
|
|
491
|
+
def __init__(
|
|
492
|
+
self,
|
|
493
|
+
*,
|
|
494
|
+
connection_config: "PsycopgPoolParams | dict[str, Any] | None" = None,
|
|
495
|
+
connection_instance: "AsyncConnectionPool | None" = None,
|
|
496
|
+
migration_config: "dict[str, Any] | None" = None,
|
|
497
|
+
statement_config: "StatementConfig | None" = None,
|
|
498
|
+
driver_features: "PsycopgDriverFeatures | dict[str, Any] | None" = None,
|
|
499
|
+
bind_key: "str | None" = None,
|
|
500
|
+
extension_config: "ExtensionConfigs | None" = None,
|
|
501
|
+
**kwargs: Any,
|
|
502
|
+
) -> None:
|
|
503
|
+
"""Initialize Psycopg asynchronous configuration.
|
|
504
|
+
|
|
505
|
+
Args:
|
|
506
|
+
connection_config: Connection and pool configuration parameters (TypedDict or dict)
|
|
507
|
+
connection_instance: Existing pool instance to use
|
|
508
|
+
migration_config: Migration configuration
|
|
509
|
+
statement_config: Default SQL statement configuration
|
|
510
|
+
driver_features: Optional driver feature configuration
|
|
511
|
+
bind_key: Optional unique identifier for this configuration
|
|
512
|
+
extension_config: Extension-specific configuration (e.g., Litestar plugin settings)
|
|
513
|
+
**kwargs: Additional keyword arguments
|
|
514
|
+
"""
|
|
515
|
+
connection_config = normalize_connection_config(connection_config)
|
|
516
|
+
|
|
517
|
+
statement_config = statement_config or default_statement_config
|
|
518
|
+
statement_config, driver_features = apply_driver_features(statement_config, driver_features)
|
|
519
|
+
|
|
520
|
+
# Extract user connection hook before storing driver_features
|
|
521
|
+
features_dict = dict(driver_features) if driver_features else {}
|
|
522
|
+
self._user_connection_hook: Callable[[PsycopgAsyncConnection], Awaitable[None]] | None = features_dict.pop(
|
|
523
|
+
"on_connection_create", None
|
|
524
|
+
)
|
|
525
|
+
self._pgvector_available: bool | None = None
|
|
526
|
+
self._paradedb_available: bool | None = None
|
|
527
|
+
|
|
528
|
+
super().__init__(
|
|
529
|
+
connection_config=connection_config,
|
|
530
|
+
connection_instance=connection_instance,
|
|
531
|
+
migration_config=migration_config,
|
|
532
|
+
statement_config=statement_config,
|
|
533
|
+
driver_features=features_dict,
|
|
534
|
+
bind_key=bind_key,
|
|
535
|
+
extension_config=extension_config,
|
|
536
|
+
**kwargs,
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
async def _create_pool(self) -> "AsyncConnectionPool":
|
|
540
|
+
"""Create the actual async connection pool."""
|
|
541
|
+
|
|
542
|
+
all_config = dict(self.connection_config)
|
|
543
|
+
|
|
544
|
+
pool_parameters = {
|
|
545
|
+
"min_size": all_config.pop("min_size", 4),
|
|
546
|
+
"max_size": all_config.pop("max_size", None),
|
|
547
|
+
"name": all_config.pop("name", None),
|
|
548
|
+
"timeout": all_config.pop("timeout", 30.0),
|
|
549
|
+
"max_waiting": all_config.pop("max_waiting", 0),
|
|
550
|
+
"max_lifetime": all_config.pop("max_lifetime", 3600.0),
|
|
551
|
+
"max_idle": all_config.pop("max_idle", 600.0),
|
|
552
|
+
"reconnect_timeout": all_config.pop("reconnect_timeout", 300.0),
|
|
553
|
+
"num_workers": all_config.pop("num_workers", 3),
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
pool_parameters["configure"] = all_config.pop("configure", self._configure_async_connection)
|
|
557
|
+
|
|
558
|
+
pool_parameters = {k: v for k, v in pool_parameters.items() if v is not None}
|
|
559
|
+
|
|
560
|
+
conninfo = all_config.pop("conninfo", None)
|
|
561
|
+
if conninfo:
|
|
562
|
+
pool = AsyncConnectionPool(conninfo, open=False, **pool_parameters)
|
|
563
|
+
else:
|
|
564
|
+
kwargs = all_config.pop("kwargs", {})
|
|
565
|
+
all_config.update(kwargs)
|
|
566
|
+
pool = AsyncConnectionPool("", kwargs=all_config, open=False, **pool_parameters)
|
|
567
|
+
|
|
568
|
+
await pool.open()
|
|
569
|
+
|
|
570
|
+
return pool
|
|
571
|
+
|
|
572
|
+
def _update_dialect_for_extensions(self) -> None:
|
|
573
|
+
"""Update statement_config dialect based on detected extensions.
|
|
574
|
+
|
|
575
|
+
Priority: paradedb > pgvector > postgres (default).
|
|
576
|
+
"""
|
|
577
|
+
current_dialect = getattr(self.statement_config, "dialect", "postgres")
|
|
578
|
+
if current_dialect != "postgres":
|
|
579
|
+
return
|
|
580
|
+
|
|
581
|
+
if self._paradedb_available:
|
|
582
|
+
self.statement_config = self.statement_config.replace(dialect="paradedb")
|
|
583
|
+
elif self._pgvector_available:
|
|
584
|
+
self.statement_config = self.statement_config.replace(dialect="pgvector")
|
|
585
|
+
|
|
586
|
+
async def _configure_async_connection(self, conn: "PsycopgAsyncConnection") -> None:
|
|
587
|
+
autocommit_setting = self.connection_config.get("autocommit")
|
|
588
|
+
if autocommit_setting is not None:
|
|
589
|
+
await conn.set_autocommit(autocommit_setting)
|
|
590
|
+
|
|
591
|
+
# Detect extensions on first connection, update dialect
|
|
592
|
+
if self._pgvector_available is None:
|
|
593
|
+
detected_extensions: set[str] = set()
|
|
594
|
+
extensions = build_postgres_extension_probe_names(self.driver_features)
|
|
595
|
+
if extensions:
|
|
596
|
+
try:
|
|
597
|
+
cursor = await conn.execute(
|
|
598
|
+
"SELECT extname FROM pg_extension WHERE extname = ANY(%s::text[])", (extensions,)
|
|
599
|
+
)
|
|
600
|
+
results = await cursor.fetchall()
|
|
601
|
+
detected_extensions = {r[0] for r in results} # type: ignore[index]
|
|
602
|
+
except Exception:
|
|
603
|
+
detected_extensions = set()
|
|
604
|
+
self.statement_config, self._pgvector_available, self._paradedb_available = (
|
|
605
|
+
resolve_postgres_extension_state(self.statement_config, self.driver_features, detected_extensions)
|
|
606
|
+
)
|
|
607
|
+
|
|
608
|
+
if self._pgvector_available:
|
|
609
|
+
await register_pgvector_async(conn)
|
|
610
|
+
|
|
611
|
+
# Ensure connection is not left in INTRANS state from extension detection or registration
|
|
612
|
+
if not conn.autocommit:
|
|
613
|
+
await conn.rollback()
|
|
614
|
+
|
|
615
|
+
# Call user-provided callback after internal setup
|
|
616
|
+
if self._user_connection_hook is not None:
|
|
617
|
+
await self._user_connection_hook(conn)
|
|
618
|
+
|
|
619
|
+
async def _close_pool(self) -> None:
|
|
620
|
+
"""Close the actual async connection pool."""
|
|
621
|
+
if not self.connection_instance:
|
|
622
|
+
return
|
|
623
|
+
|
|
624
|
+
try:
|
|
625
|
+
await self.connection_instance.close()
|
|
626
|
+
finally:
|
|
627
|
+
self.connection_instance = None
|
|
628
|
+
|
|
629
|
+
async def create_connection(self) -> "PsycopgAsyncConnection": # pyright: ignore
|
|
630
|
+
"""Create a single async connection (not from pool).
|
|
631
|
+
|
|
632
|
+
Returns:
|
|
633
|
+
A psycopg AsyncConnection instance.
|
|
634
|
+
"""
|
|
635
|
+
if self.connection_instance is None:
|
|
636
|
+
self.connection_instance = await self.create_pool()
|
|
637
|
+
return cast("PsycopgAsyncConnection", await self.connection_instance.getconn()) # pyright: ignore
|
|
638
|
+
|
|
639
|
+
def get_signature_namespace(self) -> "dict[str, Any]":
|
|
640
|
+
"""Get the signature namespace for PsycopgAsyncConfig types.
|
|
641
|
+
|
|
642
|
+
Returns:
|
|
643
|
+
Dictionary mapping type names to types.
|
|
644
|
+
"""
|
|
645
|
+
namespace = super().get_signature_namespace()
|
|
646
|
+
namespace.update({
|
|
647
|
+
"PsycopgAsyncConnectionContext": PsycopgAsyncConnectionContext,
|
|
648
|
+
"PsycopgAsyncConnection": PsycopgAsyncConnection,
|
|
649
|
+
"PsycopgAsyncCursor": PsycopgAsyncCursor,
|
|
650
|
+
"PsycopgAsyncDriver": PsycopgAsyncDriver,
|
|
651
|
+
"PsycopgAsyncExceptionHandler": PsycopgAsyncExceptionHandler,
|
|
652
|
+
"PsycopgAsyncSessionContext": PsycopgAsyncSessionContext,
|
|
653
|
+
"PsycopgConnectionParams": PsycopgConnectionParams,
|
|
654
|
+
"PsycopgPoolParams": PsycopgPoolParams,
|
|
655
|
+
})
|
|
656
|
+
return namespace
|
|
657
|
+
|
|
658
|
+
def provide_session(
|
|
659
|
+
self, *_args: Any, statement_config: "StatementConfig | None" = None, **_kwargs: Any
|
|
660
|
+
) -> "PsycopgAsyncSessionContext":
|
|
661
|
+
"""Provide an async driver session context manager.
|
|
662
|
+
|
|
663
|
+
Args:
|
|
664
|
+
*_args: Additional arguments.
|
|
665
|
+
statement_config: Optional statement configuration override.
|
|
666
|
+
**_kwargs: Additional keyword arguments.
|
|
667
|
+
|
|
668
|
+
Returns:
|
|
669
|
+
A PsycopgAsyncDriver session context manager.
|
|
670
|
+
"""
|
|
671
|
+
handler = _PsycopgAsyncSessionConnectionHandler(self)
|
|
672
|
+
|
|
673
|
+
return PsycopgAsyncSessionContext(
|
|
674
|
+
acquire_connection=handler.acquire_connection,
|
|
675
|
+
release_connection=handler.release_connection,
|
|
676
|
+
statement_config=statement_config
|
|
677
|
+
or (lambda: resolve_runtime_statement_config(None, self.statement_config, default_statement_config)),
|
|
678
|
+
driver_features=self.driver_features,
|
|
679
|
+
prepare_driver=self._prepare_driver,
|
|
680
|
+
)
|
|
681
|
+
|
|
682
|
+
async def provide_pool(self, *args: Any, **kwargs: Any) -> "AsyncConnectionPool":
|
|
683
|
+
"""Provide async pool instance.
|
|
684
|
+
|
|
685
|
+
Returns:
|
|
686
|
+
The async connection pool.
|
|
687
|
+
"""
|
|
688
|
+
if not self.connection_instance:
|
|
689
|
+
self.connection_instance = await self.create_pool()
|
|
690
|
+
return self.connection_instance
|
|
691
|
+
|
|
692
|
+
def get_event_runtime_hints(self) -> "EventRuntimeHints":
|
|
693
|
+
"""Return polling defaults for PostgreSQL queue fallback."""
|
|
694
|
+
|
|
695
|
+
return EventRuntimeHints(poll_interval=0.5, select_for_update=True, skip_locked=True)
|
|
Binary file
|