sqlspec 0.72.0__cp315-cp315-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.
- 6b29784d6b1cafc66758__mypyc.cp315-win_amd64.pyd +0 -0
- sqlspec/__init__.py +381 -0
- sqlspec/__main__.py +14 -0
- sqlspec/__metadata__.py +14 -0
- sqlspec/_typing.py +775 -0
- sqlspec/adapters/__init__.py +3 -0
- sqlspec/adapters/adbc/__init__.py +16 -0
- sqlspec/adapters/adbc/_typing.py +221 -0
- sqlspec/adapters/adbc/adk/__init__.py +11 -0
- sqlspec/adapters/adbc/adk/store.py +4101 -0
- sqlspec/adapters/adbc/config.py +843 -0
- sqlspec/adapters/adbc/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/core.py +3209 -0
- sqlspec/adapters/adbc/data_dictionary.py +1448 -0
- sqlspec/adapters/adbc/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/driver.py +1400 -0
- sqlspec/adapters/adbc/events/__init__.py +5 -0
- sqlspec/adapters/adbc/events/store.py +384 -0
- sqlspec/adapters/adbc/litestar/__init__.py +5 -0
- sqlspec/adapters/adbc/litestar/store.py +962 -0
- sqlspec/adapters/adbc/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/pool.py +242 -0
- sqlspec/adapters/adbc/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/type_converter.py +117 -0
- sqlspec/adapters/aiomysql/__init__.py +25 -0
- sqlspec/adapters/aiomysql/_typing.py +134 -0
- sqlspec/adapters/aiomysql/adk/__init__.py +5 -0
- sqlspec/adapters/aiomysql/adk/store.py +1542 -0
- sqlspec/adapters/aiomysql/config.py +634 -0
- sqlspec/adapters/aiomysql/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiomysql/core.py +922 -0
- sqlspec/adapters/aiomysql/data_dictionary.py +16 -0
- sqlspec/adapters/aiomysql/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiomysql/driver.py +494 -0
- sqlspec/adapters/aiomysql/events/__init__.py +5 -0
- sqlspec/adapters/aiomysql/events/store.py +72 -0
- sqlspec/adapters/aiomysql/litestar/__init__.py +5 -0
- sqlspec/adapters/aiomysql/litestar/store.py +345 -0
- sqlspec/adapters/aiosqlite/__init__.py +43 -0
- sqlspec/adapters/aiosqlite/_typing.py +75 -0
- sqlspec/adapters/aiosqlite/adk/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/adk/store.py +1546 -0
- sqlspec/adapters/aiosqlite/config.py +607 -0
- sqlspec/adapters/aiosqlite/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/core.py +1155 -0
- sqlspec/adapters/aiosqlite/data_dictionary.py +343 -0
- sqlspec/adapters/aiosqlite/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/driver.py +559 -0
- sqlspec/adapters/aiosqlite/events/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/events/store.py +54 -0
- sqlspec/adapters/aiosqlite/litestar/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/litestar/store.py +315 -0
- sqlspec/adapters/aiosqlite/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/pool.py +1323 -0
- sqlspec/adapters/aiosqlite/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/type_converter.py +114 -0
- sqlspec/adapters/arrow_odbc/__init__.py +32 -0
- sqlspec/adapters/arrow_odbc/_typing.py +131 -0
- sqlspec/adapters/arrow_odbc/adk/__init__.py +5 -0
- sqlspec/adapters/arrow_odbc/adk/store.py +1671 -0
- sqlspec/adapters/arrow_odbc/config.py +446 -0
- sqlspec/adapters/arrow_odbc/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/arrow_odbc/core.py +795 -0
- sqlspec/adapters/arrow_odbc/data_dictionary.py +345 -0
- sqlspec/adapters/arrow_odbc/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/arrow_odbc/driver.py +885 -0
- sqlspec/adapters/arrow_odbc/events/__init__.py +5 -0
- sqlspec/adapters/arrow_odbc/events/store.py +114 -0
- sqlspec/adapters/arrow_odbc/litestar/__init__.py +5 -0
- sqlspec/adapters/arrow_odbc/litestar/store.py +682 -0
- sqlspec/adapters/arrow_odbc/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/arrow_odbc/type_converter.py +95 -0
- sqlspec/adapters/asyncmy/__init__.py +27 -0
- sqlspec/adapters/asyncmy/_typing.py +215 -0
- sqlspec/adapters/asyncmy/adk/__init__.py +5 -0
- sqlspec/adapters/asyncmy/adk/store.py +1544 -0
- sqlspec/adapters/asyncmy/config.py +707 -0
- sqlspec/adapters/asyncmy/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncmy/core.py +917 -0
- sqlspec/adapters/asyncmy/data_dictionary.py +16 -0
- sqlspec/adapters/asyncmy/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncmy/driver.py +529 -0
- sqlspec/adapters/asyncmy/events/__init__.py +5 -0
- sqlspec/adapters/asyncmy/events/store.py +72 -0
- sqlspec/adapters/asyncmy/litestar/__init__.py +5 -0
- sqlspec/adapters/asyncmy/litestar/store.py +348 -0
- sqlspec/adapters/asyncpg/__init__.py +28 -0
- sqlspec/adapters/asyncpg/_typing.py +113 -0
- sqlspec/adapters/asyncpg/adk/__init__.py +5 -0
- sqlspec/adapters/asyncpg/adk/store.py +1145 -0
- sqlspec/adapters/asyncpg/config.py +903 -0
- sqlspec/adapters/asyncpg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/core.py +797 -0
- sqlspec/adapters/asyncpg/data_dictionary.py +417 -0
- sqlspec/adapters/asyncpg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/driver.py +927 -0
- sqlspec/adapters/asyncpg/events/__init__.py +6 -0
- sqlspec/adapters/asyncpg/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/events/_hub.py +279 -0
- sqlspec/adapters/asyncpg/events/backend.py +410 -0
- sqlspec/adapters/asyncpg/events/store.py +57 -0
- sqlspec/adapters/asyncpg/litestar/__init__.py +5 -0
- sqlspec/adapters/asyncpg/litestar/store.py +278 -0
- sqlspec/adapters/asyncpg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/tenant.py +140 -0
- sqlspec/adapters/bigquery/__init__.py +23 -0
- sqlspec/adapters/bigquery/_typing.py +184 -0
- sqlspec/adapters/bigquery/adk/__init__.py +5 -0
- sqlspec/adapters/bigquery/adk/store.py +920 -0
- sqlspec/adapters/bigquery/config.py +631 -0
- sqlspec/adapters/bigquery/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/bigquery/core.py +1433 -0
- sqlspec/adapters/bigquery/data_dictionary.py +502 -0
- sqlspec/adapters/bigquery/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/bigquery/driver.py +1266 -0
- sqlspec/adapters/bigquery/events/__init__.py +5 -0
- sqlspec/adapters/bigquery/events/store.py +158 -0
- sqlspec/adapters/bigquery/litestar/__init__.py +5 -0
- sqlspec/adapters/bigquery/litestar/store.py +359 -0
- sqlspec/adapters/cockroach_asyncpg/__init__.py +32 -0
- sqlspec/adapters/cockroach_asyncpg/_typing.py +54 -0
- sqlspec/adapters/cockroach_asyncpg/adk/__init__.py +9 -0
- sqlspec/adapters/cockroach_asyncpg/adk/store.py +1096 -0
- sqlspec/adapters/cockroach_asyncpg/config.py +653 -0
- sqlspec/adapters/cockroach_asyncpg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_asyncpg/core.py +835 -0
- sqlspec/adapters/cockroach_asyncpg/data_dictionary.py +371 -0
- sqlspec/adapters/cockroach_asyncpg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_asyncpg/driver.py +438 -0
- sqlspec/adapters/cockroach_asyncpg/events/__init__.py +5 -0
- sqlspec/adapters/cockroach_asyncpg/events/store.py +20 -0
- sqlspec/adapters/cockroach_asyncpg/litestar/__init__.py +5 -0
- sqlspec/adapters/cockroach_asyncpg/litestar/store.py +203 -0
- sqlspec/adapters/cockroach_asyncpg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_asyncpg/tenant.py +143 -0
- sqlspec/adapters/cockroach_psycopg/__init__.py +46 -0
- sqlspec/adapters/cockroach_psycopg/_typing.py +271 -0
- sqlspec/adapters/cockroach_psycopg/adk/__init__.py +17 -0
- sqlspec/adapters/cockroach_psycopg/adk/store.py +2274 -0
- sqlspec/adapters/cockroach_psycopg/config.py +1285 -0
- sqlspec/adapters/cockroach_psycopg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_psycopg/core.py +667 -0
- sqlspec/adapters/cockroach_psycopg/data_dictionary.py +622 -0
- sqlspec/adapters/cockroach_psycopg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_psycopg/driver.py +864 -0
- sqlspec/adapters/cockroach_psycopg/events/__init__.py +8 -0
- sqlspec/adapters/cockroach_psycopg/events/store.py +34 -0
- sqlspec/adapters/cockroach_psycopg/litestar/__init__.py +9 -0
- sqlspec/adapters/cockroach_psycopg/litestar/store.py +413 -0
- sqlspec/adapters/cockroach_psycopg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_psycopg/tenant.py +222 -0
- sqlspec/adapters/db2/__init__.py +34 -0
- sqlspec/adapters/db2/_typing.py +357 -0
- sqlspec/adapters/db2/adk/__init__.py +10 -0
- sqlspec/adapters/db2/adk/store.py +1950 -0
- sqlspec/adapters/db2/config.py +550 -0
- sqlspec/adapters/db2/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/core.py +1021 -0
- sqlspec/adapters/db2/data_dictionary.py +493 -0
- sqlspec/adapters/db2/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/driver.py +898 -0
- sqlspec/adapters/db2/events/__init__.py +5 -0
- sqlspec/adapters/db2/events/store.py +77 -0
- sqlspec/adapters/db2/litestar/__init__.py +5 -0
- sqlspec/adapters/db2/litestar/store.py +519 -0
- sqlspec/adapters/db2/migrations.py +221 -0
- sqlspec/adapters/db2/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/pool.py +876 -0
- sqlspec/adapters/db2/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/tenant.py +292 -0
- sqlspec/adapters/duckdb/__init__.py +30 -0
- sqlspec/adapters/duckdb/_typing.py +182 -0
- sqlspec/adapters/duckdb/adk/__init__.py +10 -0
- sqlspec/adapters/duckdb/adk/store.py +1672 -0
- sqlspec/adapters/duckdb/config.py +506 -0
- sqlspec/adapters/duckdb/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/core.py +1299 -0
- sqlspec/adapters/duckdb/data_dictionary.py +553 -0
- sqlspec/adapters/duckdb/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/driver.py +1214 -0
- sqlspec/adapters/duckdb/events/__init__.py +5 -0
- sqlspec/adapters/duckdb/events/store.py +38 -0
- sqlspec/adapters/duckdb/litestar/__init__.py +5 -0
- sqlspec/adapters/duckdb/litestar/store.py +313 -0
- sqlspec/adapters/duckdb/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/pool.py +1121 -0
- sqlspec/adapters/mssql_python/__init__.py +42 -0
- sqlspec/adapters/mssql_python/_typing.py +135 -0
- sqlspec/adapters/mssql_python/adk/__init__.py +5 -0
- sqlspec/adapters/mssql_python/adk/store.py +1278 -0
- sqlspec/adapters/mssql_python/config.py +455 -0
- sqlspec/adapters/mssql_python/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/core.py +862 -0
- sqlspec/adapters/mssql_python/data_dictionary.py +417 -0
- sqlspec/adapters/mssql_python/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/driver.py +772 -0
- sqlspec/adapters/mssql_python/events/__init__.py +5 -0
- sqlspec/adapters/mssql_python/events/store.py +46 -0
- sqlspec/adapters/mssql_python/litestar/__init__.py +5 -0
- sqlspec/adapters/mssql_python/litestar/store.py +355 -0
- sqlspec/adapters/mssql_python/migrations.py +162 -0
- sqlspec/adapters/mssql_python/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/pool.py +165 -0
- sqlspec/adapters/mssql_python/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/tenant.py +74 -0
- sqlspec/adapters/mssql_python/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/type_converter.py +98 -0
- sqlspec/adapters/mysqlconnector/__init__.py +47 -0
- sqlspec/adapters/mysqlconnector/_typing.py +205 -0
- sqlspec/adapters/mysqlconnector/adk/__init__.py +17 -0
- sqlspec/adapters/mysqlconnector/adk/store.py +2503 -0
- sqlspec/adapters/mysqlconnector/config.py +925 -0
- sqlspec/adapters/mysqlconnector/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mysqlconnector/core.py +1075 -0
- sqlspec/adapters/mysqlconnector/data_dictionary.py +23 -0
- sqlspec/adapters/mysqlconnector/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mysqlconnector/driver.py +702 -0
- sqlspec/adapters/mysqlconnector/events/__init__.py +8 -0
- sqlspec/adapters/mysqlconnector/events/store.py +89 -0
- sqlspec/adapters/mysqlconnector/litestar/__init__.py +9 -0
- sqlspec/adapters/mysqlconnector/litestar/store.py +524 -0
- sqlspec/adapters/oracledb/__init__.py +159 -0
- sqlspec/adapters/oracledb/_json_handlers.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_json_handlers.py +208 -0
- sqlspec/adapters/oracledb/_param_types.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_param_types.py +65 -0
- sqlspec/adapters/oracledb/_plugins.py +137 -0
- sqlspec/adapters/oracledb/_storage.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_storage.py +138 -0
- sqlspec/adapters/oracledb/_typing.py +468 -0
- sqlspec/adapters/oracledb/_uuid_handlers.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_uuid_handlers.py +143 -0
- sqlspec/adapters/oracledb/_vector_handlers.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_vector_handlers.py +252 -0
- sqlspec/adapters/oracledb/adk/__init__.py +27 -0
- sqlspec/adapters/oracledb/adk/store.py +4031 -0
- sqlspec/adapters/oracledb/config.py +1785 -0
- sqlspec/adapters/oracledb/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/core.py +5416 -0
- sqlspec/adapters/oracledb/data_dictionary.py +1264 -0
- sqlspec/adapters/oracledb/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/driver.py +3273 -0
- sqlspec/adapters/oracledb/events/__init__.py +29 -0
- sqlspec/adapters/oracledb/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/events/_hub.py +394 -0
- sqlspec/adapters/oracledb/events/backend.py +311 -0
- sqlspec/adapters/oracledb/events/store.py +842 -0
- sqlspec/adapters/oracledb/litestar/__init__.py +17 -0
- sqlspec/adapters/oracledb/litestar/store.py +862 -0
- sqlspec/adapters/oracledb/migrations.py +650 -0
- sqlspec/adapters/oracledb/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/tenant.py +990 -0
- sqlspec/adapters/oracledb/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/type_converter.py +93 -0
- sqlspec/adapters/psqlpy/__init__.py +21 -0
- sqlspec/adapters/psqlpy/_typing.py +180 -0
- sqlspec/adapters/psqlpy/adk/__init__.py +5 -0
- sqlspec/adapters/psqlpy/adk/store.py +1514 -0
- sqlspec/adapters/psqlpy/config.py +828 -0
- sqlspec/adapters/psqlpy/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/core.py +1040 -0
- sqlspec/adapters/psqlpy/data_dictionary.py +399 -0
- sqlspec/adapters/psqlpy/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/driver.py +631 -0
- sqlspec/adapters/psqlpy/events/__init__.py +12 -0
- sqlspec/adapters/psqlpy/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/events/_hub.py +367 -0
- sqlspec/adapters/psqlpy/events/backend.py +415 -0
- sqlspec/adapters/psqlpy/events/store.py +46 -0
- sqlspec/adapters/psqlpy/litestar/__init__.py +5 -0
- sqlspec/adapters/psqlpy/litestar/store.py +270 -0
- sqlspec/adapters/psqlpy/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/tenant.py +137 -0
- sqlspec/adapters/psqlpy/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/type_converter.py +21 -0
- sqlspec/adapters/psycopg/__init__.py +44 -0
- sqlspec/adapters/psycopg/_typing.py +408 -0
- sqlspec/adapters/psycopg/adk/__init__.py +17 -0
- sqlspec/adapters/psycopg/adk/store.py +2761 -0
- sqlspec/adapters/psycopg/config.py +1522 -0
- sqlspec/adapters/psycopg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/core.py +1001 -0
- sqlspec/adapters/psycopg/data_dictionary.py +701 -0
- sqlspec/adapters/psycopg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/driver.py +1629 -0
- sqlspec/adapters/psycopg/events/__init__.py +25 -0
- sqlspec/adapters/psycopg/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/events/_hub.py +646 -0
- sqlspec/adapters/psycopg/events/backend.py +739 -0
- sqlspec/adapters/psycopg/events/store.py +82 -0
- sqlspec/adapters/psycopg/litestar/__init__.py +5 -0
- sqlspec/adapters/psycopg/litestar/store.py +595 -0
- sqlspec/adapters/psycopg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/tenant.py +226 -0
- sqlspec/adapters/psycopg/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/type_converter.py +94 -0
- sqlspec/adapters/pymssql/__init__.py +29 -0
- sqlspec/adapters/pymssql/_typing.py +156 -0
- sqlspec/adapters/pymssql/adk/__init__.py +5 -0
- sqlspec/adapters/pymssql/adk/store.py +1270 -0
- sqlspec/adapters/pymssql/config.py +299 -0
- sqlspec/adapters/pymssql/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/core.py +527 -0
- sqlspec/adapters/pymssql/data_dictionary.py +417 -0
- sqlspec/adapters/pymssql/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/driver.py +527 -0
- sqlspec/adapters/pymssql/events/__init__.py +5 -0
- sqlspec/adapters/pymssql/events/store.py +46 -0
- sqlspec/adapters/pymssql/litestar/__init__.py +5 -0
- sqlspec/adapters/pymssql/litestar/store.py +350 -0
- sqlspec/adapters/pymssql/migrations.py +162 -0
- sqlspec/adapters/pymssql/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/pool.py +417 -0
- sqlspec/adapters/pymssql/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/tenant.py +73 -0
- sqlspec/adapters/pymysql/__init__.py +27 -0
- sqlspec/adapters/pymysql/_typing.py +105 -0
- sqlspec/adapters/pymysql/adk/__init__.py +5 -0
- sqlspec/adapters/pymysql/adk/store.py +1646 -0
- sqlspec/adapters/pymysql/config.py +545 -0
- sqlspec/adapters/pymysql/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymysql/core.py +909 -0
- sqlspec/adapters/pymysql/data_dictionary.py +16 -0
- sqlspec/adapters/pymysql/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymysql/driver.py +370 -0
- sqlspec/adapters/pymysql/events/__init__.py +5 -0
- sqlspec/adapters/pymysql/events/store.py +42 -0
- sqlspec/adapters/pymysql/litestar/__init__.py +5 -0
- sqlspec/adapters/pymysql/litestar/store.py +299 -0
- sqlspec/adapters/pymysql/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymysql/pool.py +480 -0
- sqlspec/adapters/snowflake/__init__.py +36 -0
- sqlspec/adapters/snowflake/_typing.py +62 -0
- sqlspec/adapters/snowflake/adk/__init__.py +5 -0
- sqlspec/adapters/snowflake/adk/store.py +778 -0
- sqlspec/adapters/snowflake/config.py +333 -0
- sqlspec/adapters/snowflake/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/core.py +683 -0
- sqlspec/adapters/snowflake/data_dictionary.py +355 -0
- sqlspec/adapters/snowflake/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/driver.py +872 -0
- sqlspec/adapters/snowflake/events/__init__.py +5 -0
- sqlspec/adapters/snowflake/events/store.py +28 -0
- sqlspec/adapters/snowflake/litestar/__init__.py +5 -0
- sqlspec/adapters/snowflake/litestar/store.py +162 -0
- sqlspec/adapters/snowflake/migrations.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/migrations.py +76 -0
- sqlspec/adapters/snowflake/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/pool.py +385 -0
- sqlspec/adapters/snowflake/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/tenant.py +200 -0
- sqlspec/adapters/snowflake/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/type_converter.py +33 -0
- sqlspec/adapters/spanner/__init__.py +57 -0
- sqlspec/adapters/spanner/_typing.py +300 -0
- sqlspec/adapters/spanner/adk/__init__.py +22 -0
- sqlspec/adapters/spanner/adk/artifact_store.py +693 -0
- sqlspec/adapters/spanner/adk/store.py +3053 -0
- sqlspec/adapters/spanner/config.py +1578 -0
- sqlspec/adapters/spanner/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/spanner/core.py +1244 -0
- sqlspec/adapters/spanner/data_dictionary.py +706 -0
- sqlspec/adapters/spanner/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/spanner/driver.py +1673 -0
- sqlspec/adapters/spanner/events/__init__.py +5 -0
- sqlspec/adapters/spanner/events/store.py +357 -0
- sqlspec/adapters/spanner/litestar/__init__.py +5 -0
- sqlspec/adapters/spanner/litestar/store.py +570 -0
- sqlspec/adapters/spanner/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/spanner/type_converter.py +466 -0
- sqlspec/adapters/sqlanywhere/__init__.py +40 -0
- sqlspec/adapters/sqlanywhere/_typing.py +139 -0
- sqlspec/adapters/sqlanywhere/adk/__init__.py +5 -0
- sqlspec/adapters/sqlanywhere/adk/store.py +1136 -0
- sqlspec/adapters/sqlanywhere/config.py +359 -0
- sqlspec/adapters/sqlanywhere/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlanywhere/core.py +583 -0
- sqlspec/adapters/sqlanywhere/data_dictionary.py +282 -0
- sqlspec/adapters/sqlanywhere/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlanywhere/driver.py +480 -0
- sqlspec/adapters/sqlanywhere/events/__init__.py +5 -0
- sqlspec/adapters/sqlanywhere/events/store.py +28 -0
- sqlspec/adapters/sqlanywhere/litestar/__init__.py +5 -0
- sqlspec/adapters/sqlanywhere/litestar/store.py +237 -0
- sqlspec/adapters/sqlanywhere/migrations.py +178 -0
- sqlspec/adapters/sqlanywhere/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlanywhere/pool.py +397 -0
- sqlspec/adapters/sqlite/__init__.py +32 -0
- sqlspec/adapters/sqlite/_typing.py +91 -0
- sqlspec/adapters/sqlite/adk/__init__.py +5 -0
- sqlspec/adapters/sqlite/adk/store.py +1628 -0
- sqlspec/adapters/sqlite/config.py +520 -0
- sqlspec/adapters/sqlite/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/core.py +1035 -0
- sqlspec/adapters/sqlite/data_dictionary.py +327 -0
- sqlspec/adapters/sqlite/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/driver.py +432 -0
- sqlspec/adapters/sqlite/events/__init__.py +5 -0
- sqlspec/adapters/sqlite/events/store.py +54 -0
- sqlspec/adapters/sqlite/litestar/__init__.py +5 -0
- sqlspec/adapters/sqlite/litestar/store.py +367 -0
- sqlspec/adapters/sqlite/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/pool.py +935 -0
- sqlspec/adapters/sqlite/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/type_converter.py +114 -0
- sqlspec/adapters/sybase/__init__.py +37 -0
- sqlspec/adapters/sybase/_typing.py +150 -0
- sqlspec/adapters/sybase/adk/__init__.py +5 -0
- sqlspec/adapters/sybase/adk/store.py +1370 -0
- sqlspec/adapters/sybase/config.py +276 -0
- sqlspec/adapters/sybase/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sybase/core.py +578 -0
- sqlspec/adapters/sybase/data_dictionary.py +358 -0
- sqlspec/adapters/sybase/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sybase/driver.py +497 -0
- sqlspec/adapters/sybase/events/__init__.py +5 -0
- sqlspec/adapters/sybase/events/store.py +88 -0
- sqlspec/adapters/sybase/litestar/__init__.py +5 -0
- sqlspec/adapters/sybase/litestar/store.py +328 -0
- sqlspec/adapters/sybase/migrations.py +178 -0
- sqlspec/adapters/sybase/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sybase/pool.py +435 -0
- sqlspec/adapters/teradata/__init__.py +59 -0
- sqlspec/adapters/teradata/_typing.py +145 -0
- sqlspec/adapters/teradata/adk/__init__.py +5 -0
- sqlspec/adapters/teradata/adk/store.py +1300 -0
- sqlspec/adapters/teradata/config.py +324 -0
- sqlspec/adapters/teradata/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/core.py +437 -0
- sqlspec/adapters/teradata/data_dictionary.py +316 -0
- sqlspec/adapters/teradata/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/driver.py +721 -0
- sqlspec/adapters/teradata/events/__init__.py +5 -0
- sqlspec/adapters/teradata/events/store.py +64 -0
- sqlspec/adapters/teradata/litestar/__init__.py +5 -0
- sqlspec/adapters/teradata/litestar/store.py +264 -0
- sqlspec/adapters/teradata/migrations.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/migrations.py +80 -0
- sqlspec/adapters/teradata/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/pool.py +377 -0
- sqlspec/adapters/teradata/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/type_converter.py +95 -0
- sqlspec/base.cp315-win_amd64.pyd +0 -0
- sqlspec/base.py +1275 -0
- sqlspec/builder/__init__.py +330 -0
- sqlspec/builder/_base.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_base.py +1752 -0
- sqlspec/builder/_column.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_column.py +508 -0
- sqlspec/builder/_ddl.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_ddl.py +4503 -0
- sqlspec/builder/_delete.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_delete.py +75 -0
- sqlspec/builder/_dml.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_dml.py +639 -0
- sqlspec/builder/_explain.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_explain.py +650 -0
- sqlspec/builder/_expression_wrappers.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_expression_wrappers.py +77 -0
- sqlspec/builder/_factory.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_factory.py +1834 -0
- sqlspec/builder/_generation.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_generation.py +55 -0
- sqlspec/builder/_insert.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_insert.py +308 -0
- sqlspec/builder/_join.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_join.py +501 -0
- sqlspec/builder/_locking.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_locking.py +77 -0
- sqlspec/builder/_merge.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_merge.py +1047 -0
- sqlspec/builder/_parsing_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_parsing_utils.py +1197 -0
- sqlspec/builder/_select.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_select.py +1514 -0
- sqlspec/builder/_temporal.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_temporal.py +183 -0
- sqlspec/builder/_update.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_update.py +139 -0
- sqlspec/builder/_values.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_values.py +271 -0
- sqlspec/builder/_vector_distance.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_vector_distance.py +763 -0
- sqlspec/cli.py +1656 -0
- sqlspec/config.py +3402 -0
- sqlspec/core/__init__.py +542 -0
- sqlspec/core/_cursor.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_cursor.py +564 -0
- sqlspec/core/_operators.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_operators.py +167 -0
- sqlspec/core/_ordering.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_ordering.py +151 -0
- sqlspec/core/_pagination.py +66 -0
- sqlspec/core/_pipeline.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_pipeline.py +343 -0
- sqlspec/core/_pool.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_pool.py +72 -0
- sqlspec/core/cache.cp315-win_amd64.pyd +0 -0
- sqlspec/core/cache.py +1503 -0
- sqlspec/core/capabilities.cp315-win_amd64.pyd +0 -0
- sqlspec/core/capabilities.py +67 -0
- sqlspec/core/compiler.cp315-win_amd64.pyd +0 -0
- sqlspec/core/compiler.py +1667 -0
- sqlspec/core/config_runtime.cp315-win_amd64.pyd +0 -0
- sqlspec/core/config_runtime.py +219 -0
- sqlspec/core/correlation.cp315-win_amd64.pyd +0 -0
- sqlspec/core/correlation.py +135 -0
- sqlspec/core/explain.cp315-win_amd64.pyd +0 -0
- sqlspec/core/explain.py +284 -0
- sqlspec/core/filters.cp315-win_amd64.pyd +0 -0
- sqlspec/core/filters.py +1442 -0
- sqlspec/core/hashing.cp315-win_amd64.pyd +0 -0
- sqlspec/core/hashing.py +394 -0
- sqlspec/core/metrics.cp315-win_amd64.pyd +0 -0
- sqlspec/core/metrics.py +86 -0
- sqlspec/core/parameters/__init__.py +174 -0
- sqlspec/core/parameters/_alignment.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_alignment.py +321 -0
- sqlspec/core/parameters/_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_converter.py +956 -0
- sqlspec/core/parameters/_declared.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_declared.py +154 -0
- sqlspec/core/parameters/_processor.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_processor.py +1646 -0
- sqlspec/core/parameters/_registry.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_registry.py +207 -0
- sqlspec/core/parameters/_transformers.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_transformers.py +318 -0
- sqlspec/core/parameters/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_types.py +658 -0
- sqlspec/core/parameters/_validator.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_validator.py +699 -0
- sqlspec/core/query_modifiers.cp315-win_amd64.pyd +0 -0
- sqlspec/core/query_modifiers.py +559 -0
- sqlspec/core/result/__init__.py +67 -0
- sqlspec/core/result/_base.cp315-win_amd64.pyd +0 -0
- sqlspec/core/result/_base.py +1772 -0
- sqlspec/core/routing.cp315-win_amd64.pyd +0 -0
- sqlspec/core/routing.py +270 -0
- sqlspec/core/splitter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/splitter.py +1126 -0
- sqlspec/core/sqlcommenter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/sqlcommenter.py +509 -0
- sqlspec/core/stack.cp315-win_amd64.pyd +0 -0
- sqlspec/core/stack.py +167 -0
- sqlspec/core/statement.cp315-win_amd64.pyd +0 -0
- sqlspec/core/statement.py +2253 -0
- sqlspec/core/tenant/__init__.py +64 -0
- sqlspec/core/tenant/base.cp315-win_amd64.pyd +0 -0
- sqlspec/core/tenant/base.py +123 -0
- sqlspec/core/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/type_converter.py +147 -0
- sqlspec/data_dictionary/__init__.py +237 -0
- sqlspec/data_dictionary/_capabilities.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_capabilities.py +142 -0
- sqlspec/data_dictionary/_dependencies.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_dependencies.py +602 -0
- sqlspec/data_dictionary/_index_ddl.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_index_ddl.py +562 -0
- sqlspec/data_dictionary/_loader.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_loader.py +344 -0
- sqlspec/data_dictionary/_registry.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_registry.py +152 -0
- sqlspec/data_dictionary/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_types.py +1852 -0
- sqlspec/data_dictionary/dialects/__init__.py +34 -0
- sqlspec/data_dictionary/dialects/bigquery/__init__.py +15 -0
- sqlspec/data_dictionary/dialects/bigquery/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/bigquery/config.py +128 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/columns.sql +63 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/constraints.sql +37 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/datasets.sql +14 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/ddl.sql +51 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/dependencies.sql +22 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/foreign_keys.sql +34 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/indexes.sql +59 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/objects.sql +13 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/privileges.sql +13 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/routines.sql +50 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/system.sql +59 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/tables.sql +111 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/views.sql +31 -0
- sqlspec/data_dictionary/dialects/cockroachdb/__init__.py +17 -0
- sqlspec/data_dictionary/dialects/cockroachdb/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/cockroachdb/config.py +95 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/columns.sql +163 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/comments.sql +10 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/constraints.sql +67 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/crdb_internal.sql +11 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/ddl.sql +10 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/dependencies.sql +20 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/foreign_keys.sql +62 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/indexes.sql +32 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/objects.sql +15 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/privileges.sql +13 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/sequences.sql +14 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/tables.sql +15 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/views.sql +11 -0
- sqlspec/data_dictionary/dialects/db2/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/db2/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/db2/config.py +172 -0
- sqlspec/data_dictionary/dialects/db2/sql/columns.sql +98 -0
- sqlspec/data_dictionary/dialects/db2/sql/constraints.sql +49 -0
- sqlspec/data_dictionary/dialects/db2/sql/foreign_keys.sql +43 -0
- sqlspec/data_dictionary/dialects/db2/sql/indexes.sql +39 -0
- sqlspec/data_dictionary/dialects/db2/sql/objects.sql +53 -0
- sqlspec/data_dictionary/dialects/db2/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/db2/sql/tables.sql +77 -0
- sqlspec/data_dictionary/dialects/db2/sql/version.sql +8 -0
- sqlspec/data_dictionary/dialects/db2/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/duckdb/__init__.py +5 -0
- sqlspec/data_dictionary/dialects/duckdb/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/duckdb/config.py +66 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/columns.sql +150 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/constraints.sql +34 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/databases.sql +11 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/ddl.sql +221 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/dependencies.sql +50 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/extensions.sql +14 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/foreign_keys.sql +46 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/functions.sql +18 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/indexes.sql +34 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/objects.sql +30 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/sequences.sql +19 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/system.sql +21 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/tables.sql +59 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/types.sql +12 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/mariadb/__init__.py +5 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/columns.sql +45 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/constraints.sql +30 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/ddl.sql +27 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/events.sql +29 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/foreign_keys.sql +42 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/indexes.sql +33 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/objects.sql +50 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/partitions.sql +27 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/plugins.sql +16 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/privileges.sql +24 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/routines.sql +21 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/system.sql +12 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/tables.sql +64 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/triggers.sql +21 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/version.sql +7 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/mssql/__init__.py +51 -0
- sqlspec/data_dictionary/dialects/mssql/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/mssql/config.py +558 -0
- sqlspec/data_dictionary/dialects/mssql/sql/columns.sql +120 -0
- sqlspec/data_dictionary/dialects/mssql/sql/constraints.sql +106 -0
- sqlspec/data_dictionary/dialects/mssql/sql/ddl.sql +89 -0
- sqlspec/data_dictionary/dialects/mssql/sql/dependencies.sql +17 -0
- sqlspec/data_dictionary/dialects/mssql/sql/extended_properties.sql +16 -0
- sqlspec/data_dictionary/dialects/mssql/sql/foreign_keys.sql +40 -0
- sqlspec/data_dictionary/dialects/mssql/sql/indexes.sql +86 -0
- sqlspec/data_dictionary/dialects/mssql/sql/modules.sql +19 -0
- sqlspec/data_dictionary/dialects/mssql/sql/objects.sql +16 -0
- sqlspec/data_dictionary/dialects/mssql/sql/permissions.sql +31 -0
- sqlspec/data_dictionary/dialects/mssql/sql/routines.sql +39 -0
- sqlspec/data_dictionary/dialects/mssql/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/mssql/sql/sequences.sql +18 -0
- sqlspec/data_dictionary/dialects/mssql/sql/storage.sql +22 -0
- sqlspec/data_dictionary/dialects/mssql/sql/system.sql +38 -0
- sqlspec/data_dictionary/dialects/mssql/sql/tables.sql +97 -0
- sqlspec/data_dictionary/dialects/mssql/sql/triggers.sql +21 -0
- sqlspec/data_dictionary/dialects/mssql/sql/version.sql +7 -0
- sqlspec/data_dictionary/dialects/mssql/sql/views.sql +18 -0
- sqlspec/data_dictionary/dialects/mysql/__init__.py +34 -0
- sqlspec/data_dictionary/dialects/mysql/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/mysql/config.py +363 -0
- sqlspec/data_dictionary/dialects/mysql/dictionary.py +650 -0
- sqlspec/data_dictionary/dialects/mysql/sql/columns.sql +45 -0
- sqlspec/data_dictionary/dialects/mysql/sql/components.sql +8 -0
- sqlspec/data_dictionary/dialects/mysql/sql/constraints.sql +30 -0
- sqlspec/data_dictionary/dialects/mysql/sql/ddl.sql +23 -0
- sqlspec/data_dictionary/dialects/mysql/sql/events.sql +29 -0
- sqlspec/data_dictionary/dialects/mysql/sql/foreign_keys.sql +42 -0
- sqlspec/data_dictionary/dialects/mysql/sql/indexes.sql +33 -0
- sqlspec/data_dictionary/dialects/mysql/sql/objects.sql +38 -0
- sqlspec/data_dictionary/dialects/mysql/sql/partitions.sql +27 -0
- sqlspec/data_dictionary/dialects/mysql/sql/plugins.sql +16 -0
- sqlspec/data_dictionary/dialects/mysql/sql/privileges.sql +26 -0
- sqlspec/data_dictionary/dialects/mysql/sql/routines.sql +21 -0
- sqlspec/data_dictionary/dialects/mysql/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/mysql/sql/system.sql +25 -0
- sqlspec/data_dictionary/dialects/mysql/sql/tables.sql +64 -0
- sqlspec/data_dictionary/dialects/mysql/sql/triggers.sql +21 -0
- sqlspec/data_dictionary/dialects/mysql/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/mysql/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/oracle/__init__.py +39 -0
- sqlspec/data_dictionary/dialects/oracle/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/oracle/config.py +266 -0
- sqlspec/data_dictionary/dialects/oracle/sql/arguments.sql +29 -0
- sqlspec/data_dictionary/dialects/oracle/sql/columns.sql +103 -0
- sqlspec/data_dictionary/dialects/oracle/sql/comments.sql +22 -0
- sqlspec/data_dictionary/dialects/oracle/sql/constraints.sql +49 -0
- sqlspec/data_dictionary/dialects/oracle/sql/ddl.sql +4 -0
- sqlspec/data_dictionary/dialects/oracle/sql/dependencies.sql +16 -0
- sqlspec/data_dictionary/dialects/oracle/sql/foreign_keys.sql +48 -0
- sqlspec/data_dictionary/dialects/oracle/sql/grants.sql +34 -0
- sqlspec/data_dictionary/dialects/oracle/sql/indexes.sql +87 -0
- sqlspec/data_dictionary/dialects/oracle/sql/lob_storage.sql +28 -0
- sqlspec/data_dictionary/dialects/oracle/sql/materialized_views.sql +27 -0
- sqlspec/data_dictionary/dialects/oracle/sql/objects.sql +26 -0
- sqlspec/data_dictionary/dialects/oracle/sql/partitions.sql +44 -0
- sqlspec/data_dictionary/dialects/oracle/sql/routines.sql +21 -0
- sqlspec/data_dictionary/dialects/oracle/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/oracle/sql/sequences.sql +21 -0
- sqlspec/data_dictionary/dialects/oracle/sql/source.sql +13 -0
- sqlspec/data_dictionary/dialects/oracle/sql/system.sql +37 -0
- sqlspec/data_dictionary/dialects/oracle/sql/tables.sql +48 -0
- sqlspec/data_dictionary/dialects/oracle/sql/triggers.sql +29 -0
- sqlspec/data_dictionary/dialects/oracle/sql/version.sql +25 -0
- sqlspec/data_dictionary/dialects/oracle/sql/views.sql +49 -0
- sqlspec/data_dictionary/dialects/postgres/__init__.py +19 -0
- sqlspec/data_dictionary/dialects/postgres/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/postgres/config.py +119 -0
- sqlspec/data_dictionary/dialects/postgres/sql/columns.sql +130 -0
- sqlspec/data_dictionary/dialects/postgres/sql/comments.sql +27 -0
- sqlspec/data_dictionary/dialects/postgres/sql/constraints.sql +53 -0
- sqlspec/data_dictionary/dialects/postgres/sql/ddl.sql +55 -0
- sqlspec/data_dictionary/dialects/postgres/sql/dependencies.sql +42 -0
- sqlspec/data_dictionary/dialects/postgres/sql/extensions.sql +11 -0
- sqlspec/data_dictionary/dialects/postgres/sql/foreign_keys.sql +72 -0
- sqlspec/data_dictionary/dialects/postgres/sql/indexes.sql +84 -0
- sqlspec/data_dictionary/dialects/postgres/sql/materialized_views.sql +17 -0
- sqlspec/data_dictionary/dialects/postgres/sql/objects.sql +25 -0
- sqlspec/data_dictionary/dialects/postgres/sql/partitions.sql +19 -0
- sqlspec/data_dictionary/dialects/postgres/sql/privileges.sql +29 -0
- sqlspec/data_dictionary/dialects/postgres/sql/routines.sql +25 -0
- sqlspec/data_dictionary/dialects/postgres/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/postgres/sql/sequences.sql +32 -0
- sqlspec/data_dictionary/dialects/postgres/sql/system.sql +53 -0
- sqlspec/data_dictionary/dialects/postgres/sql/tables.sql +67 -0
- sqlspec/data_dictionary/dialects/postgres/sql/triggers.sql +20 -0
- sqlspec/data_dictionary/dialects/postgres/sql/types.sql +21 -0
- sqlspec/data_dictionary/dialects/postgres/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/postgres/sql/views.sql +17 -0
- sqlspec/data_dictionary/dialects/snowflake/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/snowflake/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/snowflake/config.py +321 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/columns.sql +48 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/constraints.sql +64 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/ddl.sql +3 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/foreign_keys.sql +7 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/objects.sql +34 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/routines.sql +79 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/schemas.sql +19 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/sequences.sql +45 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/tables.sql +29 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/views.sql +37 -0
- sqlspec/data_dictionary/dialects/spanner/__init__.py +5 -0
- sqlspec/data_dictionary/dialects/spanner/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/spanner/config.py +67 -0
- sqlspec/data_dictionary/dialects/spanner/sql/columns.sql +58 -0
- sqlspec/data_dictionary/dialects/spanner/sql/foreign_keys.sql +91 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/change_streams.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/columns.sql +46 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/constraints.sql +63 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/database.sql +9 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/foreign_keys.sql +91 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/indexes.sql +66 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/objects.sql +10 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/placements.sql +8 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/privileges.sql +13 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/property_graphs.sql +11 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/routines.sql +33 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/sequences.sql +14 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/system.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/tables.sql +30 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/views.sql +13 -0
- sqlspec/data_dictionary/dialects/spanner/sql/indexes.sql +30 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/change_streams.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/columns.sql +34 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/constraints.sql +63 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/foreign_keys.sql +91 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/indexes.sql +52 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/objects.sql +10 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/sequences.sql +14 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/system.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/tables.sql +22 -0
- sqlspec/data_dictionary/dialects/spanner/sql/tables.sql +9 -0
- sqlspec/data_dictionary/dialects/spanner/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/config.py +191 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/columns.sql +97 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/constraints.sql +43 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/foreign_keys.sql +45 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/indexes.sql +39 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/objects.sql +18 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/schemas.sql +15 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/tables.sql +86 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/sqlite/__init__.py +19 -0
- sqlspec/data_dictionary/dialects/sqlite/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/sqlite/config.py +412 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/columns.sql +59 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/compile_options.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/constraints.sql +67 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/ddl.sql +37 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/foreign_keys.sql +45 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/functions.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/indexes.sql +76 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/modules.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/objects.sql +13 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/schemas.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/system.sql +7 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/tables.sql +64 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/triggers.sql +10 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/views.sql +10 -0
- sqlspec/data_dictionary/dialects/sybase/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/sybase/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/sybase/config.py +187 -0
- sqlspec/data_dictionary/dialects/sybase/sql/columns.sql +137 -0
- sqlspec/data_dictionary/dialects/sybase/sql/constraints.sql +85 -0
- sqlspec/data_dictionary/dialects/sybase/sql/foreign_keys.sql +81 -0
- sqlspec/data_dictionary/dialects/sybase/sql/indexes.sql +51 -0
- sqlspec/data_dictionary/dialects/sybase/sql/objects.sql +21 -0
- sqlspec/data_dictionary/dialects/sybase/sql/schemas.sql +16 -0
- sqlspec/data_dictionary/dialects/sybase/sql/tables.sql +46 -0
- sqlspec/data_dictionary/dialects/sybase/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sybase/sql/views.sql +19 -0
- sqlspec/data_dictionary/dialects/teradata/__init__.py +33 -0
- sqlspec/data_dictionary/dialects/teradata/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/teradata/config.py +228 -0
- sqlspec/data_dictionary/dialects/teradata/sql/columns.sql +22 -0
- sqlspec/data_dictionary/dialects/teradata/sql/constraints.sql +19 -0
- sqlspec/data_dictionary/dialects/teradata/sql/foreign_keys.sql +9 -0
- sqlspec/data_dictionary/dialects/teradata/sql/indexes.sql +9 -0
- sqlspec/data_dictionary/dialects/teradata/sql/objects.sql +4 -0
- sqlspec/data_dictionary/dialects/teradata/sql/schemas.sql +9 -0
- sqlspec/data_dictionary/dialects/teradata/sql/tables.sql +22 -0
- sqlspec/data_dictionary/dialects/teradata/sql/version.sql +4 -0
- sqlspec/data_dictionary/dialects/teradata/sql/views.sql +4 -0
- sqlspec/dialects/__init__.py +44 -0
- sqlspec/dialects/db2/__init__.py +111 -0
- sqlspec/dialects/db2/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/db2/_generators.py +376 -0
- sqlspec/dialects/db2/_parsers.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/db2/_parsers.py +657 -0
- sqlspec/dialects/db2/_transforms.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/db2/_transforms.py +175 -0
- sqlspec/dialects/postgres/__init__.py +10 -0
- sqlspec/dialects/postgres/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/postgres/_generators.py +81 -0
- sqlspec/dialects/postgres/_operators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/postgres/_operators.py +95 -0
- sqlspec/dialects/postgres/_paradedb.py +44 -0
- sqlspec/dialects/postgres/_pg_textsearch.py +38 -0
- sqlspec/dialects/postgres/_pgvector.py +36 -0
- sqlspec/dialects/spanner/__init__.py +69 -0
- sqlspec/dialects/spanner/_expressions.py +247 -0
- sqlspec/dialects/spanner/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/spanner/_generators.py +961 -0
- sqlspec/dialects/spanner/_parsers.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/spanner/_parsers.py +871 -0
- sqlspec/dialects/spanner/_spangres.py +43 -0
- sqlspec/dialects/spanner/_spanner.py +57 -0
- sqlspec/dialects/sybase/__init__.py +115 -0
- sqlspec/dialects/sybase/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/sybase/_generators.py +379 -0
- sqlspec/dialects/sybase/_parsers.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/sybase/_parsers.py +225 -0
- sqlspec/dialects/sybase/_transforms.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/sybase/_transforms.py +68 -0
- sqlspec/dialects/teradata/__init__.py +42 -0
- sqlspec/dialects/teradata/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/teradata/_generators.py +203 -0
- sqlspec/driver/__init__.py +151 -0
- sqlspec/driver/_async.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_async.py +3244 -0
- sqlspec/driver/_common.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_common.py +4765 -0
- sqlspec/driver/_deferred.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_deferred.py +232 -0
- sqlspec/driver/_exception_handler.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_exception_handler.py +224 -0
- sqlspec/driver/_routing.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_routing.py +2891 -0
- sqlspec/driver/_session.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_session.py +180 -0
- sqlspec/driver/_sql_helpers.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_sql_helpers.py +140 -0
- sqlspec/driver/_stream.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_stream.py +392 -0
- sqlspec/driver/_sync.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_sync.py +3107 -0
- sqlspec/driver/_tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_tenant.py +326 -0
- sqlspec/exceptions.cp315-win_amd64.pyd +0 -0
- sqlspec/exceptions.py +568 -0
- sqlspec/extensions/__init__.py +3 -0
- sqlspec/extensions/adk/__init__.py +136 -0
- sqlspec/extensions/adk/_config_utils.py +306 -0
- sqlspec/extensions/adk/_table_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/_table_utils.py +126 -0
- sqlspec/extensions/adk/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/_types.py +59 -0
- sqlspec/extensions/adk/artifact/__init__.py +18 -0
- sqlspec/extensions/adk/artifact/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/artifact/_types.py +41 -0
- sqlspec/extensions/adk/artifact/service.py +657 -0
- sqlspec/extensions/adk/artifact/store.py +444 -0
- sqlspec/extensions/adk/converters.py +230 -0
- sqlspec/extensions/adk/maintenance.py +262 -0
- sqlspec/extensions/adk/memory/__init__.py +36 -0
- sqlspec/extensions/adk/memory/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/memory/_types.py +48 -0
- sqlspec/extensions/adk/memory/converters.py +271 -0
- sqlspec/extensions/adk/memory/service.py +474 -0
- sqlspec/extensions/adk/memory/store.py +586 -0
- sqlspec/extensions/adk/migrations/0001_create_adk_tables.py +181 -0
- sqlspec/extensions/adk/migrations/0002_create_mssql_python_memory.py +51 -0
- sqlspec/extensions/adk/migrations/__init__.py +3 -0
- sqlspec/extensions/adk/migrations/reconcile.py +282 -0
- sqlspec/extensions/adk/service.py +463 -0
- sqlspec/extensions/adk/store.py +1239 -0
- sqlspec/extensions/events/__init__.py +132 -0
- sqlspec/extensions/events/_buffer.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_buffer.py +38 -0
- sqlspec/extensions/events/_channel.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_channel.py +1144 -0
- sqlspec/extensions/events/_hints.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_hints.py +38 -0
- sqlspec/extensions/events/_models.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_models.py +22 -0
- sqlspec/extensions/events/_names.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_names.py +27 -0
- sqlspec/extensions/events/_payload.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_payload.py +139 -0
- sqlspec/extensions/events/_protocols.py +154 -0
- sqlspec/extensions/events/_queue.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_queue.py +1147 -0
- sqlspec/extensions/events/_store.py +318 -0
- sqlspec/extensions/events/migrations/0001_create_event_queue.py +106 -0
- sqlspec/extensions/events/migrations/__init__.py +3 -0
- sqlspec/extensions/events/migrations/reconcile.py +145 -0
- sqlspec/extensions/events/primitives.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/primitives.py +91 -0
- sqlspec/extensions/fastapi/__init__.py +26 -0
- sqlspec/extensions/fastapi/extension.py +360 -0
- sqlspec/extensions/fastapi/providers.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/fastapi/providers.py +1091 -0
- sqlspec/extensions/flask/__init__.py +20 -0
- sqlspec/extensions/flask/_portal.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/flask/_portal.py +212 -0
- sqlspec/extensions/flask/_state.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/flask/_state.py +135 -0
- sqlspec/extensions/flask/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/flask/_utils.py +171 -0
- sqlspec/extensions/flask/extension.py +1234 -0
- sqlspec/extensions/litestar/__init__.py +52 -0
- sqlspec/extensions/litestar/_tenant_resolution.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/litestar/_tenant_resolution.py +314 -0
- sqlspec/extensions/litestar/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/litestar/_utils.py +222 -0
- sqlspec/extensions/litestar/channels.py +249 -0
- sqlspec/extensions/litestar/cli.py +100 -0
- sqlspec/extensions/litestar/config.py +5 -0
- sqlspec/extensions/litestar/handlers.py +796 -0
- sqlspec/extensions/litestar/migrations/0001_create_session_table.py +138 -0
- sqlspec/extensions/litestar/migrations/__init__.py +3 -0
- sqlspec/extensions/litestar/migrations/reconcile.py +132 -0
- sqlspec/extensions/litestar/plugin.py +2172 -0
- sqlspec/extensions/litestar/providers.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/litestar/providers.py +1239 -0
- sqlspec/extensions/litestar/store.py +613 -0
- sqlspec/extensions/litestar/tenant.py +292 -0
- sqlspec/extensions/otel/__init__.py +58 -0
- sqlspec/extensions/prometheus/__init__.py +5 -0
- sqlspec/extensions/prometheus/_observer.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/prometheus/_observer.py +152 -0
- sqlspec/extensions/sanic/__init__.py +28 -0
- sqlspec/extensions/sanic/_state.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/sanic/_state.py +102 -0
- sqlspec/extensions/sanic/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/sanic/_utils.py +234 -0
- sqlspec/extensions/sanic/extension.py +1467 -0
- sqlspec/extensions/starlette/__init__.py +31 -0
- sqlspec/extensions/starlette/_state.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/starlette/_state.py +103 -0
- sqlspec/extensions/starlette/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/starlette/_utils.py +267 -0
- sqlspec/extensions/starlette/extension.py +691 -0
- sqlspec/extensions/starlette/middleware.py +845 -0
- sqlspec/loader.cp315-win_amd64.pyd +0 -0
- sqlspec/loader.py +1733 -0
- sqlspec/migrations/__init__.py +104 -0
- sqlspec/migrations/_backup.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/_backup.py +36 -0
- sqlspec/migrations/base.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/base.py +1688 -0
- sqlspec/migrations/commands.py +4002 -0
- sqlspec/migrations/context.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/context.py +158 -0
- sqlspec/migrations/fix.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/fix.py +193 -0
- sqlspec/migrations/loaders.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/loaders.py +835 -0
- sqlspec/migrations/runner.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/runner.py +2144 -0
- sqlspec/migrations/schema.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/schema.py +1266 -0
- sqlspec/migrations/squash.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/squash.py +2452 -0
- sqlspec/migrations/templates.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/templates.py +310 -0
- sqlspec/migrations/tracker.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/tracker.py +1529 -0
- sqlspec/migrations/utils.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/utils.py +534 -0
- sqlspec/migrations/validation.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/validation.py +355 -0
- sqlspec/migrations/version.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/version.py +455 -0
- sqlspec/observability/__init__.py +122 -0
- sqlspec/observability/_common.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_common.py +307 -0
- sqlspec/observability/_config.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_config.py +362 -0
- sqlspec/observability/_diagnostics.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_diagnostics.py +75 -0
- sqlspec/observability/_dispatcher.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_dispatcher.py +320 -0
- sqlspec/observability/_formatters/__init__.py +13 -0
- sqlspec/observability/_formatters/_aws.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_aws.py +90 -0
- sqlspec/observability/_formatters/_azure.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_azure.py +84 -0
- sqlspec/observability/_formatters/_base.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_base.py +40 -0
- sqlspec/observability/_formatters/_gcp.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_gcp.py +119 -0
- sqlspec/observability/_formatting.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatting.py +76 -0
- sqlspec/observability/_observer.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_observer.py +445 -0
- sqlspec/observability/_runtime.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_runtime.py +740 -0
- sqlspec/observability/_sampling.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_sampling.py +169 -0
- sqlspec/observability/_spans.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_spans.py +212 -0
- sqlspec/protocols.py +1235 -0
- sqlspec/py.typed +0 -0
- sqlspec/service/__init__.py +5 -0
- sqlspec/service/_base.py +1051 -0
- sqlspec/service/_core.cp315-win_amd64.pyd +0 -0
- sqlspec/service/_core.py +625 -0
- sqlspec/storage/__init__.py +111 -0
- sqlspec/storage/_arrow_payload.py +802 -0
- sqlspec/storage/_arrow_stream.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_arrow_stream.py +134 -0
- sqlspec/storage/_ingest.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_ingest.py +810 -0
- sqlspec/storage/_paths.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_paths.py +313 -0
- sqlspec/storage/_staging_sql.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_staging_sql.py +695 -0
- sqlspec/storage/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_utils.py +174 -0
- sqlspec/storage/backends/__init__.py +43 -0
- sqlspec/storage/backends/base.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/base.py +399 -0
- sqlspec/storage/backends/fsspec.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/fsspec.py +1390 -0
- sqlspec/storage/backends/local.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/local.py +968 -0
- sqlspec/storage/backends/obstore.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/obstore.py +1974 -0
- sqlspec/storage/errors.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/errors.py +127 -0
- sqlspec/storage/pipeline.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/pipeline.py +1270 -0
- sqlspec/storage/registry.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/registry.py +318 -0
- sqlspec/typing.py +261 -0
- sqlspec/utils/__init__.py +9 -0
- sqlspec/utils/adapters.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/adapters.py +186 -0
- sqlspec/utils/arrow_helpers.py +2157 -0
- sqlspec/utils/config_tools.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/config_tools.py +712 -0
- sqlspec/utils/correlation.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/correlation.py +137 -0
- sqlspec/utils/deprecation.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/deprecation.py +222 -0
- sqlspec/utils/dispatch.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/dispatch.py +104 -0
- sqlspec/utils/env.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/env.py +437 -0
- sqlspec/utils/fixtures.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/fixtures.py +2470 -0
- sqlspec/utils/logging.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/logging.py +267 -0
- sqlspec/utils/module_loader.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/module_loader.py +399 -0
- sqlspec/utils/portal.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/portal.py +411 -0
- sqlspec/utils/routing.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/routing.py +645 -0
- sqlspec/utils/schema.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/schema.py +1050 -0
- sqlspec/utils/serializers/__init__.py +69 -0
- sqlspec/utils/serializers/_json.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_json.py +525 -0
- sqlspec/utils/serializers/_numpy.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_numpy.py +65 -0
- sqlspec/utils/serializers/_schema.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_schema.py +340 -0
- sqlspec/utils/sync_tools.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/sync_tools.py +502 -0
- sqlspec/utils/tenant/__init__.py +71 -0
- sqlspec/utils/tenant/_context.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_context.py +550 -0
- sqlspec/utils/tenant/_cursor.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_cursor.py +43 -0
- sqlspec/utils/tenant/_mssql.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_mssql.py +189 -0
- sqlspec/utils/tenant/_postgres.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_postgres.py +142 -0
- sqlspec/utils/text.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/text.py +317 -0
- sqlspec/utils/type_converters.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/type_converters.py +220 -0
- sqlspec/utils/type_guards.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/type_guards.py +1505 -0
- sqlspec/utils/uuids.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/uuids.py +263 -0
- sqlspec-0.72.0.dist-info/METADATA +228 -0
- sqlspec-0.72.0.dist-info/RECORD +1144 -0
- sqlspec-0.72.0.dist-info/WHEEL +4 -0
- sqlspec-0.72.0.dist-info/entry_points.txt +13 -0
- sqlspec-0.72.0.dist-info/licenses/LICENSE +21 -0
sqlspec/driver/_async.py
ADDED
|
@@ -0,0 +1,3244 @@
|
|
|
1
|
+
"""Asynchronous driver protocol implementation.
|
|
2
|
+
|
|
3
|
+
Storage and SQL translation methods are defined directly on ``AsyncDriverAdapterBase``
|
|
4
|
+
rather than separate mixins to avoid cross-trait mypyc attribute dispatch issues,
|
|
5
|
+
and ``AsyncExceptionHandler`` stores mapped exceptions on ``pending_exception``
|
|
6
|
+
rather than raising inside ``__aexit__`` across C-extension ABI boundaries.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
import logging
|
|
11
|
+
import sys
|
|
12
|
+
from abc import abstractmethod
|
|
13
|
+
from inspect import isawaitable
|
|
14
|
+
from time import perf_counter
|
|
15
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Final, Generic, Literal, Self, TypeVar, cast, final, overload
|
|
16
|
+
|
|
17
|
+
from mypy_extensions import mypyc_attr
|
|
18
|
+
|
|
19
|
+
from sqlspec.core.cache import CachedQuery
|
|
20
|
+
from sqlspec.core.result._base import DMLResult, SQLResult, StackResult, create_arrow_result
|
|
21
|
+
from sqlspec.core.stack import StackOperation, StatementStack
|
|
22
|
+
from sqlspec.core.statement import SQL
|
|
23
|
+
from sqlspec.data_dictionary._capabilities import (
|
|
24
|
+
DEFAULT_SYSTEM_METADATA_DOMAINS,
|
|
25
|
+
ensure_system_metadata_request,
|
|
26
|
+
system_metadata_capabilities_from_domains,
|
|
27
|
+
system_metadata_gated_result,
|
|
28
|
+
unsupported_system_metadata_capability,
|
|
29
|
+
)
|
|
30
|
+
from sqlspec.data_dictionary._index_ddl import AsyncWithoutIndexesContext
|
|
31
|
+
from sqlspec.data_dictionary._types import (
|
|
32
|
+
ColumnProfileMetadata,
|
|
33
|
+
DDLResult,
|
|
34
|
+
MetadataCapabilityProfile,
|
|
35
|
+
MetadataResult,
|
|
36
|
+
MetadataSupport,
|
|
37
|
+
ObjectIdentity,
|
|
38
|
+
)
|
|
39
|
+
from sqlspec.driver._common import (
|
|
40
|
+
_CLOSED_CONNECTION,
|
|
41
|
+
AsyncExceptionHandler,
|
|
42
|
+
CommonDriverAttributesMixin,
|
|
43
|
+
DataDictionaryDialectMixin,
|
|
44
|
+
DataDictionaryMixin,
|
|
45
|
+
ExecutionResult,
|
|
46
|
+
StackExecutionObserver,
|
|
47
|
+
_raise_database_exception,
|
|
48
|
+
_resolve_fast_params,
|
|
49
|
+
_sqlglot_dialect,
|
|
50
|
+
describe_stack_statement,
|
|
51
|
+
handle_single_row_error,
|
|
52
|
+
operation_requires_transaction,
|
|
53
|
+
run_cached_execution,
|
|
54
|
+
validate_savepoint_name,
|
|
55
|
+
)
|
|
56
|
+
from sqlspec.driver._exception_handler import _run_with_async_exception_handler
|
|
57
|
+
from sqlspec.driver._sql_helpers import DEFAULT_PRETTY
|
|
58
|
+
from sqlspec.driver._sql_helpers import convert_to_dialect as _convert_to_dialect_impl
|
|
59
|
+
from sqlspec.driver._stream import _CLOSED_CONNECTION_MESSAGE, AsyncRowStream, _LazyEagerAsyncRowSource
|
|
60
|
+
from sqlspec.exceptions import ImproperConfigurationError, StackExecutionError
|
|
61
|
+
from sqlspec.observability import _runtime as observability_runtime
|
|
62
|
+
from sqlspec.observability._common import redact_sql_literals
|
|
63
|
+
from sqlspec.storage._ingest import execute_load_from_storage_async, execute_staged_load_async
|
|
64
|
+
from sqlspec.storage.pipeline import (
|
|
65
|
+
AsyncStoragePipeline,
|
|
66
|
+
StorageBridgeJob,
|
|
67
|
+
StorageDestination,
|
|
68
|
+
StorageFormat,
|
|
69
|
+
StorageTelemetry,
|
|
70
|
+
close_async_arrow_result_resources,
|
|
71
|
+
stringify_storage_target,
|
|
72
|
+
)
|
|
73
|
+
from sqlspec.utils.arrow_helpers import arrow_batches_from_async_rows, convert_dict_to_arrow_with_schema
|
|
74
|
+
from sqlspec.utils.logging import get_logger, log_with_context
|
|
75
|
+
from sqlspec.utils.schema import ValueT, to_value_type
|
|
76
|
+
from sqlspec.utils.sync_tools import exit_async_context
|
|
77
|
+
from sqlspec.utils.type_guards import resolve_row_format
|
|
78
|
+
|
|
79
|
+
if TYPE_CHECKING:
|
|
80
|
+
from collections.abc import Awaitable, Callable, Mapping, Sequence
|
|
81
|
+
from types import TracebackType
|
|
82
|
+
|
|
83
|
+
from sqlglot.dialects.dialect import DialectType
|
|
84
|
+
|
|
85
|
+
from sqlspec.builder._base import QueryBuilder
|
|
86
|
+
from sqlspec.core.compiler import OperationType
|
|
87
|
+
from sqlspec.core.filters import StatementFilter
|
|
88
|
+
from sqlspec.core.result._base import ArrowResult
|
|
89
|
+
from sqlspec.core.statement import Statement, StatementConfig
|
|
90
|
+
from sqlspec.data_dictionary._types import (
|
|
91
|
+
ColumnMetadata,
|
|
92
|
+
ForeignKeyMetadata,
|
|
93
|
+
IndexMetadata,
|
|
94
|
+
SystemMetadataCapability,
|
|
95
|
+
SystemMetadataRequest,
|
|
96
|
+
SystemMetadataResult,
|
|
97
|
+
TableMetadata,
|
|
98
|
+
VersionInfo,
|
|
99
|
+
)
|
|
100
|
+
from sqlspec.typing import ArrowReturnFormat, ArrowTable, SchemaT, StatementParameters
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
__all__ = ("AsyncDataDictionaryBase", "AsyncDriverAdapterBase", "AsyncPoolConnectionContext", "AsyncPoolSessionFactory")
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
_LOGGER_NAME: Final[str] = "sqlspec.driver"
|
|
107
|
+
_DEFAULT_EXPORT_BATCH_SIZE: Final[int] = 10_000
|
|
108
|
+
logger = get_logger(_LOGGER_NAME)
|
|
109
|
+
_AsyncResultT = TypeVar("_AsyncResultT")
|
|
110
|
+
_AsyncDriverT = TypeVar("_AsyncDriverT", bound="AsyncDriverAdapterBase")
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
114
|
+
class AsyncPoolConnectionContext:
|
|
115
|
+
"""Base async connection context using pool acquire/release pattern.
|
|
116
|
+
|
|
117
|
+
Subclass per adapter and override ``__aenter__``/``__aexit__`` for
|
|
118
|
+
adapter-specific pool acquisition and release logic.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
__slots__ = ("_config", "_connection", "_pool", "_tenant_lease")
|
|
122
|
+
|
|
123
|
+
def __init__(self, config: Any) -> None:
|
|
124
|
+
self._config = config
|
|
125
|
+
self._connection: Any = None
|
|
126
|
+
self._pool: Any = None
|
|
127
|
+
self._tenant_lease: Any = config._create_tenant_lease()
|
|
128
|
+
|
|
129
|
+
async def __aenter__(self) -> Any:
|
|
130
|
+
if self._tenant_lease is not None:
|
|
131
|
+
return await self._tenant_lease.acquire()
|
|
132
|
+
pool = self._config.connection_instance
|
|
133
|
+
if pool is None:
|
|
134
|
+
if hasattr(self._config, "provide_pool"):
|
|
135
|
+
pool = await self._config.provide_pool()
|
|
136
|
+
else:
|
|
137
|
+
pool = await self._config.create_pool()
|
|
138
|
+
self._config.connection_instance = pool
|
|
139
|
+
self._pool = pool
|
|
140
|
+
self._connection = await pool.acquire()
|
|
141
|
+
return self._connection
|
|
142
|
+
|
|
143
|
+
async def __aexit__(
|
|
144
|
+
self, exc_type: "type[BaseException] | None", exc_val: "BaseException | None", exc_tb: Any
|
|
145
|
+
) -> "bool | None":
|
|
146
|
+
if self._tenant_lease is not None:
|
|
147
|
+
await self._tenant_lease.release(exc_type=exc_type, exc_val=exc_val, exc_tb=exc_tb)
|
|
148
|
+
return None
|
|
149
|
+
if self._connection is not None:
|
|
150
|
+
pool = self._pool or getattr(self._config, "connection_instance", None)
|
|
151
|
+
if pool is not None:
|
|
152
|
+
await pool.release(self._connection)
|
|
153
|
+
self._connection = None
|
|
154
|
+
self._pool = None
|
|
155
|
+
return None
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
159
|
+
class AsyncPoolSessionFactory:
|
|
160
|
+
"""Base async session factory using pool acquire/release pattern.
|
|
161
|
+
|
|
162
|
+
Subclass per adapter and override ``acquire_connection``/``release_connection``
|
|
163
|
+
for adapter-specific pool acquisition and release logic.
|
|
164
|
+
"""
|
|
165
|
+
|
|
166
|
+
__slots__ = ("_config", "_connection", "_pool", "_tenant_lease")
|
|
167
|
+
|
|
168
|
+
def __init__(self, config: Any) -> None:
|
|
169
|
+
self._config = config
|
|
170
|
+
self._connection: Any = None
|
|
171
|
+
self._pool: Any = None
|
|
172
|
+
self._tenant_lease: Any = config._create_tenant_lease()
|
|
173
|
+
|
|
174
|
+
async def acquire_connection(self) -> Any:
|
|
175
|
+
if self._tenant_lease is not None:
|
|
176
|
+
return await self._tenant_lease.acquire()
|
|
177
|
+
pool = self._config.connection_instance
|
|
178
|
+
if pool is None:
|
|
179
|
+
if hasattr(self._config, "provide_pool"):
|
|
180
|
+
pool = await self._config.provide_pool()
|
|
181
|
+
else:
|
|
182
|
+
pool = await self._config.create_pool()
|
|
183
|
+
self._config.connection_instance = pool
|
|
184
|
+
self._pool = pool
|
|
185
|
+
self._connection = await pool.acquire()
|
|
186
|
+
return self._connection
|
|
187
|
+
|
|
188
|
+
async def release_connection(self, _conn: Any, **kwargs: Any) -> None:
|
|
189
|
+
if self._tenant_lease is not None:
|
|
190
|
+
await self._tenant_lease.release(_conn, **kwargs)
|
|
191
|
+
return
|
|
192
|
+
if self._connection is not None:
|
|
193
|
+
pool = self._pool or getattr(self._config, "connection_instance", None)
|
|
194
|
+
if pool is not None:
|
|
195
|
+
await pool.release(self._connection)
|
|
196
|
+
self._connection = None
|
|
197
|
+
self._pool = None
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
201
|
+
class AsyncDriverAdapterBase(CommonDriverAttributesMixin):
|
|
202
|
+
"""Base execution, transaction, Arrow, and storage adapter for asynchronous database drivers.
|
|
203
|
+
|
|
204
|
+
Provides uniform SQL compilation, parameter binding, statement caching, result mapping,
|
|
205
|
+
Apache Arrow fetching, and storage pipeline execution over asynchronous driver connections.
|
|
206
|
+
"""
|
|
207
|
+
|
|
208
|
+
__slots__ = ()
|
|
209
|
+
|
|
210
|
+
dialect: "DialectType | None" = None
|
|
211
|
+
native_arrow_export: ClassVar[bool] = False
|
|
212
|
+
export_integers_may_widen: ClassVar[bool] = False
|
|
213
|
+
|
|
214
|
+
@property
|
|
215
|
+
def is_async(self) -> bool:
|
|
216
|
+
"""Return whether the driver executes asynchronously.
|
|
217
|
+
|
|
218
|
+
Returns:
|
|
219
|
+
True for async drivers.
|
|
220
|
+
"""
|
|
221
|
+
return True
|
|
222
|
+
|
|
223
|
+
@property
|
|
224
|
+
@abstractmethod
|
|
225
|
+
def data_dictionary(self) -> "AsyncDataDictionaryBase":
|
|
226
|
+
"""Get the data dictionary for this driver.
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
Data dictionary instance for metadata queries
|
|
230
|
+
"""
|
|
231
|
+
|
|
232
|
+
async def set_migration_session_schema(self, schema: str) -> None:
|
|
233
|
+
"""Set the default schema for migration SQL when supported.
|
|
234
|
+
|
|
235
|
+
Args:
|
|
236
|
+
schema: Schema requested for the current migration session.
|
|
237
|
+
"""
|
|
238
|
+
log_with_context(logger, logging.DEBUG, "migration.schema.noop", schema=schema, driver=type(self).__name__)
|
|
239
|
+
|
|
240
|
+
async def set_migration_non_transactional_schema(self, schema: str) -> None:
|
|
241
|
+
"""Set the default schema for non-transactional migration SQL when supported.
|
|
242
|
+
|
|
243
|
+
Args:
|
|
244
|
+
schema: Schema requested for the current migration session.
|
|
245
|
+
"""
|
|
246
|
+
await self.set_migration_session_schema(schema)
|
|
247
|
+
|
|
248
|
+
async def reset_migration_session_schema(self) -> None:
|
|
249
|
+
"""Reset migration schema state after a non-transactional migration."""
|
|
250
|
+
log_with_context(logger, logging.DEBUG, "migration.schema.reset.noop", driver=type(self).__name__)
|
|
251
|
+
|
|
252
|
+
async def has_schema(self, schema: str) -> bool:
|
|
253
|
+
"""Return whether the schema exists for migration validation.
|
|
254
|
+
|
|
255
|
+
Args:
|
|
256
|
+
schema: Schema name to validate.
|
|
257
|
+
|
|
258
|
+
Returns:
|
|
259
|
+
True when the adapter does not provide schema validation.
|
|
260
|
+
"""
|
|
261
|
+
log_with_context(
|
|
262
|
+
logger, logging.DEBUG, "migration.schema.validation.noop", schema=schema, driver=type(self).__name__
|
|
263
|
+
)
|
|
264
|
+
return True
|
|
265
|
+
|
|
266
|
+
@final
|
|
267
|
+
async def dispatch_statement_execution(self, statement: "SQL", connection: "Any") -> "SQLResult":
|
|
268
|
+
"""Central execution dispatcher using the Template Method Pattern.
|
|
269
|
+
|
|
270
|
+
Args:
|
|
271
|
+
statement: The SQL statement to execute
|
|
272
|
+
connection: The database connection to use
|
|
273
|
+
|
|
274
|
+
Returns:
|
|
275
|
+
The result of the SQL execution
|
|
276
|
+
"""
|
|
277
|
+
try:
|
|
278
|
+
if connection is _CLOSED_CONNECTION:
|
|
279
|
+
raise ImproperConfigurationError(_CLOSED_CONNECTION_MESSAGE)
|
|
280
|
+
runtime = self._observability
|
|
281
|
+
if statement.is_script and (statement.positional_parameters or statement.named_parameters):
|
|
282
|
+
compiled_sql, execution_parameters = statement.raw_sql, None
|
|
283
|
+
else:
|
|
284
|
+
compiled_sql, execution_parameters = statement.compile()
|
|
285
|
+
if self._auto_begin_on_write:
|
|
286
|
+
await self._ensure_transaction_for_statement(statement)
|
|
287
|
+
result: SQLResult | None = None
|
|
288
|
+
|
|
289
|
+
if runtime is None or runtime.is_idle:
|
|
290
|
+
exc_handler = self.handle_database_exceptions()
|
|
291
|
+
if sys.exc_info()[1] is None:
|
|
292
|
+
async with exc_handler:
|
|
293
|
+
result = await self._dispatch_statement_with_cursor(
|
|
294
|
+
connection, statement, has_execution_parameters=bool(execution_parameters)
|
|
295
|
+
)
|
|
296
|
+
else:
|
|
297
|
+
result = await self._run_with_exception_handler(
|
|
298
|
+
exc_handler,
|
|
299
|
+
self._dispatch_statement_with_cursor,
|
|
300
|
+
connection,
|
|
301
|
+
statement,
|
|
302
|
+
has_execution_parameters=bool(execution_parameters),
|
|
303
|
+
)
|
|
304
|
+
self._check_pending_exception(exc_handler)
|
|
305
|
+
assert result is not None
|
|
306
|
+
return result
|
|
307
|
+
|
|
308
|
+
return await self._execute_with_observability_async(
|
|
309
|
+
compiled_sql=compiled_sql,
|
|
310
|
+
execution_parameters=execution_parameters,
|
|
311
|
+
operation="SCRIPT" if statement.is_script else statement.operation_type,
|
|
312
|
+
is_many=statement.is_many,
|
|
313
|
+
is_script=statement.is_script,
|
|
314
|
+
runner=self._dispatch_statement_observed_async,
|
|
315
|
+
connection=connection,
|
|
316
|
+
statement=statement,
|
|
317
|
+
has_execution_parameters=bool(execution_parameters),
|
|
318
|
+
)
|
|
319
|
+
finally:
|
|
320
|
+
self._release_pooled_statement(statement)
|
|
321
|
+
|
|
322
|
+
@abstractmethod
|
|
323
|
+
async def dispatch_execute(self, cursor: Any, statement: "SQL") -> ExecutionResult:
|
|
324
|
+
"""Execute a single SQL statement.
|
|
325
|
+
|
|
326
|
+
Must be implemented by each driver for database-specific execution logic.
|
|
327
|
+
|
|
328
|
+
Args:
|
|
329
|
+
cursor: Database cursor/connection object
|
|
330
|
+
statement: SQL statement object with all necessary data and configuration
|
|
331
|
+
|
|
332
|
+
Returns:
|
|
333
|
+
ExecutionResult with execution data
|
|
334
|
+
"""
|
|
335
|
+
|
|
336
|
+
@abstractmethod
|
|
337
|
+
async def dispatch_execute_many(self, cursor: Any, statement: "SQL") -> ExecutionResult:
|
|
338
|
+
"""Execute SQL with multiple parameter sets (executemany).
|
|
339
|
+
|
|
340
|
+
Must be implemented by each driver for database-specific executemany logic.
|
|
341
|
+
|
|
342
|
+
Args:
|
|
343
|
+
cursor: Database cursor/connection object
|
|
344
|
+
statement: SQL statement object with all necessary data and configuration
|
|
345
|
+
|
|
346
|
+
Returns:
|
|
347
|
+
ExecutionResult with execution data for the many operation
|
|
348
|
+
"""
|
|
349
|
+
|
|
350
|
+
async def dispatch_execute_script(self, cursor: Any, statement: "SQL") -> ExecutionResult:
|
|
351
|
+
"""Execute a SQL script containing multiple statements.
|
|
352
|
+
|
|
353
|
+
Default implementation splits the script and executes statements individually.
|
|
354
|
+
Drivers can override for database-specific script execution methods.
|
|
355
|
+
|
|
356
|
+
Args:
|
|
357
|
+
cursor: Database cursor/connection object
|
|
358
|
+
statement: SQL statement object with all necessary data and configuration
|
|
359
|
+
|
|
360
|
+
Returns:
|
|
361
|
+
ExecutionResult with script execution data including statement counts
|
|
362
|
+
"""
|
|
363
|
+
bound_statements = self._bound_script_statements(statement)
|
|
364
|
+
if bound_statements is not None:
|
|
365
|
+
return await self._dispatch_bound_script(cursor, bound_statements)
|
|
366
|
+
|
|
367
|
+
sql, prepared_parameters = self._compiled_sql(statement, self.statement_config)
|
|
368
|
+
statements = self.split_script_statements(sql, self.statement_config, strip_trailing_semicolon=True)
|
|
369
|
+
|
|
370
|
+
statement_count: int = len(statements)
|
|
371
|
+
successful_count: int = 0
|
|
372
|
+
runtime = self._observability
|
|
373
|
+
has_observers = runtime is not None and runtime.has_statement_observers
|
|
374
|
+
|
|
375
|
+
for idx, stmt in enumerate(statements):
|
|
376
|
+
single_stmt = self._sub_statement(stmt, prepared_parameters)
|
|
377
|
+
stmt_started = perf_counter() if has_observers else 0.0
|
|
378
|
+
self._pending_statement_profile = None
|
|
379
|
+
try:
|
|
380
|
+
sub_result = await self.dispatch_execute(cursor, single_stmt)
|
|
381
|
+
finally:
|
|
382
|
+
self._release_pooled_statement(single_stmt)
|
|
383
|
+
if has_observers:
|
|
384
|
+
stmt_duration = perf_counter() - stmt_started
|
|
385
|
+
stmt_profile = self._consume_statement_profile()
|
|
386
|
+
self._emit_script_statement_event(
|
|
387
|
+
sql=stmt,
|
|
388
|
+
parameters=prepared_parameters,
|
|
389
|
+
operation=single_stmt.operation_type,
|
|
390
|
+
rows_affected=sub_result.rowcount_override,
|
|
391
|
+
duration_s=stmt_duration,
|
|
392
|
+
started_at=stmt_started,
|
|
393
|
+
profile=stmt_profile,
|
|
394
|
+
script_ordinal=idx,
|
|
395
|
+
script_statement_count=statement_count,
|
|
396
|
+
)
|
|
397
|
+
successful_count += 1
|
|
398
|
+
|
|
399
|
+
self._pending_statement_profile = None
|
|
400
|
+
return self.create_execution_result(
|
|
401
|
+
cursor, statement_count=statement_count, successful_statements=successful_count, is_script_result=True
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
async def _dispatch_bound_script(self, cursor: Any, statements: "list[SQL]") -> ExecutionResult:
|
|
405
|
+
"""Execute pre-bound script statements one at a time on the same cursor."""
|
|
406
|
+
statement_count: int = len(statements)
|
|
407
|
+
successful_count: int = 0
|
|
408
|
+
runtime = self._observability
|
|
409
|
+
has_observers = runtime is not None and runtime.has_statement_observers
|
|
410
|
+
|
|
411
|
+
for idx, single_stmt in enumerate(statements):
|
|
412
|
+
stmt_started = perf_counter() if has_observers else 0.0
|
|
413
|
+
self._pending_statement_profile = None
|
|
414
|
+
try:
|
|
415
|
+
sub_result = await self.dispatch_execute(cursor, single_stmt)
|
|
416
|
+
finally:
|
|
417
|
+
self._release_pooled_statement(single_stmt)
|
|
418
|
+
if has_observers:
|
|
419
|
+
stmt_duration = perf_counter() - stmt_started
|
|
420
|
+
stmt_profile = self._consume_statement_profile()
|
|
421
|
+
compiled_sql, execution_parameters = single_stmt.compile()
|
|
422
|
+
self._emit_script_statement_event(
|
|
423
|
+
sql=compiled_sql,
|
|
424
|
+
parameters=execution_parameters,
|
|
425
|
+
operation=single_stmt.operation_type,
|
|
426
|
+
rows_affected=sub_result.rowcount_override,
|
|
427
|
+
duration_s=stmt_duration,
|
|
428
|
+
started_at=stmt_started,
|
|
429
|
+
profile=stmt_profile,
|
|
430
|
+
script_ordinal=idx,
|
|
431
|
+
script_statement_count=statement_count,
|
|
432
|
+
)
|
|
433
|
+
successful_count += 1
|
|
434
|
+
|
|
435
|
+
self._pending_statement_profile = None
|
|
436
|
+
return self.create_execution_result(
|
|
437
|
+
cursor, statement_count=statement_count, successful_statements=successful_count, is_script_result=True
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
async def dispatch_special_handling(self, cursor: Any, statement: "SQL") -> "SQLResult | None":
|
|
441
|
+
"""Hook for database-specific special operations.
|
|
442
|
+
|
|
443
|
+
This method is called first in dispatch_statement_execution() to allow drivers to handle
|
|
444
|
+
special operations that don't follow the standard SQL execution pattern.
|
|
445
|
+
|
|
446
|
+
Args:
|
|
447
|
+
cursor: Database cursor/connection object
|
|
448
|
+
statement: SQL statement to analyze
|
|
449
|
+
|
|
450
|
+
Returns:
|
|
451
|
+
SQLResult if the special operation was handled and completed,
|
|
452
|
+
None if standard execution should proceed
|
|
453
|
+
"""
|
|
454
|
+
_ = (cursor, statement)
|
|
455
|
+
return None
|
|
456
|
+
|
|
457
|
+
def collect_rows(self, cursor: Any, fetched: "list[Any]") -> "tuple[list[Any], list[str], int]":
|
|
458
|
+
"""Collect rows from cursor after fetchall for the direct execution path.
|
|
459
|
+
|
|
460
|
+
Adapters should override this method to provide optimized row collection
|
|
461
|
+
that bypasses full dispatch_execute overhead.
|
|
462
|
+
|
|
463
|
+
Args:
|
|
464
|
+
cursor: Database cursor with description metadata.
|
|
465
|
+
fetched: Rows returned from cursor.fetchall().
|
|
466
|
+
|
|
467
|
+
Returns:
|
|
468
|
+
Tuple of (data, column_names, row_count).
|
|
469
|
+
|
|
470
|
+
Raises:
|
|
471
|
+
NotImplementedError: If the adapter does not implement this method.
|
|
472
|
+
"""
|
|
473
|
+
msg = "Adapter must implement collect_rows() for direct execution path"
|
|
474
|
+
raise NotImplementedError(msg)
|
|
475
|
+
|
|
476
|
+
def resolve_rowcount(self, cursor: Any) -> int:
|
|
477
|
+
"""Resolve the number of affected rows from cursor for the direct execution path.
|
|
478
|
+
|
|
479
|
+
Adapters should override this method to provide optimized rowcount resolution
|
|
480
|
+
that bypasses full dispatch_execute overhead.
|
|
481
|
+
|
|
482
|
+
Args:
|
|
483
|
+
cursor: Database cursor with rowcount metadata.
|
|
484
|
+
|
|
485
|
+
Returns:
|
|
486
|
+
Number of affected rows, or 0 when unknown.
|
|
487
|
+
|
|
488
|
+
Raises:
|
|
489
|
+
NotImplementedError: If the adapter does not implement this method.
|
|
490
|
+
"""
|
|
491
|
+
msg = "Adapter must implement resolve_rowcount() for direct execution path"
|
|
492
|
+
raise NotImplementedError(msg)
|
|
493
|
+
|
|
494
|
+
@abstractmethod
|
|
495
|
+
async def begin(self) -> None:
|
|
496
|
+
"""Begin a database transaction on the current connection."""
|
|
497
|
+
|
|
498
|
+
@abstractmethod
|
|
499
|
+
async def commit(self) -> None:
|
|
500
|
+
"""Commit the current transaction on the current connection."""
|
|
501
|
+
|
|
502
|
+
@abstractmethod
|
|
503
|
+
async def rollback(self) -> None:
|
|
504
|
+
"""Rollback the current transaction on the current connection."""
|
|
505
|
+
|
|
506
|
+
async def create_savepoint(self, name: str) -> None:
|
|
507
|
+
"""Create a savepoint within the current transaction."""
|
|
508
|
+
await self.execute_script(f"SAVEPOINT {validate_savepoint_name(name)}")
|
|
509
|
+
|
|
510
|
+
async def release_savepoint(self, name: str) -> None:
|
|
511
|
+
"""Release a previously created savepoint."""
|
|
512
|
+
await self.execute_script(f"RELEASE SAVEPOINT {validate_savepoint_name(name)}")
|
|
513
|
+
|
|
514
|
+
async def rollback_to_savepoint(self, name: str) -> None:
|
|
515
|
+
"""Roll back the current transaction to a previously created savepoint."""
|
|
516
|
+
await self.execute_script(f"ROLLBACK TO SAVEPOINT {validate_savepoint_name(name)}")
|
|
517
|
+
|
|
518
|
+
def transaction(self) -> "_AsyncDriverTransaction[Self]":
|
|
519
|
+
"""Return a context manager that wraps a block in a transaction.
|
|
520
|
+
|
|
521
|
+
Entering the block calls ``begin()`` and yields this driver. A normal exit
|
|
522
|
+
calls ``commit()``; an exception calls ``rollback()`` and propagates. A
|
|
523
|
+
failed commit is followed by a rollback attempt before the commit error
|
|
524
|
+
propagates. When the connection already has an open transaction, the block
|
|
525
|
+
joins it instead of calling ``begin()`` and commits it on exit. Inside
|
|
526
|
+
another ``transaction()`` or service ``begin_transaction()`` block on this
|
|
527
|
+
driver, the block runs in a savepoint instead and leaves the outer
|
|
528
|
+
transaction open.
|
|
529
|
+
Isolation settings are applied with ``execute_script`` inside the block.
|
|
530
|
+
|
|
531
|
+
Example:
|
|
532
|
+
.. code-block:: python
|
|
533
|
+
|
|
534
|
+
async with session.transaction():
|
|
535
|
+
await session.execute(
|
|
536
|
+
"INSERT INTO items (id) VALUES (:id)", id=1
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
Returns:
|
|
540
|
+
A context manager yielding this driver.
|
|
541
|
+
"""
|
|
542
|
+
return _AsyncDriverTransaction(self)
|
|
543
|
+
|
|
544
|
+
@abstractmethod
|
|
545
|
+
def with_cursor(self, connection: Any) -> Any:
|
|
546
|
+
"""Create and return an async context manager for cursor acquisition and cleanup.
|
|
547
|
+
|
|
548
|
+
Returns an async context manager that yields a cursor for database operations.
|
|
549
|
+
Concrete implementations handle database-specific cursor creation and cleanup.
|
|
550
|
+
"""
|
|
551
|
+
|
|
552
|
+
@abstractmethod
|
|
553
|
+
def handle_database_exceptions(self) -> "AsyncExceptionHandler":
|
|
554
|
+
"""Return an async context manager that maps driver errors to SQLSpec exceptions.
|
|
555
|
+
|
|
556
|
+
Returns:
|
|
557
|
+
Asynchronous exception handler exposing mapped errors via ``pending_exception``.
|
|
558
|
+
"""
|
|
559
|
+
|
|
560
|
+
async def execute(
|
|
561
|
+
self,
|
|
562
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
563
|
+
/,
|
|
564
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
565
|
+
statement_config: "StatementConfig | None" = None,
|
|
566
|
+
**kwargs: Any,
|
|
567
|
+
) -> "SQLResult":
|
|
568
|
+
"""Execute a statement with parameter handling."""
|
|
569
|
+
if (
|
|
570
|
+
self._stmt_cache_enabled
|
|
571
|
+
and (statement_config is None or statement_config is self.statement_config)
|
|
572
|
+
and isinstance(statement, str)
|
|
573
|
+
):
|
|
574
|
+
fast_params = _resolve_fast_params(parameters, kwargs)
|
|
575
|
+
if fast_params is not None:
|
|
576
|
+
if self._auto_begin_on_write:
|
|
577
|
+
await self._ensure_transaction_for_cached_sql(statement, fast_params)
|
|
578
|
+
outcome = run_cached_execution(self, statement, fast_params)
|
|
579
|
+
if outcome is not None:
|
|
580
|
+
if isinstance(outcome, SQLResult):
|
|
581
|
+
return outcome
|
|
582
|
+
fast_result = await outcome
|
|
583
|
+
if fast_result is not None:
|
|
584
|
+
return fast_result
|
|
585
|
+
cached = self._stmt_cache.get(statement)
|
|
586
|
+
if cached is not None:
|
|
587
|
+
return await self._execute_cache_hit(statement, fast_params, cached)
|
|
588
|
+
return await self._execute(statement, parameters, statement_config, kwargs)
|
|
589
|
+
|
|
590
|
+
async def execute_many(
|
|
591
|
+
self,
|
|
592
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
593
|
+
/,
|
|
594
|
+
parameters: "Sequence[StatementParameters]",
|
|
595
|
+
*filters: "StatementParameters | StatementFilter",
|
|
596
|
+
statement_config: "StatementConfig | None" = None,
|
|
597
|
+
**kwargs: Any,
|
|
598
|
+
) -> "SQLResult":
|
|
599
|
+
"""Execute statement multiple times with different parameters.
|
|
600
|
+
|
|
601
|
+
Parameters passed will be used as the batch execution sequence.
|
|
602
|
+
"""
|
|
603
|
+
return await self._execute_many(statement, parameters, filters, statement_config, kwargs)
|
|
604
|
+
|
|
605
|
+
async def execute_script(
|
|
606
|
+
self,
|
|
607
|
+
statement: "str | SQL",
|
|
608
|
+
/,
|
|
609
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
610
|
+
statement_config: "StatementConfig | None" = None,
|
|
611
|
+
**kwargs: Any,
|
|
612
|
+
) -> "SQLResult":
|
|
613
|
+
"""Execute a multi-statement SQL script."""
|
|
614
|
+
return await self._execute_script(statement, parameters, statement_config, kwargs)
|
|
615
|
+
|
|
616
|
+
@overload
|
|
617
|
+
async def select(
|
|
618
|
+
self,
|
|
619
|
+
statement: "Statement | QueryBuilder",
|
|
620
|
+
/,
|
|
621
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
622
|
+
schema_type: "type[SchemaT]",
|
|
623
|
+
statement_config: "StatementConfig | None" = None,
|
|
624
|
+
**kwargs: Any,
|
|
625
|
+
) -> "list[SchemaT]": ...
|
|
626
|
+
@overload
|
|
627
|
+
async def select(
|
|
628
|
+
self,
|
|
629
|
+
statement: "Statement | QueryBuilder",
|
|
630
|
+
/,
|
|
631
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
632
|
+
schema_type: None = None,
|
|
633
|
+
statement_config: "StatementConfig | None" = None,
|
|
634
|
+
**kwargs: Any,
|
|
635
|
+
) -> "list[dict[str, Any]]": ...
|
|
636
|
+
async def select(
|
|
637
|
+
self,
|
|
638
|
+
statement: "Statement | QueryBuilder",
|
|
639
|
+
/,
|
|
640
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
641
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
642
|
+
statement_config: "StatementConfig | None" = None,
|
|
643
|
+
**kwargs: Any,
|
|
644
|
+
) -> "list[SchemaT] | list[dict[str, Any]]":
|
|
645
|
+
"""Execute a select statement and return all rows."""
|
|
646
|
+
result = await self.execute(statement, *parameters, statement_config=statement_config, **kwargs)
|
|
647
|
+
return result.get_data(schema_type=schema_type)
|
|
648
|
+
|
|
649
|
+
@overload
|
|
650
|
+
async def fetch(
|
|
651
|
+
self,
|
|
652
|
+
statement: "Statement | QueryBuilder",
|
|
653
|
+
/,
|
|
654
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
655
|
+
schema_type: "type[SchemaT]",
|
|
656
|
+
statement_config: "StatementConfig | None" = None,
|
|
657
|
+
**kwargs: Any,
|
|
658
|
+
) -> "list[SchemaT]": ...
|
|
659
|
+
@overload
|
|
660
|
+
async def fetch(
|
|
661
|
+
self,
|
|
662
|
+
statement: "Statement | QueryBuilder",
|
|
663
|
+
/,
|
|
664
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
665
|
+
schema_type: None = None,
|
|
666
|
+
statement_config: "StatementConfig | None" = None,
|
|
667
|
+
**kwargs: Any,
|
|
668
|
+
) -> "list[dict[str, Any]]": ...
|
|
669
|
+
async def fetch(
|
|
670
|
+
self,
|
|
671
|
+
statement: "Statement | QueryBuilder",
|
|
672
|
+
/,
|
|
673
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
674
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
675
|
+
statement_config: "StatementConfig | None" = None,
|
|
676
|
+
**kwargs: Any,
|
|
677
|
+
) -> "list[SchemaT] | list[dict[str, Any]]":
|
|
678
|
+
"""Execute a select statement and return all rows.
|
|
679
|
+
|
|
680
|
+
This is an alias for :meth:`select` provided for users familiar
|
|
681
|
+
with asyncpg's fetch() naming convention.
|
|
682
|
+
|
|
683
|
+
See Also:
|
|
684
|
+
select(): Primary method with identical behavior
|
|
685
|
+
"""
|
|
686
|
+
return await self.select(
|
|
687
|
+
statement, *parameters, schema_type=schema_type, statement_config=statement_config, **kwargs
|
|
688
|
+
)
|
|
689
|
+
|
|
690
|
+
@overload
|
|
691
|
+
async def select_one(
|
|
692
|
+
self,
|
|
693
|
+
statement: "Statement | QueryBuilder",
|
|
694
|
+
/,
|
|
695
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
696
|
+
schema_type: "type[SchemaT]",
|
|
697
|
+
statement_config: "StatementConfig | None" = None,
|
|
698
|
+
**kwargs: Any,
|
|
699
|
+
) -> "SchemaT": ...
|
|
700
|
+
@overload
|
|
701
|
+
async def select_one(
|
|
702
|
+
self,
|
|
703
|
+
statement: "Statement | QueryBuilder",
|
|
704
|
+
/,
|
|
705
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
706
|
+
schema_type: None = None,
|
|
707
|
+
statement_config: "StatementConfig | None" = None,
|
|
708
|
+
**kwargs: Any,
|
|
709
|
+
) -> "dict[str, Any]": ...
|
|
710
|
+
async def select_one(
|
|
711
|
+
self,
|
|
712
|
+
statement: "Statement | QueryBuilder",
|
|
713
|
+
/,
|
|
714
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
715
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
716
|
+
statement_config: "StatementConfig | None" = None,
|
|
717
|
+
**kwargs: Any,
|
|
718
|
+
) -> "SchemaT | dict[str, Any]":
|
|
719
|
+
"""Execute a select statement and return exactly one row.
|
|
720
|
+
|
|
721
|
+
Raises an exception if no rows or more than one row is returned.
|
|
722
|
+
"""
|
|
723
|
+
result = await self.execute(statement, *parameters, statement_config=statement_config, **kwargs)
|
|
724
|
+
try:
|
|
725
|
+
return result.one(schema_type=schema_type)
|
|
726
|
+
except ValueError as error:
|
|
727
|
+
handle_single_row_error(error)
|
|
728
|
+
|
|
729
|
+
@overload
|
|
730
|
+
async def fetch_one(
|
|
731
|
+
self,
|
|
732
|
+
statement: "Statement | QueryBuilder",
|
|
733
|
+
/,
|
|
734
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
735
|
+
schema_type: "type[SchemaT]",
|
|
736
|
+
statement_config: "StatementConfig | None" = None,
|
|
737
|
+
**kwargs: Any,
|
|
738
|
+
) -> "SchemaT": ...
|
|
739
|
+
@overload
|
|
740
|
+
async def fetch_one(
|
|
741
|
+
self,
|
|
742
|
+
statement: "Statement | QueryBuilder",
|
|
743
|
+
/,
|
|
744
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
745
|
+
schema_type: None = None,
|
|
746
|
+
statement_config: "StatementConfig | None" = None,
|
|
747
|
+
**kwargs: Any,
|
|
748
|
+
) -> "dict[str, Any]": ...
|
|
749
|
+
async def fetch_one(
|
|
750
|
+
self,
|
|
751
|
+
statement: "Statement | QueryBuilder",
|
|
752
|
+
/,
|
|
753
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
754
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
755
|
+
statement_config: "StatementConfig | None" = None,
|
|
756
|
+
**kwargs: Any,
|
|
757
|
+
) -> "SchemaT | dict[str, Any]":
|
|
758
|
+
"""Execute a select statement and return exactly one row.
|
|
759
|
+
|
|
760
|
+
This is an alias for :meth:`select_one` provided for users familiar
|
|
761
|
+
with asyncpg's fetch_one() naming convention.
|
|
762
|
+
|
|
763
|
+
Raises an exception if no rows or more than one row is returned.
|
|
764
|
+
|
|
765
|
+
See Also:
|
|
766
|
+
select_one(): Primary method with identical behavior
|
|
767
|
+
"""
|
|
768
|
+
return await self.select_one(
|
|
769
|
+
statement, *parameters, schema_type=schema_type, statement_config=statement_config, **kwargs
|
|
770
|
+
)
|
|
771
|
+
|
|
772
|
+
@overload
|
|
773
|
+
async def select_one_or_none(
|
|
774
|
+
self,
|
|
775
|
+
statement: "Statement | QueryBuilder",
|
|
776
|
+
/,
|
|
777
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
778
|
+
schema_type: "type[SchemaT]",
|
|
779
|
+
statement_config: "StatementConfig | None" = None,
|
|
780
|
+
**kwargs: Any,
|
|
781
|
+
) -> "SchemaT | None": ...
|
|
782
|
+
@overload
|
|
783
|
+
async def select_one_or_none(
|
|
784
|
+
self,
|
|
785
|
+
statement: "Statement | QueryBuilder",
|
|
786
|
+
/,
|
|
787
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
788
|
+
schema_type: None = None,
|
|
789
|
+
statement_config: "StatementConfig | None" = None,
|
|
790
|
+
**kwargs: Any,
|
|
791
|
+
) -> "dict[str, Any] | None": ...
|
|
792
|
+
async def select_one_or_none(
|
|
793
|
+
self,
|
|
794
|
+
statement: "Statement | QueryBuilder",
|
|
795
|
+
/,
|
|
796
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
797
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
798
|
+
statement_config: "StatementConfig | None" = None,
|
|
799
|
+
**kwargs: Any,
|
|
800
|
+
) -> "SchemaT | dict[str, Any] | None":
|
|
801
|
+
"""Execute a select statement and return at most one row.
|
|
802
|
+
|
|
803
|
+
Returns None if no rows are found. Raises
|
|
804
|
+
:class:`~sqlspec.exceptions.MultipleResultsFoundError` if more than one row
|
|
805
|
+
is returned. Any database or SQL execution errors raised by the driver are
|
|
806
|
+
propagated unchanged.
|
|
807
|
+
"""
|
|
808
|
+
result = await self.execute(statement, *parameters, statement_config=statement_config, **kwargs)
|
|
809
|
+
return result.one_or_none(schema_type=schema_type)
|
|
810
|
+
|
|
811
|
+
@overload
|
|
812
|
+
async def fetch_one_or_none(
|
|
813
|
+
self,
|
|
814
|
+
statement: "Statement | QueryBuilder",
|
|
815
|
+
/,
|
|
816
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
817
|
+
schema_type: "type[SchemaT]",
|
|
818
|
+
statement_config: "StatementConfig | None" = None,
|
|
819
|
+
**kwargs: Any,
|
|
820
|
+
) -> "SchemaT | None": ...
|
|
821
|
+
@overload
|
|
822
|
+
async def fetch_one_or_none(
|
|
823
|
+
self,
|
|
824
|
+
statement: "Statement | QueryBuilder",
|
|
825
|
+
/,
|
|
826
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
827
|
+
schema_type: None = None,
|
|
828
|
+
statement_config: "StatementConfig | None" = None,
|
|
829
|
+
**kwargs: Any,
|
|
830
|
+
) -> "dict[str, Any] | None": ...
|
|
831
|
+
async def fetch_one_or_none(
|
|
832
|
+
self,
|
|
833
|
+
statement: "Statement | QueryBuilder",
|
|
834
|
+
/,
|
|
835
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
836
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
837
|
+
statement_config: "StatementConfig | None" = None,
|
|
838
|
+
**kwargs: Any,
|
|
839
|
+
) -> "SchemaT | dict[str, Any] | None":
|
|
840
|
+
"""Execute a select statement and return at most one row.
|
|
841
|
+
|
|
842
|
+
This is an alias for :meth:`select_one_or_none` provided for users familiar
|
|
843
|
+
with asyncpg's fetch_one_or_none() naming convention.
|
|
844
|
+
|
|
845
|
+
Returns None if no rows are found.
|
|
846
|
+
Raises an exception if more than one row is returned.
|
|
847
|
+
|
|
848
|
+
See Also:
|
|
849
|
+
select_one_or_none(): Primary method with identical behavior
|
|
850
|
+
"""
|
|
851
|
+
return await self.select_one_or_none(
|
|
852
|
+
statement, *parameters, schema_type=schema_type, statement_config=statement_config, **kwargs
|
|
853
|
+
)
|
|
854
|
+
|
|
855
|
+
@overload
|
|
856
|
+
async def select_value(
|
|
857
|
+
self,
|
|
858
|
+
statement: "Statement | QueryBuilder",
|
|
859
|
+
/,
|
|
860
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
861
|
+
value_type: "type[ValueT]",
|
|
862
|
+
statement_config: "StatementConfig | None" = None,
|
|
863
|
+
**kwargs: Any,
|
|
864
|
+
) -> "ValueT": ...
|
|
865
|
+
@overload
|
|
866
|
+
async def select_value(
|
|
867
|
+
self,
|
|
868
|
+
statement: "Statement | QueryBuilder",
|
|
869
|
+
/,
|
|
870
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
871
|
+
value_type: None = None,
|
|
872
|
+
statement_config: "StatementConfig | None" = None,
|
|
873
|
+
**kwargs: Any,
|
|
874
|
+
) -> Any: ...
|
|
875
|
+
async def select_value(
|
|
876
|
+
self,
|
|
877
|
+
statement: "Statement | QueryBuilder",
|
|
878
|
+
/,
|
|
879
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
880
|
+
value_type: "type[ValueT] | None" = None,
|
|
881
|
+
statement_config: "StatementConfig | None" = None,
|
|
882
|
+
**kwargs: Any,
|
|
883
|
+
) -> "ValueT | Any":
|
|
884
|
+
"""Execute a select statement and return a single scalar value.
|
|
885
|
+
|
|
886
|
+
Expects exactly one row with one column.
|
|
887
|
+
Raises an exception if no rows or more than one row/column is returned.
|
|
888
|
+
|
|
889
|
+
Args:
|
|
890
|
+
statement: SQL statement or query builder to execute.
|
|
891
|
+
*parameters: Positional parameters for the statement.
|
|
892
|
+
value_type: Optional type to convert the result to. When provided,
|
|
893
|
+
the return value is converted to this type and the return type
|
|
894
|
+
is narrowed for type checkers. Supports int, float, str, bool,
|
|
895
|
+
datetime, date, time, Decimal, UUID, Path, dict, and list.
|
|
896
|
+
statement_config: Optional statement configuration.
|
|
897
|
+
**kwargs: Additional keyword arguments.
|
|
898
|
+
|
|
899
|
+
Returns:
|
|
900
|
+
The scalar value, optionally converted to the specified type
|
|
901
|
+
"""
|
|
902
|
+
result = await self.execute(statement, *parameters, statement_config=statement_config, **kwargs)
|
|
903
|
+
try:
|
|
904
|
+
value = result.scalar()
|
|
905
|
+
except ValueError as error:
|
|
906
|
+
handle_single_row_error(error)
|
|
907
|
+
|
|
908
|
+
if value_type is not None:
|
|
909
|
+
return to_value_type(value, value_type)
|
|
910
|
+
return value
|
|
911
|
+
|
|
912
|
+
@overload
|
|
913
|
+
async def fetch_value(
|
|
914
|
+
self,
|
|
915
|
+
statement: "Statement | QueryBuilder",
|
|
916
|
+
/,
|
|
917
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
918
|
+
value_type: "type[ValueT]",
|
|
919
|
+
statement_config: "StatementConfig | None" = None,
|
|
920
|
+
**kwargs: Any,
|
|
921
|
+
) -> "ValueT": ...
|
|
922
|
+
@overload
|
|
923
|
+
async def fetch_value(
|
|
924
|
+
self,
|
|
925
|
+
statement: "Statement | QueryBuilder",
|
|
926
|
+
/,
|
|
927
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
928
|
+
value_type: None = None,
|
|
929
|
+
statement_config: "StatementConfig | None" = None,
|
|
930
|
+
**kwargs: Any,
|
|
931
|
+
) -> Any: ...
|
|
932
|
+
async def fetch_value(
|
|
933
|
+
self,
|
|
934
|
+
statement: "Statement | QueryBuilder",
|
|
935
|
+
/,
|
|
936
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
937
|
+
value_type: "type[ValueT] | None" = None,
|
|
938
|
+
statement_config: "StatementConfig | None" = None,
|
|
939
|
+
**kwargs: Any,
|
|
940
|
+
) -> "ValueT | Any":
|
|
941
|
+
"""Execute a select statement and return a single scalar value.
|
|
942
|
+
|
|
943
|
+
This is an alias for :meth:`select_value` provided for users familiar
|
|
944
|
+
with asyncpg's fetch_value() naming convention.
|
|
945
|
+
|
|
946
|
+
Expects exactly one row with one column.
|
|
947
|
+
Raises an exception if no rows or more than one row/column is returned.
|
|
948
|
+
|
|
949
|
+
See Also:
|
|
950
|
+
select_value(): Primary method with identical behavior
|
|
951
|
+
"""
|
|
952
|
+
return await self.select_value(
|
|
953
|
+
statement, *parameters, value_type=value_type, statement_config=statement_config, **kwargs
|
|
954
|
+
)
|
|
955
|
+
|
|
956
|
+
@overload
|
|
957
|
+
async def select_value_or_none(
|
|
958
|
+
self,
|
|
959
|
+
statement: "Statement | QueryBuilder",
|
|
960
|
+
/,
|
|
961
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
962
|
+
value_type: "type[ValueT]",
|
|
963
|
+
statement_config: "StatementConfig | None" = None,
|
|
964
|
+
**kwargs: Any,
|
|
965
|
+
) -> "ValueT | None": ...
|
|
966
|
+
@overload
|
|
967
|
+
async def select_value_or_none(
|
|
968
|
+
self,
|
|
969
|
+
statement: "Statement | QueryBuilder",
|
|
970
|
+
/,
|
|
971
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
972
|
+
value_type: None = None,
|
|
973
|
+
statement_config: "StatementConfig | None" = None,
|
|
974
|
+
**kwargs: Any,
|
|
975
|
+
) -> Any: ...
|
|
976
|
+
async def select_value_or_none(
|
|
977
|
+
self,
|
|
978
|
+
statement: "Statement | QueryBuilder",
|
|
979
|
+
/,
|
|
980
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
981
|
+
value_type: "type[ValueT] | None" = None,
|
|
982
|
+
statement_config: "StatementConfig | None" = None,
|
|
983
|
+
**kwargs: Any,
|
|
984
|
+
) -> "ValueT | Any | None":
|
|
985
|
+
"""Execute a select statement and return a single scalar value or None.
|
|
986
|
+
|
|
987
|
+
Returns None if no rows are found.
|
|
988
|
+
Expects at most one row with one column.
|
|
989
|
+
Raises an exception if more than one row is returned.
|
|
990
|
+
|
|
991
|
+
Args:
|
|
992
|
+
statement: SQL statement or query builder to execute.
|
|
993
|
+
*parameters: Positional parameters for the statement.
|
|
994
|
+
value_type: Optional type to convert the result to. When provided,
|
|
995
|
+
the return value is converted to this type and the return type
|
|
996
|
+
is narrowed to ``T | None`` for type checkers. Supports int, float,
|
|
997
|
+
str, bool, datetime, date, time, Decimal, UUID, Path, dict, and list.
|
|
998
|
+
statement_config: Optional statement configuration.
|
|
999
|
+
**kwargs: Additional keyword arguments.
|
|
1000
|
+
|
|
1001
|
+
Returns:
|
|
1002
|
+
The scalar value (optionally converted), or None if no rows found.
|
|
1003
|
+
"""
|
|
1004
|
+
result = await self.execute(statement, *parameters, statement_config=statement_config, **kwargs)
|
|
1005
|
+
value = result.scalar_or_none()
|
|
1006
|
+
|
|
1007
|
+
if value is None:
|
|
1008
|
+
return None
|
|
1009
|
+
if value_type is not None:
|
|
1010
|
+
return to_value_type(value, value_type)
|
|
1011
|
+
return value
|
|
1012
|
+
|
|
1013
|
+
@overload
|
|
1014
|
+
async def fetch_value_or_none(
|
|
1015
|
+
self,
|
|
1016
|
+
statement: "Statement | QueryBuilder",
|
|
1017
|
+
/,
|
|
1018
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1019
|
+
value_type: "type[ValueT]",
|
|
1020
|
+
statement_config: "StatementConfig | None" = None,
|
|
1021
|
+
**kwargs: Any,
|
|
1022
|
+
) -> "ValueT | None": ...
|
|
1023
|
+
@overload
|
|
1024
|
+
async def fetch_value_or_none(
|
|
1025
|
+
self,
|
|
1026
|
+
statement: "Statement | QueryBuilder",
|
|
1027
|
+
/,
|
|
1028
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1029
|
+
value_type: None = None,
|
|
1030
|
+
statement_config: "StatementConfig | None" = None,
|
|
1031
|
+
**kwargs: Any,
|
|
1032
|
+
) -> Any: ...
|
|
1033
|
+
async def fetch_value_or_none(
|
|
1034
|
+
self,
|
|
1035
|
+
statement: "Statement | QueryBuilder",
|
|
1036
|
+
/,
|
|
1037
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1038
|
+
value_type: "type[ValueT] | None" = None,
|
|
1039
|
+
statement_config: "StatementConfig | None" = None,
|
|
1040
|
+
**kwargs: Any,
|
|
1041
|
+
) -> "ValueT | Any | None":
|
|
1042
|
+
"""Execute a select statement and return a single scalar value or None.
|
|
1043
|
+
|
|
1044
|
+
This is an alias for :meth:`select_value_or_none` provided for users familiar
|
|
1045
|
+
with asyncpg's fetch_value_or_none() naming convention.
|
|
1046
|
+
|
|
1047
|
+
Returns None if no rows are found.
|
|
1048
|
+
Expects at most one row with one column.
|
|
1049
|
+
Raises an exception if more than one row is returned.
|
|
1050
|
+
|
|
1051
|
+
See Also:
|
|
1052
|
+
select_value_or_none(): Primary method with identical behavior
|
|
1053
|
+
"""
|
|
1054
|
+
return await self.select_value_or_none(
|
|
1055
|
+
statement, *parameters, value_type=value_type, statement_config=statement_config, **kwargs
|
|
1056
|
+
)
|
|
1057
|
+
|
|
1058
|
+
@overload
|
|
1059
|
+
async def select_with_total(
|
|
1060
|
+
self,
|
|
1061
|
+
statement: "Statement | QueryBuilder",
|
|
1062
|
+
/,
|
|
1063
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1064
|
+
schema_type: "type[SchemaT]",
|
|
1065
|
+
statement_config: "StatementConfig | None" = None,
|
|
1066
|
+
count_with_window: bool = False,
|
|
1067
|
+
**kwargs: Any,
|
|
1068
|
+
) -> "tuple[list[SchemaT], int]": ...
|
|
1069
|
+
@overload
|
|
1070
|
+
async def select_with_total(
|
|
1071
|
+
self,
|
|
1072
|
+
statement: "Statement | QueryBuilder",
|
|
1073
|
+
/,
|
|
1074
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1075
|
+
schema_type: None = None,
|
|
1076
|
+
statement_config: "StatementConfig | None" = None,
|
|
1077
|
+
count_with_window: bool = False,
|
|
1078
|
+
**kwargs: Any,
|
|
1079
|
+
) -> "tuple[list[dict[str, Any]], int]": ...
|
|
1080
|
+
async def select_with_total(
|
|
1081
|
+
self,
|
|
1082
|
+
statement: "Statement | QueryBuilder",
|
|
1083
|
+
/,
|
|
1084
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1085
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
1086
|
+
statement_config: "StatementConfig | None" = None,
|
|
1087
|
+
count_with_window: bool = False,
|
|
1088
|
+
**kwargs: Any,
|
|
1089
|
+
) -> "tuple[list[SchemaT] | list[dict[str, Any]], int]":
|
|
1090
|
+
"""Execute a select statement and return both the data and total count.
|
|
1091
|
+
|
|
1092
|
+
This method is designed for pagination scenarios where you need both
|
|
1093
|
+
the current page of data and the total number of rows that match the query.
|
|
1094
|
+
|
|
1095
|
+
Args:
|
|
1096
|
+
statement: The SQL statement, QueryBuilder, or raw SQL string
|
|
1097
|
+
*parameters: Parameters for the SQL statement
|
|
1098
|
+
schema_type: Optional schema type for data transformation
|
|
1099
|
+
statement_config: Optional SQL configuration
|
|
1100
|
+
count_with_window: If True, use a single query with COUNT(*) OVER() window
|
|
1101
|
+
function instead of two separate queries. This can be more efficient
|
|
1102
|
+
for some databases but adds a column to each row. Default False.
|
|
1103
|
+
**kwargs: Additional keyword arguments
|
|
1104
|
+
|
|
1105
|
+
Returns:
|
|
1106
|
+
A tuple containing:
|
|
1107
|
+
- List of data rows (transformed by schema_type if provided)
|
|
1108
|
+
- Total count of rows matching the query (ignoring LIMIT/OFFSET)
|
|
1109
|
+
"""
|
|
1110
|
+
sql_statement = self.prepare_statement(
|
|
1111
|
+
statement, parameters, statement_config=statement_config or self.statement_config, kwargs=kwargs
|
|
1112
|
+
)
|
|
1113
|
+
|
|
1114
|
+
if count_with_window:
|
|
1115
|
+
modified_sql = self._with_total_count(sql_statement)
|
|
1116
|
+
result = await self.execute(modified_sql)
|
|
1117
|
+
rows = result.all()
|
|
1118
|
+
data, total = self._extract_total_from_rows(rows)
|
|
1119
|
+
|
|
1120
|
+
if schema_type is not None:
|
|
1121
|
+
return (cast("list[SchemaT]", self.to_schema(data, schema_type=schema_type)), total)
|
|
1122
|
+
return (data, total)
|
|
1123
|
+
|
|
1124
|
+
count_result = await self.execute(self._count_query(sql_statement))
|
|
1125
|
+
select_result = await self.execute(sql_statement)
|
|
1126
|
+
|
|
1127
|
+
return (select_result.get_data(schema_type=schema_type), count_result.scalar())
|
|
1128
|
+
|
|
1129
|
+
@overload
|
|
1130
|
+
async def fetch_with_total(
|
|
1131
|
+
self,
|
|
1132
|
+
statement: "Statement | QueryBuilder",
|
|
1133
|
+
/,
|
|
1134
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1135
|
+
schema_type: "type[SchemaT]",
|
|
1136
|
+
statement_config: "StatementConfig | None" = None,
|
|
1137
|
+
count_with_window: bool = False,
|
|
1138
|
+
**kwargs: Any,
|
|
1139
|
+
) -> "tuple[list[SchemaT], int]": ...
|
|
1140
|
+
@overload
|
|
1141
|
+
async def fetch_with_total(
|
|
1142
|
+
self,
|
|
1143
|
+
statement: "Statement | QueryBuilder",
|
|
1144
|
+
/,
|
|
1145
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1146
|
+
schema_type: None = None,
|
|
1147
|
+
statement_config: "StatementConfig | None" = None,
|
|
1148
|
+
count_with_window: bool = False,
|
|
1149
|
+
**kwargs: Any,
|
|
1150
|
+
) -> "tuple[list[dict[str, Any]], int]": ...
|
|
1151
|
+
async def fetch_with_total(
|
|
1152
|
+
self,
|
|
1153
|
+
statement: "Statement | QueryBuilder",
|
|
1154
|
+
/,
|
|
1155
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1156
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
1157
|
+
statement_config: "StatementConfig | None" = None,
|
|
1158
|
+
count_with_window: bool = False,
|
|
1159
|
+
**kwargs: Any,
|
|
1160
|
+
) -> "tuple[list[SchemaT] | list[dict[str, Any]], int]":
|
|
1161
|
+
"""Execute a select statement and return both the data and total count.
|
|
1162
|
+
|
|
1163
|
+
This is an alias for :meth:`select_with_total` provided for users familiar
|
|
1164
|
+
with asyncpg's fetch() naming convention.
|
|
1165
|
+
|
|
1166
|
+
This method is designed for pagination scenarios where you need both
|
|
1167
|
+
the current page of data and the total number of rows that match the query.
|
|
1168
|
+
|
|
1169
|
+
See Also:
|
|
1170
|
+
select_with_total(): Primary method with identical behavior and full documentation
|
|
1171
|
+
"""
|
|
1172
|
+
return await self.select_with_total(
|
|
1173
|
+
statement,
|
|
1174
|
+
*parameters,
|
|
1175
|
+
schema_type=schema_type,
|
|
1176
|
+
statement_config=statement_config,
|
|
1177
|
+
count_with_window=count_with_window,
|
|
1178
|
+
**kwargs,
|
|
1179
|
+
)
|
|
1180
|
+
|
|
1181
|
+
async def select_to_arrow(
|
|
1182
|
+
self,
|
|
1183
|
+
statement: "Statement | QueryBuilder",
|
|
1184
|
+
/,
|
|
1185
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1186
|
+
statement_config: "StatementConfig | None" = None,
|
|
1187
|
+
return_format: "ArrowReturnFormat" = "table",
|
|
1188
|
+
native_only: bool = False,
|
|
1189
|
+
batch_size: int | None = None,
|
|
1190
|
+
arrow_schema: Any = None,
|
|
1191
|
+
**kwargs: Any,
|
|
1192
|
+
) -> "ArrowResult":
|
|
1193
|
+
"""Execute query and return results as Apache Arrow format (async).
|
|
1194
|
+
|
|
1195
|
+
This base implementation uses the conversion path: execute() → dict → Arrow.
|
|
1196
|
+
Adapters with native Arrow support (ADBC, DuckDB, BigQuery) override this
|
|
1197
|
+
method to use zero-copy native paths for 5-10x performance improvement.
|
|
1198
|
+
|
|
1199
|
+
Args:
|
|
1200
|
+
statement: SQL query string, Statement, or QueryBuilder
|
|
1201
|
+
*parameters: Query parameters (same format as execute()/select())
|
|
1202
|
+
statement_config: Optional statement configuration override
|
|
1203
|
+
return_format: "table" for pyarrow.Table (default), "batch" for single RecordBatch,
|
|
1204
|
+
"batches" for iterator of RecordBatches, "reader" for RecordBatchReader
|
|
1205
|
+
native_only: If True, raise error if native Arrow unavailable (default: False)
|
|
1206
|
+
batch_size: Rows per batch for "batch"/"batches" format (default: None = all rows)
|
|
1207
|
+
arrow_schema: Optional pyarrow.Schema for type casting
|
|
1208
|
+
**kwargs: Additional keyword arguments
|
|
1209
|
+
|
|
1210
|
+
Returns:
|
|
1211
|
+
ArrowResult containing pyarrow.Table, RecordBatchReader, or RecordBatches
|
|
1212
|
+
|
|
1213
|
+
Raises:
|
|
1214
|
+
ImproperConfigurationError: If native_only=True and adapter doesn't support native Arrow
|
|
1215
|
+
"""
|
|
1216
|
+
if native_only:
|
|
1217
|
+
msg = (
|
|
1218
|
+
f"Adapter '{self.__class__.__name__}' does not support native Arrow results. "
|
|
1219
|
+
f"Use native_only=False to allow conversion path, or switch to an adapter "
|
|
1220
|
+
f"with native Arrow support (ADBC, DuckDB, BigQuery)."
|
|
1221
|
+
)
|
|
1222
|
+
raise ImproperConfigurationError(msg)
|
|
1223
|
+
|
|
1224
|
+
result = await self.execute(statement, *parameters, statement_config=statement_config, **kwargs)
|
|
1225
|
+
|
|
1226
|
+
arrow_data = convert_dict_to_arrow_with_schema(
|
|
1227
|
+
result.get_data(),
|
|
1228
|
+
return_format=return_format,
|
|
1229
|
+
batch_size=batch_size,
|
|
1230
|
+
arrow_schema=arrow_schema,
|
|
1231
|
+
column_types=result.get_metadata("column_types"),
|
|
1232
|
+
column_names=result.column_names,
|
|
1233
|
+
)
|
|
1234
|
+
return create_arrow_result(
|
|
1235
|
+
statement=result.statement,
|
|
1236
|
+
data=arrow_data,
|
|
1237
|
+
rows_affected=result.rows_affected,
|
|
1238
|
+
last_inserted_id=result.last_inserted_id,
|
|
1239
|
+
execution_time=result.execution_time,
|
|
1240
|
+
metadata=result.metadata,
|
|
1241
|
+
)
|
|
1242
|
+
|
|
1243
|
+
async def fetch_to_arrow(
|
|
1244
|
+
self,
|
|
1245
|
+
statement: "Statement | QueryBuilder",
|
|
1246
|
+
/,
|
|
1247
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1248
|
+
statement_config: "StatementConfig | None" = None,
|
|
1249
|
+
return_format: "ArrowReturnFormat" = "table",
|
|
1250
|
+
native_only: bool = False,
|
|
1251
|
+
batch_size: int | None = None,
|
|
1252
|
+
arrow_schema: Any = None,
|
|
1253
|
+
**kwargs: Any,
|
|
1254
|
+
) -> "ArrowResult":
|
|
1255
|
+
"""Execute query and return results as Apache Arrow format (async).
|
|
1256
|
+
|
|
1257
|
+
This is an alias for :meth:`select_to_arrow` provided for users familiar
|
|
1258
|
+
with asyncpg's fetch() naming convention.
|
|
1259
|
+
|
|
1260
|
+
See Also:
|
|
1261
|
+
select_to_arrow(): Primary method with identical behavior and full documentation
|
|
1262
|
+
"""
|
|
1263
|
+
return await self.select_to_arrow(
|
|
1264
|
+
statement,
|
|
1265
|
+
*parameters,
|
|
1266
|
+
statement_config=statement_config,
|
|
1267
|
+
return_format=return_format,
|
|
1268
|
+
native_only=native_only,
|
|
1269
|
+
batch_size=batch_size,
|
|
1270
|
+
arrow_schema=arrow_schema,
|
|
1271
|
+
**kwargs,
|
|
1272
|
+
)
|
|
1273
|
+
|
|
1274
|
+
@overload
|
|
1275
|
+
def select_stream(
|
|
1276
|
+
self,
|
|
1277
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1278
|
+
/,
|
|
1279
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1280
|
+
schema_type: "type[SchemaT]",
|
|
1281
|
+
statement_config: "StatementConfig | None" = None,
|
|
1282
|
+
chunk_size: int = 1000,
|
|
1283
|
+
native_only: bool = False,
|
|
1284
|
+
**kwargs: Any,
|
|
1285
|
+
) -> "AsyncRowStream[SchemaT]": ...
|
|
1286
|
+
@overload
|
|
1287
|
+
def select_stream(
|
|
1288
|
+
self,
|
|
1289
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1290
|
+
/,
|
|
1291
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1292
|
+
schema_type: None = None,
|
|
1293
|
+
statement_config: "StatementConfig | None" = None,
|
|
1294
|
+
chunk_size: int = 1000,
|
|
1295
|
+
native_only: bool = False,
|
|
1296
|
+
**kwargs: Any,
|
|
1297
|
+
) -> "AsyncRowStream[dict[str, Any]]": ...
|
|
1298
|
+
def select_stream(
|
|
1299
|
+
self,
|
|
1300
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1301
|
+
/,
|
|
1302
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1303
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
1304
|
+
statement_config: "StatementConfig | None" = None,
|
|
1305
|
+
chunk_size: int = 1000,
|
|
1306
|
+
native_only: bool = False,
|
|
1307
|
+
**kwargs: Any,
|
|
1308
|
+
) -> "AsyncRowStream[SchemaT] | AsyncRowStream[dict[str, Any]]":
|
|
1309
|
+
"""Execute a query and stream rows in chunks."""
|
|
1310
|
+
if chunk_size < 1:
|
|
1311
|
+
msg = "chunk_size must be greater than or equal to 1"
|
|
1312
|
+
raise ValueError(msg)
|
|
1313
|
+
sql_statement = self.prepare_statement(
|
|
1314
|
+
statement, parameters, statement_config=statement_config or self.statement_config, kwargs=kwargs
|
|
1315
|
+
)
|
|
1316
|
+
stream = self.dispatch_select_stream(sql_statement, chunk_size)
|
|
1317
|
+
if stream is not None:
|
|
1318
|
+
return self._register_open_stream(stream._with_schema_type(schema_type))
|
|
1319
|
+
if native_only:
|
|
1320
|
+
msg = (
|
|
1321
|
+
f"Adapter '{type(self).__name__}' does not support native row streaming. "
|
|
1322
|
+
"Use native_only=False to allow eager fallback (not bounded-memory), "
|
|
1323
|
+
"or switch to an adapter with native row streaming support."
|
|
1324
|
+
)
|
|
1325
|
+
raise ImproperConfigurationError(msg)
|
|
1326
|
+
return self._register_open_stream(
|
|
1327
|
+
AsyncRowStream(_LazyEagerAsyncRowSource(self, sql_statement, chunk_size), schema_type=schema_type)
|
|
1328
|
+
)
|
|
1329
|
+
|
|
1330
|
+
@overload
|
|
1331
|
+
def fetch_stream(
|
|
1332
|
+
self,
|
|
1333
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1334
|
+
/,
|
|
1335
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1336
|
+
schema_type: "type[SchemaT]",
|
|
1337
|
+
statement_config: "StatementConfig | None" = None,
|
|
1338
|
+
chunk_size: int = 1000,
|
|
1339
|
+
native_only: bool = False,
|
|
1340
|
+
**kwargs: Any,
|
|
1341
|
+
) -> "AsyncRowStream[SchemaT]": ...
|
|
1342
|
+
@overload
|
|
1343
|
+
def fetch_stream(
|
|
1344
|
+
self,
|
|
1345
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1346
|
+
/,
|
|
1347
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1348
|
+
schema_type: None = None,
|
|
1349
|
+
statement_config: "StatementConfig | None" = None,
|
|
1350
|
+
chunk_size: int = 1000,
|
|
1351
|
+
native_only: bool = False,
|
|
1352
|
+
**kwargs: Any,
|
|
1353
|
+
) -> "AsyncRowStream[dict[str, Any]]": ...
|
|
1354
|
+
def fetch_stream(
|
|
1355
|
+
self,
|
|
1356
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1357
|
+
/,
|
|
1358
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1359
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
1360
|
+
statement_config: "StatementConfig | None" = None,
|
|
1361
|
+
chunk_size: int = 1000,
|
|
1362
|
+
native_only: bool = False,
|
|
1363
|
+
**kwargs: Any,
|
|
1364
|
+
) -> "AsyncRowStream[SchemaT] | AsyncRowStream[dict[str, Any]]":
|
|
1365
|
+
"""Execute a query and stream rows in chunks.
|
|
1366
|
+
|
|
1367
|
+
This is an alias for :meth:`select_stream` provided for users familiar
|
|
1368
|
+
with asyncpg's fetch() naming convention.
|
|
1369
|
+
|
|
1370
|
+
See Also:
|
|
1371
|
+
select_stream(): Primary method with identical behavior and full documentation
|
|
1372
|
+
"""
|
|
1373
|
+
return self.select_stream(
|
|
1374
|
+
statement,
|
|
1375
|
+
*parameters,
|
|
1376
|
+
schema_type=schema_type,
|
|
1377
|
+
statement_config=statement_config,
|
|
1378
|
+
chunk_size=chunk_size,
|
|
1379
|
+
native_only=native_only,
|
|
1380
|
+
**kwargs,
|
|
1381
|
+
)
|
|
1382
|
+
|
|
1383
|
+
async def _close_open_streams(self, *, error: bool = False) -> None:
|
|
1384
|
+
"""Close every registered row stream before the session releases its connection.
|
|
1385
|
+
|
|
1386
|
+
Every stream is closed even when an earlier close raises; the first such error is then re-raised.
|
|
1387
|
+
|
|
1388
|
+
Args:
|
|
1389
|
+
error: Whether the session is ending because of an error.
|
|
1390
|
+
"""
|
|
1391
|
+
open_streams = self._open_streams
|
|
1392
|
+
self._open_streams = []
|
|
1393
|
+
first_error: BaseException | None = None
|
|
1394
|
+
for open_stream in open_streams:
|
|
1395
|
+
try:
|
|
1396
|
+
await open_stream._aclose_for_session_exit(error=error)
|
|
1397
|
+
except BaseException as exc:
|
|
1398
|
+
if first_error is None:
|
|
1399
|
+
first_error = exc
|
|
1400
|
+
if first_error is not None:
|
|
1401
|
+
raise first_error
|
|
1402
|
+
|
|
1403
|
+
def dispatch_select_stream(self, statement: "SQL", chunk_size: int) -> "AsyncRowStream[dict[str, Any]] | None":
|
|
1404
|
+
"""Adapter hook returning a native row stream, or None when unsupported."""
|
|
1405
|
+
_ = (statement, chunk_size)
|
|
1406
|
+
return None
|
|
1407
|
+
|
|
1408
|
+
async def execute_stack(
|
|
1409
|
+
self, stack: "StatementStack", *, continue_on_error: bool = False
|
|
1410
|
+
) -> "tuple[StackResult, ...]":
|
|
1411
|
+
"""Execute a StatementStack sequentially using the adapter's primitives."""
|
|
1412
|
+
if not isinstance(stack, StatementStack):
|
|
1413
|
+
msg = "execute_stack expects a StatementStack instance"
|
|
1414
|
+
raise TypeError(msg)
|
|
1415
|
+
if not stack:
|
|
1416
|
+
msg = "Cannot execute an empty StatementStack"
|
|
1417
|
+
raise ValueError(msg)
|
|
1418
|
+
|
|
1419
|
+
results: list[StackResult] = []
|
|
1420
|
+
single_transaction = not continue_on_error
|
|
1421
|
+
|
|
1422
|
+
with StackExecutionObserver(self, stack, continue_on_error, native_pipeline=False) as observer:
|
|
1423
|
+
started_transaction = False
|
|
1424
|
+
try:
|
|
1425
|
+
caller_in_transaction = self._connection_in_transaction()
|
|
1426
|
+
except NotImplementedError:
|
|
1427
|
+
caller_in_transaction = False
|
|
1428
|
+
|
|
1429
|
+
stack_failure: Exception | None = None
|
|
1430
|
+
try:
|
|
1431
|
+
if single_transaction and not caller_in_transaction:
|
|
1432
|
+
await self.begin()
|
|
1433
|
+
started_transaction = True
|
|
1434
|
+
|
|
1435
|
+
for index, operation in enumerate(stack.operations):
|
|
1436
|
+
operation_error: Exception | None = None
|
|
1437
|
+
result: SQLResult | ArrowResult | None = None
|
|
1438
|
+
try:
|
|
1439
|
+
result = await self._execute_stack_operation(operation)
|
|
1440
|
+
except Exception as exc: # pragma: no cover
|
|
1441
|
+
operation_error = exc
|
|
1442
|
+
if operation_error is not None:
|
|
1443
|
+
stack_error = StackExecutionError(
|
|
1444
|
+
index,
|
|
1445
|
+
describe_stack_statement(operation.statement),
|
|
1446
|
+
operation_error,
|
|
1447
|
+
adapter=type(self).__name__,
|
|
1448
|
+
mode="continue-on-error" if continue_on_error else "fail-fast",
|
|
1449
|
+
)
|
|
1450
|
+
|
|
1451
|
+
if started_transaction and not continue_on_error:
|
|
1452
|
+
try:
|
|
1453
|
+
await self.rollback()
|
|
1454
|
+
except Exception as rollback_error: # pragma: no cover
|
|
1455
|
+
logger.debug("Rollback after stack failure failed: %s", rollback_error)
|
|
1456
|
+
started_transaction = False
|
|
1457
|
+
|
|
1458
|
+
if continue_on_error:
|
|
1459
|
+
if not caller_in_transaction:
|
|
1460
|
+
await self._rollback_failed_stack()
|
|
1461
|
+
observer.record_operation_error(stack_error)
|
|
1462
|
+
results.append(StackResult.from_error(stack_error))
|
|
1463
|
+
continue
|
|
1464
|
+
|
|
1465
|
+
stack_error.__cause__ = operation_error
|
|
1466
|
+
stack_failure = stack_error
|
|
1467
|
+
break
|
|
1468
|
+
|
|
1469
|
+
results.append(StackResult(result=result))
|
|
1470
|
+
|
|
1471
|
+
if continue_on_error and not caller_in_transaction:
|
|
1472
|
+
await self._commit_stack_success()
|
|
1473
|
+
|
|
1474
|
+
if stack_failure is None and started_transaction:
|
|
1475
|
+
await self._commit_stack_success()
|
|
1476
|
+
except Exception as exc:
|
|
1477
|
+
stack_failure = exc
|
|
1478
|
+
if stack_failure is not None:
|
|
1479
|
+
if started_transaction:
|
|
1480
|
+
try:
|
|
1481
|
+
await self.rollback()
|
|
1482
|
+
except Exception as rollback_error: # pragma: no cover
|
|
1483
|
+
logger.debug("Rollback after stack failure failed: %s", rollback_error)
|
|
1484
|
+
raise stack_failure
|
|
1485
|
+
|
|
1486
|
+
return tuple(results)
|
|
1487
|
+
|
|
1488
|
+
async def select_to_storage(
|
|
1489
|
+
self,
|
|
1490
|
+
statement: "SQL | str",
|
|
1491
|
+
destination: "StorageDestination",
|
|
1492
|
+
/,
|
|
1493
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1494
|
+
statement_config: "StatementConfig | None" = None,
|
|
1495
|
+
partitioner: "dict[str, object] | None" = None,
|
|
1496
|
+
format_hint: "StorageFormat | None" = None,
|
|
1497
|
+
telemetry: "StorageTelemetry | None" = None,
|
|
1498
|
+
) -> "StorageBridgeJob":
|
|
1499
|
+
"""Stream a SELECT statement directly into storage.
|
|
1500
|
+
|
|
1501
|
+
Args:
|
|
1502
|
+
statement: SQL statement to execute.
|
|
1503
|
+
destination: Storage destination path.
|
|
1504
|
+
parameters: Query parameters.
|
|
1505
|
+
statement_config: Optional statement configuration.
|
|
1506
|
+
partitioner: Optional partitioner configuration.
|
|
1507
|
+
format_hint: Optional format hint for storage.
|
|
1508
|
+
telemetry: Optional telemetry dict to merge.
|
|
1509
|
+
|
|
1510
|
+
Returns:
|
|
1511
|
+
StorageBridgeJob with execution telemetry.
|
|
1512
|
+
"""
|
|
1513
|
+
self._raise_storage_not_implemented("select_to_storage")
|
|
1514
|
+
|
|
1515
|
+
def without_indexes(
|
|
1516
|
+
self, table: str, *, schema: str | None = None, concurrent: bool = False
|
|
1517
|
+
) -> AsyncWithoutIndexesContext:
|
|
1518
|
+
"""Drop secondary indexes on ``table`` before bulk loading and rebuild them on exit."""
|
|
1519
|
+
return AsyncWithoutIndexesContext(self, table, schema=schema, concurrent=concurrent)
|
|
1520
|
+
|
|
1521
|
+
async def load_from_arrow(
|
|
1522
|
+
self,
|
|
1523
|
+
table: str,
|
|
1524
|
+
source: "ArrowResult | Any",
|
|
1525
|
+
*,
|
|
1526
|
+
partitioner: "dict[str, object] | None" = None,
|
|
1527
|
+
overwrite: bool = False,
|
|
1528
|
+
telemetry: "StorageTelemetry | None" = None,
|
|
1529
|
+
stage_table: "bool | str | None" = None,
|
|
1530
|
+
conflict_keys: "Sequence[str] | None" = None,
|
|
1531
|
+
on_conflict: Literal["update", "nothing"] = "update",
|
|
1532
|
+
exclude_update_columns: "Sequence[str] | None" = None,
|
|
1533
|
+
drop_stage_table: bool = True,
|
|
1534
|
+
drop_indexes: bool = False,
|
|
1535
|
+
concurrent_indexes: bool = False,
|
|
1536
|
+
type_casts: "Mapping[str, str] | None" = None,
|
|
1537
|
+
) -> "StorageBridgeJob":
|
|
1538
|
+
"""Load Arrow data into the target table.
|
|
1539
|
+
|
|
1540
|
+
Args:
|
|
1541
|
+
table: Target table name.
|
|
1542
|
+
source: Arrow data source.
|
|
1543
|
+
partitioner: Optional partitioner configuration.
|
|
1544
|
+
overwrite: Whether to overwrite existing data.
|
|
1545
|
+
telemetry: Optional inbound storage telemetry to merge.
|
|
1546
|
+
stage_table: Optional staging table flag or explicit staging table name.
|
|
1547
|
+
conflict_keys: Optional conflict key columns for server-side merge/upsert.
|
|
1548
|
+
on_conflict: Conflict action (``"update"`` or ``"nothing"``).
|
|
1549
|
+
exclude_update_columns: Optional columns excluded from ``SET`` updates.
|
|
1550
|
+
drop_stage_table: Whether to drop the staging table after merge.
|
|
1551
|
+
drop_indexes: Whether to drop and rebuild secondary indexes around the load.
|
|
1552
|
+
concurrent_indexes: Whether to rebuild PostgreSQL indexes with ``CONCURRENTLY``.
|
|
1553
|
+
type_casts: Optional column-to-SQL-type mapping for stage-to-target casts.
|
|
1554
|
+
|
|
1555
|
+
Returns:
|
|
1556
|
+
StorageBridgeJob with execution telemetry.
|
|
1557
|
+
|
|
1558
|
+
Raises:
|
|
1559
|
+
NotImplementedError: If not implemented.
|
|
1560
|
+
"""
|
|
1561
|
+
_ = (
|
|
1562
|
+
table,
|
|
1563
|
+
source,
|
|
1564
|
+
partitioner,
|
|
1565
|
+
overwrite,
|
|
1566
|
+
telemetry,
|
|
1567
|
+
stage_table,
|
|
1568
|
+
conflict_keys,
|
|
1569
|
+
on_conflict,
|
|
1570
|
+
exclude_update_columns,
|
|
1571
|
+
drop_stage_table,
|
|
1572
|
+
drop_indexes,
|
|
1573
|
+
concurrent_indexes,
|
|
1574
|
+
type_casts,
|
|
1575
|
+
)
|
|
1576
|
+
self._raise_storage_not_implemented("load_from_arrow")
|
|
1577
|
+
|
|
1578
|
+
async def load_from_storage(
|
|
1579
|
+
self,
|
|
1580
|
+
table: str,
|
|
1581
|
+
source: "StorageDestination",
|
|
1582
|
+
*,
|
|
1583
|
+
file_format: "StorageFormat",
|
|
1584
|
+
partitioner: "dict[str, object] | None" = None,
|
|
1585
|
+
overwrite: bool = False,
|
|
1586
|
+
storage_options: "dict[str, Any] | None" = None,
|
|
1587
|
+
stage_table: "bool | str | None" = None,
|
|
1588
|
+
conflict_keys: "Sequence[str] | None" = None,
|
|
1589
|
+
on_conflict: Literal["update", "nothing"] = "update",
|
|
1590
|
+
exclude_update_columns: "Sequence[str] | None" = None,
|
|
1591
|
+
drop_stage_table: bool = True,
|
|
1592
|
+
drop_indexes: bool = False,
|
|
1593
|
+
concurrent_indexes: bool = False,
|
|
1594
|
+
checkpoint_table: str | None = None,
|
|
1595
|
+
checkpoint_phase: str = "default",
|
|
1596
|
+
max_workers: int = 1,
|
|
1597
|
+
executor: Literal["thread", "process"] = "thread",
|
|
1598
|
+
arrow_schema: Any = None,
|
|
1599
|
+
type_casts: "Mapping[str, str] | None" = None,
|
|
1600
|
+
) -> "StorageBridgeJob":
|
|
1601
|
+
"""Load artifacts from storage into the target table.
|
|
1602
|
+
|
|
1603
|
+
Args:
|
|
1604
|
+
table: Target table name.
|
|
1605
|
+
source: Storage source path, prefix, or glob pattern.
|
|
1606
|
+
file_format: File format of source.
|
|
1607
|
+
partitioner: Optional partitioner configuration.
|
|
1608
|
+
overwrite: Whether to overwrite existing data.
|
|
1609
|
+
storage_options: Optional storage backend configuration.
|
|
1610
|
+
stage_table: Optional staging table flag or explicit staging table name.
|
|
1611
|
+
conflict_keys: Optional conflict key columns for server-side merge/upsert.
|
|
1612
|
+
on_conflict: Conflict action (``"update"`` or ``"nothing"``).
|
|
1613
|
+
exclude_update_columns: Optional columns excluded from ``SET`` updates.
|
|
1614
|
+
drop_stage_table: Whether to drop the staging table after merge.
|
|
1615
|
+
drop_indexes: Whether to drop and rebuild secondary indexes around the load.
|
|
1616
|
+
concurrent_indexes: Whether to rebuild PostgreSQL indexes with ``CONCURRENTLY``.
|
|
1617
|
+
checkpoint_table: Optional database table name for shard-level checkpoint tracking.
|
|
1618
|
+
checkpoint_phase: Checkpoint phase identifier (default ``"default"``).
|
|
1619
|
+
max_workers: Number of parallel workers for multi-shard storage fan-out.
|
|
1620
|
+
executor: Worker pool type (``"thread"`` or ``"process"``).
|
|
1621
|
+
arrow_schema: Optional PyArrow schema for explicit type pinning on decode.
|
|
1622
|
+
type_casts: Optional column-to-SQL-type mapping for stage-to-target casts.
|
|
1623
|
+
|
|
1624
|
+
Returns:
|
|
1625
|
+
StorageBridgeJob with execution telemetry.
|
|
1626
|
+
"""
|
|
1627
|
+
if type(self).load_from_arrow is AsyncDriverAdapterBase.load_from_arrow:
|
|
1628
|
+
self._raise_storage_not_implemented("load_from_storage")
|
|
1629
|
+
return await execute_load_from_storage_async(
|
|
1630
|
+
self,
|
|
1631
|
+
table,
|
|
1632
|
+
source,
|
|
1633
|
+
file_format=file_format,
|
|
1634
|
+
partitioner=partitioner,
|
|
1635
|
+
overwrite=overwrite,
|
|
1636
|
+
storage_options=storage_options,
|
|
1637
|
+
stage_table=stage_table,
|
|
1638
|
+
conflict_keys=conflict_keys,
|
|
1639
|
+
on_conflict=on_conflict,
|
|
1640
|
+
exclude_update_columns=exclude_update_columns,
|
|
1641
|
+
drop_stage_table=drop_stage_table,
|
|
1642
|
+
drop_indexes=drop_indexes,
|
|
1643
|
+
concurrent_indexes=concurrent_indexes,
|
|
1644
|
+
checkpoint_table=checkpoint_table,
|
|
1645
|
+
checkpoint_phase=checkpoint_phase,
|
|
1646
|
+
max_workers=max_workers,
|
|
1647
|
+
executor=executor,
|
|
1648
|
+
arrow_schema=arrow_schema,
|
|
1649
|
+
type_casts=type_casts,
|
|
1650
|
+
)
|
|
1651
|
+
|
|
1652
|
+
async def load_from_records(
|
|
1653
|
+
self,
|
|
1654
|
+
table: str,
|
|
1655
|
+
records: "Sequence[Mapping[str, Any]] | Sequence[Sequence[Any]]",
|
|
1656
|
+
*,
|
|
1657
|
+
columns: "list[str] | None" = None,
|
|
1658
|
+
overwrite: bool = False,
|
|
1659
|
+
stage_table: "bool | str | None" = None,
|
|
1660
|
+
conflict_keys: "Sequence[str] | None" = None,
|
|
1661
|
+
on_conflict: Literal["update", "nothing"] = "update",
|
|
1662
|
+
exclude_update_columns: "Sequence[str] | None" = None,
|
|
1663
|
+
drop_stage_table: bool = True,
|
|
1664
|
+
drop_indexes: bool = False,
|
|
1665
|
+
concurrent_indexes: bool = False,
|
|
1666
|
+
type_casts: "Mapping[str, str] | None" = None,
|
|
1667
|
+
) -> "StorageBridgeJob":
|
|
1668
|
+
"""Load in-memory dict or positional records into the target table.
|
|
1669
|
+
|
|
1670
|
+
Records are normalized into an Arrow table and routed through the
|
|
1671
|
+
adapter's native ``load_from_arrow`` path (COPY, executemany, mutations,
|
|
1672
|
+
etc.). Dict records derive their columns from the keys; positional
|
|
1673
|
+
records require ``columns``.
|
|
1674
|
+
|
|
1675
|
+
Args:
|
|
1676
|
+
table: Target table name.
|
|
1677
|
+
records: Mapping records, or positional sequences with ``columns``.
|
|
1678
|
+
columns: Column names (required for positional records).
|
|
1679
|
+
overwrite: Whether to overwrite existing data.
|
|
1680
|
+
stage_table: Optional staging table flag or explicit staging table name.
|
|
1681
|
+
conflict_keys: Optional conflict key columns for server-side merge/upsert.
|
|
1682
|
+
on_conflict: Conflict action (``"update"`` or ``"nothing"``).
|
|
1683
|
+
exclude_update_columns: Optional columns excluded from ``SET`` updates.
|
|
1684
|
+
drop_stage_table: Whether to drop the staging table after merge.
|
|
1685
|
+
drop_indexes: Whether to drop and rebuild secondary indexes around the load.
|
|
1686
|
+
concurrent_indexes: Whether to rebuild PostgreSQL indexes with ``CONCURRENTLY``.
|
|
1687
|
+
type_casts: Optional column-to-SQL-type mapping for stage-to-target casts.
|
|
1688
|
+
|
|
1689
|
+
Returns:
|
|
1690
|
+
StorageBridgeJob with execution telemetry.
|
|
1691
|
+
"""
|
|
1692
|
+
prepared_records = self._prepare_records_for_arrow(records)
|
|
1693
|
+
arrow_table = self._records_to_arrow_table(prepared_records, columns)
|
|
1694
|
+
if stage_table or conflict_keys or drop_indexes:
|
|
1695
|
+
return await execute_staged_load_async(
|
|
1696
|
+
self,
|
|
1697
|
+
table,
|
|
1698
|
+
arrow_table,
|
|
1699
|
+
raw_loader=self.load_from_arrow,
|
|
1700
|
+
overwrite=overwrite,
|
|
1701
|
+
stage_table=stage_table,
|
|
1702
|
+
conflict_keys=conflict_keys,
|
|
1703
|
+
on_conflict=on_conflict,
|
|
1704
|
+
exclude_update_columns=exclude_update_columns,
|
|
1705
|
+
drop_stage_table=drop_stage_table,
|
|
1706
|
+
drop_indexes=drop_indexes,
|
|
1707
|
+
concurrent_indexes=concurrent_indexes,
|
|
1708
|
+
type_casts=type_casts,
|
|
1709
|
+
)
|
|
1710
|
+
return await self.load_from_arrow(table, arrow_table, overwrite=overwrite)
|
|
1711
|
+
|
|
1712
|
+
def convert_to_dialect(
|
|
1713
|
+
self, statement: "Statement", to_dialect: "DialectType | None" = None, pretty: bool = DEFAULT_PRETTY
|
|
1714
|
+
) -> str:
|
|
1715
|
+
"""Convert a statement to a target SQL dialect.
|
|
1716
|
+
|
|
1717
|
+
Args:
|
|
1718
|
+
statement: SQL statement to convert.
|
|
1719
|
+
to_dialect: Target dialect (defaults to current dialect).
|
|
1720
|
+
pretty: Whether to format the output SQL.
|
|
1721
|
+
|
|
1722
|
+
Returns:
|
|
1723
|
+
SQL string in target dialect.
|
|
1724
|
+
"""
|
|
1725
|
+
return _convert_to_dialect_impl(statement, self.dialect, to_dialect, pretty)
|
|
1726
|
+
|
|
1727
|
+
@staticmethod
|
|
1728
|
+
def _check_pending_exception(exc_handler: AsyncExceptionHandler) -> None:
|
|
1729
|
+
"""Raise any pending mapped exception after context manager exit."""
|
|
1730
|
+
pending = exc_handler.pending_exception
|
|
1731
|
+
if pending is not None:
|
|
1732
|
+
if pending.__cause__ is not None:
|
|
1733
|
+
raise pending
|
|
1734
|
+
raise pending from None
|
|
1735
|
+
|
|
1736
|
+
async def _run_with_exception_handler(
|
|
1737
|
+
self,
|
|
1738
|
+
exc_handler: AsyncExceptionHandler,
|
|
1739
|
+
operation: "Callable[..., Awaitable[_AsyncResultT]]",
|
|
1740
|
+
*args: Any,
|
|
1741
|
+
**kwargs: Any,
|
|
1742
|
+
) -> "_AsyncResultT | None":
|
|
1743
|
+
"""Run an async operation without inheriting the caller's active exception state."""
|
|
1744
|
+
return await _run_with_async_exception_handler(exc_handler, operation, *args, **kwargs)
|
|
1745
|
+
|
|
1746
|
+
async def _execute_with_observability_async(
|
|
1747
|
+
self,
|
|
1748
|
+
*,
|
|
1749
|
+
compiled_sql: str,
|
|
1750
|
+
execution_parameters: Any,
|
|
1751
|
+
operation: "OperationType",
|
|
1752
|
+
is_many: bool,
|
|
1753
|
+
is_script: bool,
|
|
1754
|
+
runner: "Callable[..., Awaitable[SQLResult]]",
|
|
1755
|
+
precomputed_sql_hash: "str | None" = None,
|
|
1756
|
+
**runner_kwargs: Any,
|
|
1757
|
+
) -> "SQLResult":
|
|
1758
|
+
"""Execute an async runner while emitting spans, lifecycle hooks, and statement events."""
|
|
1759
|
+
runtime = self._observability
|
|
1760
|
+
if runtime is None or runtime.is_idle:
|
|
1761
|
+
return await runner(**runner_kwargs)
|
|
1762
|
+
driver_name = type(self).__name__
|
|
1763
|
+
db_system = self.observability_db_system
|
|
1764
|
+
observed_sql = (
|
|
1765
|
+
redact_sql_literals(compiled_sql, dialect=db_system)
|
|
1766
|
+
if is_script and runtime._redaction is not None and runtime._redaction.mask_parameters
|
|
1767
|
+
else compiled_sql
|
|
1768
|
+
)
|
|
1769
|
+
query_context = {
|
|
1770
|
+
"sql": observed_sql,
|
|
1771
|
+
"parameters": execution_parameters,
|
|
1772
|
+
"driver": driver_name,
|
|
1773
|
+
"operation": operation,
|
|
1774
|
+
"is_many": is_many,
|
|
1775
|
+
"is_script": is_script,
|
|
1776
|
+
}
|
|
1777
|
+
if db_system is not None:
|
|
1778
|
+
query_context["db_system"] = db_system
|
|
1779
|
+
await runtime.emit_query_start_async(**query_context)
|
|
1780
|
+
sql_hash = precomputed_sql_hash if not is_script else None
|
|
1781
|
+
if sql_hash is None and (
|
|
1782
|
+
runtime.span_manager.is_enabled
|
|
1783
|
+
or (runtime.has_statement_observers and runtime.config.logging and runtime.config.logging.include_sql_hash)
|
|
1784
|
+
):
|
|
1785
|
+
sql_hash = observability_runtime.compute_sql_hash(observed_sql)
|
|
1786
|
+
span = runtime.start_query_span(observed_sql, operation, driver_name, sql_hash=sql_hash, db_system=db_system)
|
|
1787
|
+
started = perf_counter()
|
|
1788
|
+
self._pending_statement_profile = None
|
|
1789
|
+
run_error: Exception | None = None
|
|
1790
|
+
result: SQLResult | None = None
|
|
1791
|
+
try:
|
|
1792
|
+
result = await runner(**runner_kwargs)
|
|
1793
|
+
except Exception as exc:
|
|
1794
|
+
run_error = exc
|
|
1795
|
+
if run_error is not None:
|
|
1796
|
+
self._pending_statement_profile = None
|
|
1797
|
+
runtime.span_manager.end_span(span, error=run_error)
|
|
1798
|
+
await runtime.emit_error_async(run_error, **query_context)
|
|
1799
|
+
runtime.emit_statement_event(
|
|
1800
|
+
sql=observed_sql,
|
|
1801
|
+
parameters=execution_parameters,
|
|
1802
|
+
driver=driver_name,
|
|
1803
|
+
operation=operation,
|
|
1804
|
+
execution_mode=self.statement_config.execution_mode,
|
|
1805
|
+
is_many=is_many,
|
|
1806
|
+
is_script=is_script,
|
|
1807
|
+
rows_affected=None,
|
|
1808
|
+
duration_s=perf_counter() - started,
|
|
1809
|
+
storage_backend=None,
|
|
1810
|
+
started_at=started,
|
|
1811
|
+
precomputed_sql_hash=sql_hash,
|
|
1812
|
+
is_error=True,
|
|
1813
|
+
profile=None,
|
|
1814
|
+
db_system=db_system,
|
|
1815
|
+
)
|
|
1816
|
+
raise run_error
|
|
1817
|
+
assert result is not None
|
|
1818
|
+
profile = self._consume_statement_profile()
|
|
1819
|
+
runtime.span_manager.end_span(span)
|
|
1820
|
+
duration = perf_counter() - started
|
|
1821
|
+
await runtime.emit_query_complete_async(**{**query_context, "rows_affected": result.rows_affected})
|
|
1822
|
+
runtime.emit_statement_event(
|
|
1823
|
+
sql=observed_sql,
|
|
1824
|
+
parameters=execution_parameters,
|
|
1825
|
+
driver=driver_name,
|
|
1826
|
+
operation=operation,
|
|
1827
|
+
execution_mode=self.statement_config.execution_mode,
|
|
1828
|
+
is_many=is_many,
|
|
1829
|
+
is_script=is_script,
|
|
1830
|
+
rows_affected=result.rows_affected,
|
|
1831
|
+
duration_s=duration,
|
|
1832
|
+
storage_backend=(result.metadata or {}).get("storage_backend"),
|
|
1833
|
+
started_at=started,
|
|
1834
|
+
precomputed_sql_hash=sql_hash,
|
|
1835
|
+
profile=profile,
|
|
1836
|
+
db_system=db_system,
|
|
1837
|
+
)
|
|
1838
|
+
return result
|
|
1839
|
+
|
|
1840
|
+
async def _dispatch_statement_observed_async(
|
|
1841
|
+
self, connection: Any, statement: "SQL", *, has_execution_parameters: bool
|
|
1842
|
+
) -> "SQLResult":
|
|
1843
|
+
"""Execute an async statement inside an exception handler and raise any mapped error."""
|
|
1844
|
+
exc_handler = self.handle_database_exceptions()
|
|
1845
|
+
result: SQLResult | None = None
|
|
1846
|
+
try:
|
|
1847
|
+
if sys.exc_info()[1] is None:
|
|
1848
|
+
async with exc_handler:
|
|
1849
|
+
result = await self._dispatch_statement_with_cursor(
|
|
1850
|
+
connection, statement, has_execution_parameters=has_execution_parameters
|
|
1851
|
+
)
|
|
1852
|
+
else:
|
|
1853
|
+
result = await self._run_with_exception_handler(
|
|
1854
|
+
exc_handler,
|
|
1855
|
+
self._dispatch_statement_with_cursor,
|
|
1856
|
+
connection,
|
|
1857
|
+
statement,
|
|
1858
|
+
has_execution_parameters=has_execution_parameters,
|
|
1859
|
+
)
|
|
1860
|
+
except Exception as exc: # pragma: no cover
|
|
1861
|
+
_raise_database_exception(exc_handler, exc)
|
|
1862
|
+
if exc_handler.pending_exception is not None:
|
|
1863
|
+
_raise_database_exception(exc_handler, None)
|
|
1864
|
+
assert result is not None
|
|
1865
|
+
return result
|
|
1866
|
+
|
|
1867
|
+
async def _execute_cache_hit(
|
|
1868
|
+
self, sql: str, params: "tuple[Any, ...] | list[Any] | dict[str, Any]", cached: CachedQuery
|
|
1869
|
+
) -> "SQLResult":
|
|
1870
|
+
"""Execute pre-compiled query via ultra-fast path (async).
|
|
1871
|
+
|
|
1872
|
+
Uses DBAPI-style async cursor methods when available. Async adapters with
|
|
1873
|
+
connection-level execution APIs fall back to dispatch_execute so they can
|
|
1874
|
+
preserve adapter-specific parameter binding semantics. For DML operations,
|
|
1875
|
+
returns DMLResult to bypass full SQLResult construction.
|
|
1876
|
+
|
|
1877
|
+
Args:
|
|
1878
|
+
sql: Raw SQL string (original, not compiled).
|
|
1879
|
+
params: Query parameters.
|
|
1880
|
+
cached: Cached query metadata.
|
|
1881
|
+
|
|
1882
|
+
Returns:
|
|
1883
|
+
SQLResult or DMLResult.
|
|
1884
|
+
"""
|
|
1885
|
+
if self._auto_begin_on_write:
|
|
1886
|
+
await self._ensure_transaction_for_operation(cached.operation_type, cached.operation_profile.modifies_rows)
|
|
1887
|
+
exc_handler = self.handle_database_exceptions()
|
|
1888
|
+
result: SQLResult | None = None
|
|
1889
|
+
if sys.exc_info()[1] is None:
|
|
1890
|
+
async with exc_handler:
|
|
1891
|
+
result = await self._execute_cache_hit_with_cursor(sql, params, cached)
|
|
1892
|
+
else:
|
|
1893
|
+
result = await self._run_with_exception_handler(
|
|
1894
|
+
exc_handler, self._execute_cache_hit_with_cursor, sql, params, cached
|
|
1895
|
+
)
|
|
1896
|
+
self._check_pending_exception(exc_handler)
|
|
1897
|
+
assert result is not None
|
|
1898
|
+
return result
|
|
1899
|
+
|
|
1900
|
+
async def _execute_cache_hit_observed(
|
|
1901
|
+
self, sql: str, params: "tuple[Any, ...] | list[Any] | dict[str, Any]", cached: CachedQuery
|
|
1902
|
+
) -> "SQLResult":
|
|
1903
|
+
"""Execute an async fast-path cache hit wrapped in observability instrumentation."""
|
|
1904
|
+
obs_params = list(params) if isinstance(params, tuple) else params
|
|
1905
|
+
wire_sql = self._format_wire_sql(cached.compiled_sql)
|
|
1906
|
+
sql_hash: str | None = None
|
|
1907
|
+
if not self.statement_config.enable_sqlcommenter:
|
|
1908
|
+
sql_hash = cached._sql_hash
|
|
1909
|
+
if sql_hash is None:
|
|
1910
|
+
sql_hash = observability_runtime.compute_sql_hash(wire_sql)
|
|
1911
|
+
cached._sql_hash = sql_hash
|
|
1912
|
+
return await self._execute_with_observability_async(
|
|
1913
|
+
compiled_sql=wire_sql,
|
|
1914
|
+
execution_parameters=obs_params,
|
|
1915
|
+
operation=cached.operation_type,
|
|
1916
|
+
is_many=False,
|
|
1917
|
+
is_script=False,
|
|
1918
|
+
runner=self._execute_cache_hit,
|
|
1919
|
+
precomputed_sql_hash=sql_hash,
|
|
1920
|
+
sql=sql,
|
|
1921
|
+
params=params,
|
|
1922
|
+
cached=cached,
|
|
1923
|
+
)
|
|
1924
|
+
|
|
1925
|
+
async def _execute_cached_statement(self, statement: "SQL") -> "SQLResult":
|
|
1926
|
+
"""Execute pre-compiled query via fast path (async).
|
|
1927
|
+
|
|
1928
|
+
The statement is already compiled by run_cached_execution, so dispatch_execute
|
|
1929
|
+
will hit the fast path in _compiled_statement (is_processed check).
|
|
1930
|
+
"""
|
|
1931
|
+
exc_handler = self.handle_database_exceptions()
|
|
1932
|
+
result: SQLResult | None = None
|
|
1933
|
+
try:
|
|
1934
|
+
if self._auto_begin_on_write:
|
|
1935
|
+
await self._ensure_transaction_for_statement(statement)
|
|
1936
|
+
if sys.exc_info()[1] is None:
|
|
1937
|
+
async with exc_handler:
|
|
1938
|
+
result = await self._execute_cached_statement_with_cursor(statement)
|
|
1939
|
+
else:
|
|
1940
|
+
result = await self._run_with_exception_handler(
|
|
1941
|
+
exc_handler, self._execute_cached_statement_with_cursor, statement
|
|
1942
|
+
)
|
|
1943
|
+
|
|
1944
|
+
self._check_pending_exception(exc_handler)
|
|
1945
|
+
assert result is not None
|
|
1946
|
+
return result
|
|
1947
|
+
finally:
|
|
1948
|
+
self._release_pooled_statement(statement)
|
|
1949
|
+
|
|
1950
|
+
async def _execute_cached_statement_observed(
|
|
1951
|
+
self, statement: "SQL", compiled_sql: str, execution_parameters: Any, operation: "OperationType"
|
|
1952
|
+
) -> "SQLResult":
|
|
1953
|
+
"""Execute a rebound cached async statement wrapped in observability instrumentation."""
|
|
1954
|
+
obs_params = list(execution_parameters) if isinstance(execution_parameters, tuple) else execution_parameters
|
|
1955
|
+
return await self._execute_with_observability_async(
|
|
1956
|
+
compiled_sql=compiled_sql,
|
|
1957
|
+
execution_parameters=obs_params,
|
|
1958
|
+
operation=operation,
|
|
1959
|
+
is_many=False,
|
|
1960
|
+
is_script=False,
|
|
1961
|
+
runner=self._execute_cached_statement,
|
|
1962
|
+
statement=statement,
|
|
1963
|
+
)
|
|
1964
|
+
|
|
1965
|
+
async def _execute(
|
|
1966
|
+
self,
|
|
1967
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1968
|
+
parameters: "tuple[StatementParameters | StatementFilter, ...]",
|
|
1969
|
+
statement_config: "StatementConfig | None",
|
|
1970
|
+
kwargs: "dict[str, Any]",
|
|
1971
|
+
) -> "SQLResult":
|
|
1972
|
+
sql_statement = self.prepare_statement(
|
|
1973
|
+
statement, parameters, statement_config=statement_config or self.statement_config, kwargs=kwargs
|
|
1974
|
+
)
|
|
1975
|
+
return await self.dispatch_statement_execution(statement=sql_statement, connection=self.connection)
|
|
1976
|
+
|
|
1977
|
+
async def _execute_many(
|
|
1978
|
+
self,
|
|
1979
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1980
|
+
parameters: "Sequence[StatementParameters]",
|
|
1981
|
+
filters: "tuple[StatementParameters | StatementFilter, ...]",
|
|
1982
|
+
statement_config: "StatementConfig | None",
|
|
1983
|
+
kwargs: "dict[str, Any]",
|
|
1984
|
+
) -> "SQLResult":
|
|
1985
|
+
config = statement_config or self.statement_config
|
|
1986
|
+
if isinstance(statement, str) and not filters and not kwargs:
|
|
1987
|
+
sql_statement = SQL(statement, parameters, statement_config=config, is_many=True)
|
|
1988
|
+
elif isinstance(statement, SQL):
|
|
1989
|
+
statement_seed = statement.raw_expression or statement.raw_sql
|
|
1990
|
+
sql_statement = SQL(statement_seed, parameters, statement_config=config, is_many=True, **kwargs)
|
|
1991
|
+
else:
|
|
1992
|
+
base_statement = self.prepare_statement(statement, filters, statement_config=config, kwargs=kwargs)
|
|
1993
|
+
statement_seed = base_statement.raw_expression or base_statement.raw_sql
|
|
1994
|
+
sql_statement = SQL(statement_seed, parameters, statement_config=config, is_many=True, **kwargs)
|
|
1995
|
+
return await self.dispatch_statement_execution(statement=sql_statement, connection=self.connection)
|
|
1996
|
+
|
|
1997
|
+
async def _execute_script(
|
|
1998
|
+
self,
|
|
1999
|
+
statement: "str | SQL",
|
|
2000
|
+
parameters: "tuple[StatementParameters | StatementFilter, ...]",
|
|
2001
|
+
statement_config: "StatementConfig | None",
|
|
2002
|
+
kwargs: "dict[str, Any]",
|
|
2003
|
+
) -> "SQLResult":
|
|
2004
|
+
config = statement_config or self.statement_config
|
|
2005
|
+
sql_statement = self.prepare_statement(statement, parameters, statement_config=config, kwargs=kwargs)
|
|
2006
|
+
return await self.dispatch_statement_execution(statement=sql_statement.as_script(), connection=self.connection)
|
|
2007
|
+
|
|
2008
|
+
def _connection_in_transaction(self) -> bool:
|
|
2009
|
+
"""Check if the connection is inside a transaction.
|
|
2010
|
+
|
|
2011
|
+
Each adapter MUST override this method with direct attribute access
|
|
2012
|
+
for optimal mypyc performance. Do not use getattr chains.
|
|
2013
|
+
|
|
2014
|
+
Raises:
|
|
2015
|
+
NotImplementedError: Always - subclasses must override.
|
|
2016
|
+
"""
|
|
2017
|
+
msg = "Adapters must override _connection_in_transaction()"
|
|
2018
|
+
raise NotImplementedError(msg)
|
|
2019
|
+
|
|
2020
|
+
async def _connection_in_transaction_async(self) -> bool:
|
|
2021
|
+
"""Return whether an awaited probe of the connection reports an open transaction.
|
|
2022
|
+
|
|
2023
|
+
Adapters whose transaction state is only readable through an awaited call override this
|
|
2024
|
+
method. Callers combine it with :meth:`_connection_in_transaction`.
|
|
2025
|
+
|
|
2026
|
+
Returns:
|
|
2027
|
+
False for adapters without an awaited transaction probe.
|
|
2028
|
+
"""
|
|
2029
|
+
return False
|
|
2030
|
+
|
|
2031
|
+
async def _ensure_transaction_for_cached_sql(
|
|
2032
|
+
self, statement: str, params: "tuple[Any, ...] | list[Any] | dict[str, Any]"
|
|
2033
|
+
) -> None:
|
|
2034
|
+
"""Open a transaction before a cached positional statement when lazy write begin is armed."""
|
|
2035
|
+
cached = self._stmt_cache.get(statement)
|
|
2036
|
+
if cached is None or cached.param_count != len(params) or cached.input_named_parameters:
|
|
2037
|
+
return
|
|
2038
|
+
if self.statement_config.parameter_config.ast_transformer is not None:
|
|
2039
|
+
return
|
|
2040
|
+
await self._ensure_transaction_for_operation(cached.operation_type, cached.operation_profile.modifies_rows)
|
|
2041
|
+
|
|
2042
|
+
async def _ensure_transaction_for_operation(self, operation_type: "OperationType", modifies_rows: bool) -> None:
|
|
2043
|
+
"""Open a transaction before a mutating statement when lazy write begin is armed."""
|
|
2044
|
+
if operation_requires_transaction(operation_type, modifies_rows) and not self._connection_in_transaction():
|
|
2045
|
+
await self.begin()
|
|
2046
|
+
|
|
2047
|
+
async def _ensure_transaction_for_statement(self, statement: "SQL") -> None:
|
|
2048
|
+
"""Open a transaction before a mutating prepared statement when lazy write begin is armed."""
|
|
2049
|
+
if statement.is_script or statement.is_many:
|
|
2050
|
+
if not self._connection_in_transaction():
|
|
2051
|
+
await self.begin()
|
|
2052
|
+
return
|
|
2053
|
+
profile = statement.get_processed_state().operation_profile
|
|
2054
|
+
await self._ensure_transaction_for_operation(statement.operation_type, profile.modifies_rows)
|
|
2055
|
+
|
|
2056
|
+
async def _dispatch_statement_with_cursor(
|
|
2057
|
+
self, connection: Any, statement: "SQL", *, has_execution_parameters: bool
|
|
2058
|
+
) -> "SQLResult":
|
|
2059
|
+
"""Execute a statement while owning only the cursor context."""
|
|
2060
|
+
cursor_manager = self.with_cursor(connection)
|
|
2061
|
+
cursor_entered = False
|
|
2062
|
+
exit_suppressed = False
|
|
2063
|
+
error: Exception | None = None
|
|
2064
|
+
interruption: BaseException | None = None
|
|
2065
|
+
execution_result: ExecutionResult | None = None
|
|
2066
|
+
result: SQLResult | None = None
|
|
2067
|
+
try:
|
|
2068
|
+
cursor = await cursor_manager.__aenter__()
|
|
2069
|
+
cursor_entered = True
|
|
2070
|
+
special_result = await self.dispatch_special_handling(cursor, statement)
|
|
2071
|
+
if special_result is not None:
|
|
2072
|
+
result = special_result
|
|
2073
|
+
elif statement.is_script:
|
|
2074
|
+
execution_result = await self.dispatch_execute_script(cursor, statement)
|
|
2075
|
+
elif statement.is_many:
|
|
2076
|
+
if has_execution_parameters:
|
|
2077
|
+
execution_result = await self.dispatch_execute_many(cursor, statement)
|
|
2078
|
+
else:
|
|
2079
|
+
execution_result = self.create_execution_result(cursor, rowcount_override=0, is_many_result=True)
|
|
2080
|
+
else:
|
|
2081
|
+
execution_result = await self.dispatch_execute(cursor, statement)
|
|
2082
|
+
if special_result is None:
|
|
2083
|
+
assert execution_result is not None
|
|
2084
|
+
result = self.build_statement_result(statement, execution_result)
|
|
2085
|
+
except Exception as exc:
|
|
2086
|
+
error = exc
|
|
2087
|
+
except BaseException as exc:
|
|
2088
|
+
interruption = exc
|
|
2089
|
+
if cursor_entered:
|
|
2090
|
+
if error is None:
|
|
2091
|
+
await cursor_manager.__aexit__(None, None, None)
|
|
2092
|
+
else:
|
|
2093
|
+
exit_suppressed = bool(await cursor_manager.__aexit__(type(error), error, error.__traceback__))
|
|
2094
|
+
if interruption is not None:
|
|
2095
|
+
raise interruption
|
|
2096
|
+
if error is not None and not exit_suppressed:
|
|
2097
|
+
raise error
|
|
2098
|
+
assert result is not None
|
|
2099
|
+
return result
|
|
2100
|
+
|
|
2101
|
+
async def _execute_cache_hit_with_cursor(
|
|
2102
|
+
self, sql: str, params: "tuple[Any, ...] | list[Any] | dict[str, Any]", cached: CachedQuery
|
|
2103
|
+
) -> "SQLResult":
|
|
2104
|
+
"""Execute a cached query while owning only the cursor context."""
|
|
2105
|
+
direct_statement: SQL | None = None
|
|
2106
|
+
result: SQLResult | None = None
|
|
2107
|
+
try:
|
|
2108
|
+
cursor_context = self.with_cursor(self.connection)
|
|
2109
|
+
cursor = await cursor_context.__aenter__()
|
|
2110
|
+
cursor_error: BaseException | None = None
|
|
2111
|
+
try:
|
|
2112
|
+
wire_sql = self._format_wire_sql(cached.compiled_sql)
|
|
2113
|
+
returns_rows = cached.operation_profile.returns_rows
|
|
2114
|
+
execute = getattr(cursor, "execute", None) if cursor is not self.connection else None
|
|
2115
|
+
fetchall = getattr(cursor, "fetchall", None) if execute is not None and returns_rows else None
|
|
2116
|
+
can_use_cursor_fast_path = execute is not None and (
|
|
2117
|
+
(returns_rows and fetchall is not None) or (not returns_rows and hasattr(cursor, "rowcount"))
|
|
2118
|
+
)
|
|
2119
|
+
if can_use_cursor_fast_path:
|
|
2120
|
+
assert execute is not None
|
|
2121
|
+
execute_result = execute(wire_sql, params) if params else execute(wire_sql)
|
|
2122
|
+
if isawaitable(execute_result):
|
|
2123
|
+
await execute_result
|
|
2124
|
+
if returns_rows:
|
|
2125
|
+
assert fetchall is not None
|
|
2126
|
+
fetched_data = fetchall()
|
|
2127
|
+
if isawaitable(fetched_data):
|
|
2128
|
+
fetched_data = await fetched_data
|
|
2129
|
+
if isinstance(fetched_data, tuple):
|
|
2130
|
+
fetched_data = list(fetched_data)
|
|
2131
|
+
data, column_names, row_count = self.collect_rows(cursor, fetched_data)
|
|
2132
|
+
result = self.build_cached_select_result(
|
|
2133
|
+
sql,
|
|
2134
|
+
params,
|
|
2135
|
+
cached,
|
|
2136
|
+
selected_data=data,
|
|
2137
|
+
column_names=column_names,
|
|
2138
|
+
data_row_count=row_count,
|
|
2139
|
+
row_format=resolve_row_format(data),
|
|
2140
|
+
compiled_sql=wire_sql,
|
|
2141
|
+
)
|
|
2142
|
+
else:
|
|
2143
|
+
affected_rows = self.resolve_rowcount(cursor)
|
|
2144
|
+
result = DMLResult(cached.operation_type, affected_rows)
|
|
2145
|
+
else:
|
|
2146
|
+
direct_statement = self._cached_statement(
|
|
2147
|
+
sql, params, cached, params, params_are_simple=True, compiled_sql=wire_sql
|
|
2148
|
+
)
|
|
2149
|
+
execution_result = await self.dispatch_execute(cursor, direct_statement)
|
|
2150
|
+
if returns_rows:
|
|
2151
|
+
result = self.build_statement_result(direct_statement, execution_result)
|
|
2152
|
+
else:
|
|
2153
|
+
affected_rows = (
|
|
2154
|
+
execution_result.rowcount_override
|
|
2155
|
+
if execution_result.rowcount_override is not None
|
|
2156
|
+
and execution_result.rowcount_override >= 0
|
|
2157
|
+
else 0
|
|
2158
|
+
)
|
|
2159
|
+
result = DMLResult(cached.operation_type, affected_rows)
|
|
2160
|
+
except BaseException as caught:
|
|
2161
|
+
cursor_error = caught
|
|
2162
|
+
await exit_async_context(cursor_context, cursor_error)
|
|
2163
|
+
assert result is not None
|
|
2164
|
+
return result
|
|
2165
|
+
finally:
|
|
2166
|
+
if direct_statement is not None:
|
|
2167
|
+
self._release_pooled_statement(direct_statement)
|
|
2168
|
+
|
|
2169
|
+
async def _execute_cached_statement_with_cursor(self, statement: "SQL") -> "SQLResult":
|
|
2170
|
+
"""Execute a prepared statement while owning only the cursor context."""
|
|
2171
|
+
cursor_context = self.with_cursor(self.connection)
|
|
2172
|
+
cursor = await cursor_context.__aenter__()
|
|
2173
|
+
cursor_error: BaseException | None = None
|
|
2174
|
+
result: SQLResult | None = None
|
|
2175
|
+
try:
|
|
2176
|
+
execution_result = await self.dispatch_execute(cursor, statement)
|
|
2177
|
+
result = self.build_statement_result(statement, execution_result)
|
|
2178
|
+
except BaseException as caught:
|
|
2179
|
+
cursor_error = caught
|
|
2180
|
+
await exit_async_context(cursor_context, cursor_error)
|
|
2181
|
+
assert result is not None
|
|
2182
|
+
return result
|
|
2183
|
+
|
|
2184
|
+
async def _execute_stack_operation(self, operation: "StackOperation") -> "SQLResult | ArrowResult | None":
|
|
2185
|
+
kwargs = dict(operation.keyword_arguments) if operation.keyword_arguments else {}
|
|
2186
|
+
|
|
2187
|
+
if operation.method == "execute":
|
|
2188
|
+
return await self.execute(operation.statement, *operation.arguments, **kwargs)
|
|
2189
|
+
|
|
2190
|
+
if operation.method == "execute_many":
|
|
2191
|
+
if not operation.arguments:
|
|
2192
|
+
msg = "execute_many stack operation requires parameter sets"
|
|
2193
|
+
raise ValueError(msg)
|
|
2194
|
+
parameter_sets = operation.arguments[0]
|
|
2195
|
+
filters = operation.arguments[1:]
|
|
2196
|
+
return await self.execute_many(operation.statement, parameter_sets, *filters, **kwargs)
|
|
2197
|
+
|
|
2198
|
+
if operation.method == "execute_script":
|
|
2199
|
+
return await self.execute_script(operation.statement, *operation.arguments, **kwargs)
|
|
2200
|
+
|
|
2201
|
+
if operation.method == "execute_arrow":
|
|
2202
|
+
return await self.select_to_arrow(operation.statement, *operation.arguments, **kwargs)
|
|
2203
|
+
|
|
2204
|
+
msg = f"Unsupported stack operation method: {operation.method}"
|
|
2205
|
+
raise ValueError(msg)
|
|
2206
|
+
|
|
2207
|
+
async def _rollback_failed_stack(self) -> None:
|
|
2208
|
+
"""Attempt to rollback after a stack operation error (async)."""
|
|
2209
|
+
try:
|
|
2210
|
+
await self.rollback()
|
|
2211
|
+
except Exception as rollback_error: # pragma: no cover
|
|
2212
|
+
logger.debug("Rollback after stack error failed: %s", rollback_error)
|
|
2213
|
+
|
|
2214
|
+
async def _commit_stack_success(self) -> None:
|
|
2215
|
+
"""Commit after a successful stack operation when not batching (async)."""
|
|
2216
|
+
exc_handler = self.handle_database_exceptions()
|
|
2217
|
+
async with exc_handler:
|
|
2218
|
+
await self.commit()
|
|
2219
|
+
self._check_pending_exception(exc_handler)
|
|
2220
|
+
|
|
2221
|
+
def _storage_pipeline(self) -> "AsyncStoragePipeline":
|
|
2222
|
+
"""Get or create an async storage pipeline.
|
|
2223
|
+
|
|
2224
|
+
Returns:
|
|
2225
|
+
AsyncStoragePipeline instance.
|
|
2226
|
+
"""
|
|
2227
|
+
factory = self.storage_pipeline_factory
|
|
2228
|
+
if factory is None:
|
|
2229
|
+
return AsyncStoragePipeline()
|
|
2230
|
+
return cast("AsyncStoragePipeline", factory())
|
|
2231
|
+
|
|
2232
|
+
async def _write_storage_result(
|
|
2233
|
+
self,
|
|
2234
|
+
result: "ArrowResult",
|
|
2235
|
+
destination: "StorageDestination",
|
|
2236
|
+
*,
|
|
2237
|
+
format_hint: "StorageFormat | None" = None,
|
|
2238
|
+
storage_options: "dict[str, Any] | None" = None,
|
|
2239
|
+
pipeline: "AsyncStoragePipeline | None" = None,
|
|
2240
|
+
) -> "StorageTelemetry":
|
|
2241
|
+
"""Write Arrow result to storage with telemetry.
|
|
2242
|
+
|
|
2243
|
+
Args:
|
|
2244
|
+
result: Arrow result to write.
|
|
2245
|
+
destination: Storage destination.
|
|
2246
|
+
format_hint: Optional format hint.
|
|
2247
|
+
storage_options: Optional storage options.
|
|
2248
|
+
pipeline: Optional storage pipeline.
|
|
2249
|
+
|
|
2250
|
+
Returns:
|
|
2251
|
+
StorageTelemetry with write metrics.
|
|
2252
|
+
"""
|
|
2253
|
+
runtime = self.observability
|
|
2254
|
+
span: Any = None
|
|
2255
|
+
span_started = False
|
|
2256
|
+
telemetry: StorageTelemetry | None = None
|
|
2257
|
+
pending_exc: BaseException | None = None
|
|
2258
|
+
result_metadata = result.metadata
|
|
2259
|
+
stream_aclose = result_metadata.get("stream_aclose") if isinstance(result_metadata, dict) else None
|
|
2260
|
+
stream_close = result_metadata.get("stream_close") if isinstance(result_metadata, dict) else None
|
|
2261
|
+
try:
|
|
2262
|
+
span = runtime.start_storage_span(
|
|
2263
|
+
"write", destination=stringify_storage_target(destination), format_label=format_hint
|
|
2264
|
+
)
|
|
2265
|
+
span_started = True
|
|
2266
|
+
telemetry = await result.write_to_storage_async(
|
|
2267
|
+
destination, format_hint=format_hint, storage_options=storage_options, pipeline=pipeline
|
|
2268
|
+
)
|
|
2269
|
+
except BaseException as exc:
|
|
2270
|
+
pending_exc = exc
|
|
2271
|
+
cleanup_cancel: asyncio.CancelledError | None = None
|
|
2272
|
+
try:
|
|
2273
|
+
await close_async_arrow_result_resources(
|
|
2274
|
+
result.data,
|
|
2275
|
+
stream_aclose=stream_aclose if callable(stream_aclose) else None,
|
|
2276
|
+
stream_close=stream_close if callable(stream_close) else None,
|
|
2277
|
+
)
|
|
2278
|
+
except asyncio.CancelledError as caught_cancel:
|
|
2279
|
+
cleanup_cancel = caught_cancel
|
|
2280
|
+
if pending_exc is not None:
|
|
2281
|
+
if span_started and isinstance(pending_exc, Exception):
|
|
2282
|
+
runtime.end_storage_span(span, error=pending_exc)
|
|
2283
|
+
raise pending_exc
|
|
2284
|
+
if cleanup_cancel is not None:
|
|
2285
|
+
raise cleanup_cancel
|
|
2286
|
+
if telemetry is None:
|
|
2287
|
+
msg = "Unreachable"
|
|
2288
|
+
raise RuntimeError(msg)
|
|
2289
|
+
read_ahead_columns = result_metadata.get("read_ahead_columns") if isinstance(result_metadata, dict) else None
|
|
2290
|
+
if read_ahead_columns:
|
|
2291
|
+
extra = telemetry.get("extra")
|
|
2292
|
+
if extra is None:
|
|
2293
|
+
extra = {}
|
|
2294
|
+
telemetry["extra"] = extra
|
|
2295
|
+
extra["read_ahead_columns"] = read_ahead_columns
|
|
2296
|
+
telemetry = runtime.annotate_storage_telemetry(telemetry)
|
|
2297
|
+
runtime.end_storage_span(span, telemetry=telemetry)
|
|
2298
|
+
return telemetry
|
|
2299
|
+
|
|
2300
|
+
async def _select_for_storage(
|
|
2301
|
+
self,
|
|
2302
|
+
statement: "Statement | QueryBuilder",
|
|
2303
|
+
/,
|
|
2304
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
2305
|
+
statement_config: "StatementConfig | None" = None,
|
|
2306
|
+
**kwargs: Any,
|
|
2307
|
+
) -> "ArrowResult":
|
|
2308
|
+
"""Return an Arrow result that streams rows to storage asynchronously."""
|
|
2309
|
+
if "return_format" in kwargs or kwargs.get("native_only"):
|
|
2310
|
+
return await self.select_to_arrow(statement, *parameters, statement_config=statement_config, **kwargs)
|
|
2311
|
+
if self.native_arrow_export:
|
|
2312
|
+
return await self.select_to_arrow(
|
|
2313
|
+
statement, *parameters, statement_config=statement_config, return_format="reader", **kwargs
|
|
2314
|
+
)
|
|
2315
|
+
fallback_kwargs = dict(kwargs)
|
|
2316
|
+
raw_batch_size = kwargs.pop("batch_size", None)
|
|
2317
|
+
batch_size = _DEFAULT_EXPORT_BATCH_SIZE if raw_batch_size is None else int(raw_batch_size)
|
|
2318
|
+
arrow_schema = kwargs.pop("arrow_schema", None)
|
|
2319
|
+
stream = self.select_stream(
|
|
2320
|
+
statement, *parameters, statement_config=statement_config, chunk_size=batch_size, **kwargs
|
|
2321
|
+
)
|
|
2322
|
+
read_ahead: list[str] = []
|
|
2323
|
+
batches = await arrow_batches_from_async_rows(
|
|
2324
|
+
stream,
|
|
2325
|
+
batch_size=batch_size,
|
|
2326
|
+
arrow_schema=arrow_schema,
|
|
2327
|
+
integer_may_widen=self.export_integers_may_widen,
|
|
2328
|
+
on_read_ahead=read_ahead.extend,
|
|
2329
|
+
)
|
|
2330
|
+
if batches is None:
|
|
2331
|
+
await stream.aclose()
|
|
2332
|
+
return await self.select_to_arrow(
|
|
2333
|
+
statement, *parameters, statement_config=statement_config, **fallback_kwargs
|
|
2334
|
+
)
|
|
2335
|
+
metadata: dict[str, Any] = {"streamed": True, "row_stream_batches": True, "stream_aclose": stream.aclose}
|
|
2336
|
+
if read_ahead:
|
|
2337
|
+
metadata["read_ahead_columns"] = tuple(read_ahead)
|
|
2338
|
+
prepared = self.prepare_statement(
|
|
2339
|
+
statement, parameters, statement_config=statement_config or self.statement_config, kwargs={}
|
|
2340
|
+
)
|
|
2341
|
+
return create_arrow_result(statement=prepared, data=batches, rows_affected=0, metadata=metadata)
|
|
2342
|
+
|
|
2343
|
+
async def _read_storage_arrow(
|
|
2344
|
+
self,
|
|
2345
|
+
source: "StorageDestination",
|
|
2346
|
+
*,
|
|
2347
|
+
file_format: "StorageFormat",
|
|
2348
|
+
storage_options: "dict[str, Any] | None" = None,
|
|
2349
|
+
) -> "tuple[ArrowTable, StorageTelemetry]":
|
|
2350
|
+
"""Read Arrow table from storage with telemetry.
|
|
2351
|
+
|
|
2352
|
+
Args:
|
|
2353
|
+
source: Storage source path.
|
|
2354
|
+
file_format: File format to read.
|
|
2355
|
+
storage_options: Optional storage options.
|
|
2356
|
+
|
|
2357
|
+
Returns:
|
|
2358
|
+
Tuple of (ArrowTable, StorageTelemetry).
|
|
2359
|
+
"""
|
|
2360
|
+
runtime = self.observability
|
|
2361
|
+
span = runtime.start_storage_span(
|
|
2362
|
+
"read", destination=stringify_storage_target(source), format_label=file_format
|
|
2363
|
+
)
|
|
2364
|
+
pipeline = self._storage_pipeline()
|
|
2365
|
+
try:
|
|
2366
|
+
table, telemetry = await pipeline.read_arrow_async(
|
|
2367
|
+
source, file_format=file_format, storage_options=storage_options
|
|
2368
|
+
)
|
|
2369
|
+
except Exception as exc:
|
|
2370
|
+
runtime.end_storage_span(span, error=exc)
|
|
2371
|
+
raise
|
|
2372
|
+
telemetry = runtime.annotate_storage_telemetry(telemetry)
|
|
2373
|
+
runtime.end_storage_span(span, telemetry=telemetry)
|
|
2374
|
+
return table, telemetry
|
|
2375
|
+
|
|
2376
|
+
|
|
2377
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
2378
|
+
class AsyncDataDictionaryBase(DataDictionaryDialectMixin, DataDictionaryMixin):
|
|
2379
|
+
"""Base class for asynchronous data dictionary implementations.
|
|
2380
|
+
|
|
2381
|
+
Uses Python-compatible class layouts for cross-module inheritance.
|
|
2382
|
+
Child classes define dialect as a class attribute.
|
|
2383
|
+
"""
|
|
2384
|
+
|
|
2385
|
+
dialect: "ClassVar[str]"
|
|
2386
|
+
"""Dialect identifier. Must be defined by subclasses as a class attribute."""
|
|
2387
|
+
|
|
2388
|
+
def __init__(self) -> None:
|
|
2389
|
+
self._version_cache: dict[int, VersionInfo | None] = {}
|
|
2390
|
+
self._version_fetch_attempted: set[int] = set()
|
|
2391
|
+
|
|
2392
|
+
async def get_metadata_capabilities(
|
|
2393
|
+
self, driver: Any, domains: "Sequence[str] | None" = None
|
|
2394
|
+
) -> "MetadataCapabilityProfile":
|
|
2395
|
+
"""Get data-dictionary capability profile.
|
|
2396
|
+
|
|
2397
|
+
Args:
|
|
2398
|
+
driver: Async database driver instance.
|
|
2399
|
+
domains: Optional metadata domains to report.
|
|
2400
|
+
|
|
2401
|
+
Returns:
|
|
2402
|
+
Capability profile. Base implementations report requested domains as unsupported.
|
|
2403
|
+
"""
|
|
2404
|
+
requested_domains: tuple[str, ...] = (
|
|
2405
|
+
"schemas",
|
|
2406
|
+
"objects",
|
|
2407
|
+
"tables",
|
|
2408
|
+
"columns",
|
|
2409
|
+
"constraints",
|
|
2410
|
+
"indexes",
|
|
2411
|
+
"views",
|
|
2412
|
+
"routines",
|
|
2413
|
+
"privileges",
|
|
2414
|
+
"dependencies",
|
|
2415
|
+
"ddl",
|
|
2416
|
+
)
|
|
2417
|
+
if domains is not None:
|
|
2418
|
+
requested_domains = tuple(domains)
|
|
2419
|
+
return MetadataCapabilityProfile.from_domains(self.dialect, type(self).__name__, requested_domains)
|
|
2420
|
+
|
|
2421
|
+
async def get_system_metadata_capabilities(
|
|
2422
|
+
self, driver: Any, domains: "Sequence[str] | None" = None
|
|
2423
|
+
) -> "tuple[SystemMetadataCapability, ...]":
|
|
2424
|
+
"""Get opt-in system metadata capability disclosures.
|
|
2425
|
+
|
|
2426
|
+
Args:
|
|
2427
|
+
driver: Async database driver instance.
|
|
2428
|
+
domains: Optional system metadata domains to report.
|
|
2429
|
+
|
|
2430
|
+
Returns:
|
|
2431
|
+
System metadata capabilities. Base implementations report requested domains as unsupported.
|
|
2432
|
+
"""
|
|
2433
|
+
requested_domains = DEFAULT_SYSTEM_METADATA_DOMAINS if domains is None else tuple(domains)
|
|
2434
|
+
return system_metadata_capabilities_from_domains(requested_domains)
|
|
2435
|
+
|
|
2436
|
+
async def get_schemas(self, driver: Any) -> "MetadataResult":
|
|
2437
|
+
"""Get schema metadata or an unsupported-domain result."""
|
|
2438
|
+
return self._unsupported_metadata("schemas")
|
|
2439
|
+
|
|
2440
|
+
async def get_objects(self, driver: Any, schema: "str | None" = None) -> "MetadataResult":
|
|
2441
|
+
"""Get database object metadata or an unsupported-domain result."""
|
|
2442
|
+
return self._unsupported_metadata("objects")
|
|
2443
|
+
|
|
2444
|
+
async def get_table_details(self, driver: Any, table: str, schema: "str | None" = None) -> "MetadataResult":
|
|
2445
|
+
"""Get rich table metadata or an unsupported-domain result."""
|
|
2446
|
+
return self._unsupported_metadata("tables")
|
|
2447
|
+
|
|
2448
|
+
async def get_constraints(
|
|
2449
|
+
self, driver: Any, table: "str | None" = None, schema: "str | None" = None
|
|
2450
|
+
) -> "MetadataResult":
|
|
2451
|
+
"""Get constraint metadata or an unsupported-domain result."""
|
|
2452
|
+
return self._unsupported_metadata("constraints")
|
|
2453
|
+
|
|
2454
|
+
async def get_views(self, driver: Any, schema: "str | None" = None) -> "MetadataResult":
|
|
2455
|
+
"""Get view metadata or an unsupported-domain result."""
|
|
2456
|
+
return self._unsupported_metadata("views")
|
|
2457
|
+
|
|
2458
|
+
async def get_routines(self, driver: Any, schema: "str | None" = None) -> "MetadataResult":
|
|
2459
|
+
"""Get routine metadata or an unsupported-domain result."""
|
|
2460
|
+
return self._unsupported_metadata("routines")
|
|
2461
|
+
|
|
2462
|
+
async def get_privileges(
|
|
2463
|
+
self, driver: Any, object_name: "str | None" = None, schema: "str | None" = None
|
|
2464
|
+
) -> "MetadataResult":
|
|
2465
|
+
"""Get privilege metadata or an unsupported-domain result."""
|
|
2466
|
+
return self._unsupported_metadata("privileges")
|
|
2467
|
+
|
|
2468
|
+
async def get_dependencies(
|
|
2469
|
+
self, driver: Any, object_name: "str | None" = None, schema: "str | None" = None
|
|
2470
|
+
) -> "MetadataResult":
|
|
2471
|
+
"""Get dependency metadata or an unsupported-domain result."""
|
|
2472
|
+
return self._unsupported_metadata("dependencies")
|
|
2473
|
+
|
|
2474
|
+
async def get_sequences(self, driver: Any, schema: "str | None" = None) -> "MetadataResult":
|
|
2475
|
+
"""Get sequence metadata or an unsupported-domain result."""
|
|
2476
|
+
return self._unsupported_metadata("sequences")
|
|
2477
|
+
|
|
2478
|
+
async def get_types(self, driver: Any, schema: "str | None" = None) -> "MetadataResult":
|
|
2479
|
+
"""Get user-defined type metadata or an unsupported-domain result."""
|
|
2480
|
+
return self._unsupported_metadata("types")
|
|
2481
|
+
|
|
2482
|
+
async def get_ddl(
|
|
2483
|
+
self,
|
|
2484
|
+
driver: Any,
|
|
2485
|
+
object_name: str,
|
|
2486
|
+
schema: "str | None" = None,
|
|
2487
|
+
*,
|
|
2488
|
+
object_type: str = "table",
|
|
2489
|
+
include_dependencies: bool = True,
|
|
2490
|
+
prefer_native: bool = True,
|
|
2491
|
+
redact: bool = True,
|
|
2492
|
+
target_dialect: "str | None" = None,
|
|
2493
|
+
) -> "DDLResult":
|
|
2494
|
+
"""Get object DDL or an explicit unsupported DDL result.
|
|
2495
|
+
|
|
2496
|
+
Public alias of :meth:`get_object_ddl` that accepts ``schema`` positionally.
|
|
2497
|
+
"""
|
|
2498
|
+
return await self.get_object_ddl(
|
|
2499
|
+
driver,
|
|
2500
|
+
object_name,
|
|
2501
|
+
schema=schema,
|
|
2502
|
+
object_type=object_type,
|
|
2503
|
+
include_dependencies=include_dependencies,
|
|
2504
|
+
prefer_native=prefer_native,
|
|
2505
|
+
redact=redact,
|
|
2506
|
+
target_dialect=target_dialect,
|
|
2507
|
+
)
|
|
2508
|
+
|
|
2509
|
+
async def get_object_ddl(
|
|
2510
|
+
self,
|
|
2511
|
+
driver: Any,
|
|
2512
|
+
object_name: str,
|
|
2513
|
+
*,
|
|
2514
|
+
schema: "str | None" = None,
|
|
2515
|
+
object_type: str = "table",
|
|
2516
|
+
include_dependencies: bool = True,
|
|
2517
|
+
prefer_native: bool = True,
|
|
2518
|
+
redact: bool = True,
|
|
2519
|
+
target_dialect: "str | None" = None,
|
|
2520
|
+
) -> "DDLResult":
|
|
2521
|
+
"""Get one object's DDL or an explicit unsupported DDL result.
|
|
2522
|
+
|
|
2523
|
+
``object_name`` and ``schema`` are caller input and follow the dialect's identifier
|
|
2524
|
+
normalization (quote a name to match it exactly). Native catalog DDL is preferred; table
|
|
2525
|
+
DDL is synthesized from catalog metadata when ``prefer_native`` is False, when a
|
|
2526
|
+
``target_dialect`` is requested, or when native DDL is unavailable.
|
|
2527
|
+
|
|
2528
|
+
Args:
|
|
2529
|
+
driver: Database driver instance.
|
|
2530
|
+
object_name: Object name.
|
|
2531
|
+
schema: Schema name, or None for the dialect default.
|
|
2532
|
+
object_type: Object kind such as ``table``, ``view``, or ``sequence``.
|
|
2533
|
+
include_dependencies: Whether native helpers should report dependencies.
|
|
2534
|
+
prefer_native: Prefer native catalog DDL over synthesized DDL.
|
|
2535
|
+
redact: Whether native helpers should redact sensitive values.
|
|
2536
|
+
target_dialect: Dialect to render or transpile the DDL into.
|
|
2537
|
+
|
|
2538
|
+
Returns:
|
|
2539
|
+
DDL result for the object.
|
|
2540
|
+
"""
|
|
2541
|
+
resolved_name, resolved_schema = type(self).resolve_ddl_object_name(self, driver, object_name, schema)
|
|
2542
|
+
return await self._get_exact_object_ddl(
|
|
2543
|
+
driver,
|
|
2544
|
+
resolved_name,
|
|
2545
|
+
schema=resolved_schema,
|
|
2546
|
+
object_type=object_type,
|
|
2547
|
+
include_dependencies=include_dependencies,
|
|
2548
|
+
prefer_native=prefer_native,
|
|
2549
|
+
redact=redact,
|
|
2550
|
+
target_dialect=target_dialect,
|
|
2551
|
+
)
|
|
2552
|
+
|
|
2553
|
+
async def get_schema_ddl(
|
|
2554
|
+
self,
|
|
2555
|
+
driver: Any,
|
|
2556
|
+
schema: "str | None" = None,
|
|
2557
|
+
*,
|
|
2558
|
+
include_domains: "Sequence[str] | None" = None,
|
|
2559
|
+
exclude_domains: "Sequence[str] | None" = None,
|
|
2560
|
+
exclude_tables: "Sequence[str] | None" = (),
|
|
2561
|
+
direction: "Literal['create', 'drop']" = "create",
|
|
2562
|
+
include_dependencies: bool = True,
|
|
2563
|
+
prefer_native: bool = True,
|
|
2564
|
+
redact: bool = True,
|
|
2565
|
+
target_dialect: "str | None" = None,
|
|
2566
|
+
) -> "MetadataResult":
|
|
2567
|
+
"""Get schema DDL items in topological dependency order.
|
|
2568
|
+
|
|
2569
|
+
When ``prefer_native`` is set and no ``target_dialect`` is requested, adapters with a
|
|
2570
|
+
native schema DDL source supply the objects; tables whose native DDL is not faithful are
|
|
2571
|
+
synthesized from catalog metadata. Otherwise types, sequences, tables, and views are
|
|
2572
|
+
collected, and tables are synthesized from schema-wide catalog queries. ``direction="drop"``
|
|
2573
|
+
only collects object identities and dependency edges; it never synthesizes table DDL.
|
|
2574
|
+
Domains that cannot be collected are reported in the result warnings.
|
|
2575
|
+
|
|
2576
|
+
Args:
|
|
2577
|
+
driver: Database driver instance.
|
|
2578
|
+
schema: Schema name, or None for the dialect default.
|
|
2579
|
+
include_domains: Domains to include (``tables``, ``views``, ``sequences``, ``types``, ...).
|
|
2580
|
+
exclude_domains: Domains to exclude.
|
|
2581
|
+
exclude_tables: Table names to omit, matched as bare, unquoted, case-insensitive names
|
|
2582
|
+
with any schema qualification stripped.
|
|
2583
|
+
direction: ``create`` for CREATE statements in dependency order, ``drop`` for
|
|
2584
|
+
``DROP ... IF EXISTS`` statements in reverse dependency order.
|
|
2585
|
+
include_dependencies: Collect foreign keys and dependencies to order the output.
|
|
2586
|
+
prefer_native: Prefer native catalog DDL over synthesized DDL.
|
|
2587
|
+
redact: Whether native helpers should redact sensitive values.
|
|
2588
|
+
target_dialect: Dialect to render or transpile the DDL into.
|
|
2589
|
+
|
|
2590
|
+
Returns:
|
|
2591
|
+
Schema DDL result.
|
|
2592
|
+
"""
|
|
2593
|
+
warnings: list[str] = []
|
|
2594
|
+
exact_schema, getter_schema = self._resolve_schema_ddl_input(driver, schema)
|
|
2595
|
+
native_items: list[DDLResult] | None = None
|
|
2596
|
+
loaded_foreign_keys: list[Any] | None = None
|
|
2597
|
+
if prefer_native and target_dialect is None:
|
|
2598
|
+
native_items = await self._get_native_schema_ddl(
|
|
2599
|
+
driver, exact_schema, include_dependencies=include_dependencies, redact=redact
|
|
2600
|
+
)
|
|
2601
|
+
if native_items is not None:
|
|
2602
|
+
ddl_results = (
|
|
2603
|
+
native_items
|
|
2604
|
+
if direction == "drop"
|
|
2605
|
+
else await self._replace_unfaithful_native_tables(driver, getter_schema, native_items, warnings)
|
|
2606
|
+
)
|
|
2607
|
+
else:
|
|
2608
|
+
ddl_results, loaded_foreign_keys = await self._collect_synthesized_schema_ddl(
|
|
2609
|
+
driver,
|
|
2610
|
+
getter_schema,
|
|
2611
|
+
default_schema=exact_schema,
|
|
2612
|
+
domains=self._schema_ddl_collect_domains(include_domains, exclude_domains),
|
|
2613
|
+
exclude_tables=exclude_tables,
|
|
2614
|
+
direction=direction,
|
|
2615
|
+
include_dependencies=include_dependencies,
|
|
2616
|
+
prefer_native=prefer_native,
|
|
2617
|
+
redact=redact,
|
|
2618
|
+
target_dialect=target_dialect,
|
|
2619
|
+
warnings=warnings,
|
|
2620
|
+
)
|
|
2621
|
+
foreign_keys: list[Any] = []
|
|
2622
|
+
dependency_items: tuple[Any, ...] = ()
|
|
2623
|
+
if include_dependencies:
|
|
2624
|
+
if loaded_foreign_keys is None:
|
|
2625
|
+
loaded_foreign_keys = list(await self.get_foreign_keys(driver, table=None, schema=getter_schema))
|
|
2626
|
+
foreign_keys = loaded_foreign_keys
|
|
2627
|
+
dependencies = await self.get_dependencies(driver, schema=getter_schema)
|
|
2628
|
+
if dependencies.capability.support == MetadataSupport.SUPPORTED:
|
|
2629
|
+
dependency_items = dependencies.items
|
|
2630
|
+
return self._finalize_schema_ddl_results(
|
|
2631
|
+
ddl_results,
|
|
2632
|
+
foreign_keys=foreign_keys,
|
|
2633
|
+
dependency_items=dependency_items,
|
|
2634
|
+
include_domains=include_domains,
|
|
2635
|
+
exclude_domains=exclude_domains,
|
|
2636
|
+
exclude_tables=exclude_tables,
|
|
2637
|
+
direction=direction,
|
|
2638
|
+
target_dialect=target_dialect,
|
|
2639
|
+
warnings=tuple(warnings),
|
|
2640
|
+
)
|
|
2641
|
+
|
|
2642
|
+
async def get_table_profile(
|
|
2643
|
+
self,
|
|
2644
|
+
driver: Any,
|
|
2645
|
+
table: str,
|
|
2646
|
+
schema: "str | None" = None,
|
|
2647
|
+
*,
|
|
2648
|
+
sample_size: int = 1000,
|
|
2649
|
+
target_dialect: "str | None" = None,
|
|
2650
|
+
) -> "list[ColumnProfileMetadata]":
|
|
2651
|
+
"""Profile live table columns and infer refined SQL types from existing data.
|
|
2652
|
+
|
|
2653
|
+
Query failures (for example missing privileges) propagate to the caller.
|
|
2654
|
+
"""
|
|
2655
|
+
resolved_table, resolved_schema = type(self).resolve_ddl_object_name(self, driver, table, schema)
|
|
2656
|
+
columns = await self.get_columns(
|
|
2657
|
+
driver,
|
|
2658
|
+
table=type(self).exact_catalog_identifier(self, driver, resolved_table),
|
|
2659
|
+
schema=type(self).exact_catalog_identifier(self, driver, resolved_schema)
|
|
2660
|
+
if resolved_schema is not None
|
|
2661
|
+
else None,
|
|
2662
|
+
)
|
|
2663
|
+
if not columns:
|
|
2664
|
+
return []
|
|
2665
|
+
stats_rows = await driver.select(self._build_table_profile_sql(resolved_table, columns, schema=resolved_schema))
|
|
2666
|
+
stats_row: Mapping[str, Any] | None = stats_rows[0] if stats_rows else None
|
|
2667
|
+
sample_rows: list[Mapping[str, Any]] = list(
|
|
2668
|
+
await driver.select(
|
|
2669
|
+
self._build_table_sample_sql(resolved_table, schema=resolved_schema, sample_size=sample_size)
|
|
2670
|
+
)
|
|
2671
|
+
)
|
|
2672
|
+
return self._compile_column_profiles(columns, stats_row, sample_rows, target_dialect=target_dialect)
|
|
2673
|
+
|
|
2674
|
+
async def infer_table_ddl_from_data(
|
|
2675
|
+
self,
|
|
2676
|
+
driver: Any,
|
|
2677
|
+
table: str,
|
|
2678
|
+
schema: "str | None" = None,
|
|
2679
|
+
*,
|
|
2680
|
+
target_table: "str | None" = None,
|
|
2681
|
+
target_dialect: "str | None" = None,
|
|
2682
|
+
sample_size: int = 1000,
|
|
2683
|
+
primary_key: "str | Sequence[str] | None" = None,
|
|
2684
|
+
) -> "DDLResult":
|
|
2685
|
+
"""Synthesize a refined table DDLResult by profiling live table data."""
|
|
2686
|
+
profiles = await self.get_table_profile(
|
|
2687
|
+
driver, table, schema=schema, sample_size=sample_size, target_dialect=target_dialect
|
|
2688
|
+
)
|
|
2689
|
+
resolved_table, resolved_schema = type(self).resolve_ddl_object_name(self, driver, table, schema)
|
|
2690
|
+
if not profiles:
|
|
2691
|
+
return self._unsupported_ddl(target_table or resolved_table, schema=resolved_schema, object_type="table")
|
|
2692
|
+
return self._compile_profiled_table_ddl(
|
|
2693
|
+
resolved_table,
|
|
2694
|
+
profiles,
|
|
2695
|
+
schema=resolved_schema,
|
|
2696
|
+
target_table=target_table,
|
|
2697
|
+
target_dialect=target_dialect,
|
|
2698
|
+
primary_key=primary_key,
|
|
2699
|
+
)
|
|
2700
|
+
|
|
2701
|
+
async def get_system_metadata(
|
|
2702
|
+
self, driver: Any, request: "SystemMetadataRequest | str | None" = None, **kwargs: Any
|
|
2703
|
+
) -> "SystemMetadataResult":
|
|
2704
|
+
"""Get opt-in system metadata or a gated/unsupported result."""
|
|
2705
|
+
metadata_request = ensure_system_metadata_request(request, **kwargs)
|
|
2706
|
+
capability = unsupported_system_metadata_capability(metadata_request.domain)
|
|
2707
|
+
return system_metadata_gated_result(metadata_request, capability)
|
|
2708
|
+
|
|
2709
|
+
@abstractmethod
|
|
2710
|
+
async def get_version(self, driver: Any) -> "VersionInfo | None":
|
|
2711
|
+
"""Get database version information.
|
|
2712
|
+
|
|
2713
|
+
Args:
|
|
2714
|
+
driver: Async database driver instance
|
|
2715
|
+
|
|
2716
|
+
Returns:
|
|
2717
|
+
Version information or None if detection fails
|
|
2718
|
+
"""
|
|
2719
|
+
|
|
2720
|
+
@abstractmethod
|
|
2721
|
+
async def get_feature_flag(self, driver: Any, feature: str) -> bool:
|
|
2722
|
+
"""Check if database supports a specific feature.
|
|
2723
|
+
|
|
2724
|
+
Args:
|
|
2725
|
+
driver: Async database driver instance
|
|
2726
|
+
feature: Feature name to check
|
|
2727
|
+
|
|
2728
|
+
Returns:
|
|
2729
|
+
True if feature is supported, False otherwise
|
|
2730
|
+
"""
|
|
2731
|
+
|
|
2732
|
+
@abstractmethod
|
|
2733
|
+
async def get_optimal_type(self, driver: Any, type_category: str) -> str:
|
|
2734
|
+
"""Get optimal database type for a category.
|
|
2735
|
+
|
|
2736
|
+
Args:
|
|
2737
|
+
driver: Async database driver instance
|
|
2738
|
+
type_category: Type category
|
|
2739
|
+
|
|
2740
|
+
Returns:
|
|
2741
|
+
Database-specific type name
|
|
2742
|
+
"""
|
|
2743
|
+
|
|
2744
|
+
@abstractmethod
|
|
2745
|
+
async def get_tables(self, driver: Any, schema: "str | None" = None) -> "list[TableMetadata]":
|
|
2746
|
+
"""Get list of tables in schema.
|
|
2747
|
+
|
|
2748
|
+
Args:
|
|
2749
|
+
driver: Async database driver instance
|
|
2750
|
+
schema: Schema name (None for default)
|
|
2751
|
+
|
|
2752
|
+
Returns:
|
|
2753
|
+
List of table metadata dictionaries
|
|
2754
|
+
"""
|
|
2755
|
+
|
|
2756
|
+
@abstractmethod
|
|
2757
|
+
async def get_columns(
|
|
2758
|
+
self, driver: Any, table: "str | None" = None, schema: "str | None" = None
|
|
2759
|
+
) -> "list[ColumnMetadata]":
|
|
2760
|
+
"""Get column information for a table or schema.
|
|
2761
|
+
|
|
2762
|
+
Args:
|
|
2763
|
+
driver: Async database driver instance
|
|
2764
|
+
table: Table name (None to fetch columns for all tables in schema)
|
|
2765
|
+
schema: Schema name (None for default)
|
|
2766
|
+
|
|
2767
|
+
Returns:
|
|
2768
|
+
List of column metadata dictionaries
|
|
2769
|
+
"""
|
|
2770
|
+
|
|
2771
|
+
@abstractmethod
|
|
2772
|
+
async def get_indexes(
|
|
2773
|
+
self, driver: Any, table: "str | None" = None, schema: "str | None" = None
|
|
2774
|
+
) -> "list[IndexMetadata]":
|
|
2775
|
+
"""Get index information for a table or schema.
|
|
2776
|
+
|
|
2777
|
+
Args:
|
|
2778
|
+
driver: Async database driver instance
|
|
2779
|
+
table: Table name (None to fetch indexes for all tables in schema)
|
|
2780
|
+
schema: Schema name (None for default)
|
|
2781
|
+
|
|
2782
|
+
Returns:
|
|
2783
|
+
List of index metadata dictionaries
|
|
2784
|
+
"""
|
|
2785
|
+
|
|
2786
|
+
@abstractmethod
|
|
2787
|
+
async def get_foreign_keys(
|
|
2788
|
+
self, driver: Any, table: "str | None" = None, schema: "str | None" = None
|
|
2789
|
+
) -> "list[ForeignKeyMetadata]":
|
|
2790
|
+
"""Get foreign key metadata.
|
|
2791
|
+
|
|
2792
|
+
Args:
|
|
2793
|
+
driver: Async database driver instance
|
|
2794
|
+
table: Optional table name filter
|
|
2795
|
+
schema: Optional schema name filter
|
|
2796
|
+
|
|
2797
|
+
Returns:
|
|
2798
|
+
List of foreign key metadata
|
|
2799
|
+
"""
|
|
2800
|
+
|
|
2801
|
+
async def _get_native_object_ddl(
|
|
2802
|
+
self,
|
|
2803
|
+
driver: Any,
|
|
2804
|
+
object_name: str,
|
|
2805
|
+
*,
|
|
2806
|
+
schema: "str | None",
|
|
2807
|
+
object_type: str,
|
|
2808
|
+
include_dependencies: bool,
|
|
2809
|
+
redact: bool,
|
|
2810
|
+
) -> "DDLResult | None":
|
|
2811
|
+
"""Return native catalog DDL for one object, or None when the adapter has no native source.
|
|
2812
|
+
|
|
2813
|
+
Adapters with native DDL override this hook. ``object_name`` and ``schema`` are exact
|
|
2814
|
+
catalog names and must not be normalized again. Return an unsupported DDLResult with
|
|
2815
|
+
warnings when native DDL exists in principle but is unavailable or not faithful for this
|
|
2816
|
+
object; tables then fall back to synthesized DDL carrying those warnings.
|
|
2817
|
+
"""
|
|
2818
|
+
return None
|
|
2819
|
+
|
|
2820
|
+
async def _get_native_schema_ddl(
|
|
2821
|
+
self, driver: Any, schema: "str | None", *, include_dependencies: bool, redact: bool
|
|
2822
|
+
) -> "list[DDLResult] | None":
|
|
2823
|
+
"""Return native CREATE DDL for every schema object, or None when the adapter has no native source.
|
|
2824
|
+
|
|
2825
|
+
Adapters with a schema-wide native DDL source override this hook. Returned items may carry
|
|
2826
|
+
dependency edges and a ``DDL_PARENT_TABLE_CONTEXT_KEY`` context entry for indexes and
|
|
2827
|
+
triggers. Tables returned as unsupported are replaced by synthesized DDL. Filtering,
|
|
2828
|
+
exclusion, ordering, transpiling, and DROP generation are handled by the base class.
|
|
2829
|
+
"""
|
|
2830
|
+
return None
|
|
2831
|
+
|
|
2832
|
+
async def _get_exact_object_ddl(
|
|
2833
|
+
self,
|
|
2834
|
+
driver: Any,
|
|
2835
|
+
object_name: str,
|
|
2836
|
+
*,
|
|
2837
|
+
schema: "str | None",
|
|
2838
|
+
object_type: str,
|
|
2839
|
+
include_dependencies: bool,
|
|
2840
|
+
prefer_native: bool,
|
|
2841
|
+
redact: bool,
|
|
2842
|
+
target_dialect: "str | None",
|
|
2843
|
+
) -> "DDLResult":
|
|
2844
|
+
"""Resolve one object's DDL from exact catalog names, choosing native or synthesized DDL."""
|
|
2845
|
+
is_table = self._is_table_object_type(object_type)
|
|
2846
|
+
if is_table and (not prefer_native or target_dialect is not None):
|
|
2847
|
+
return await self._synthesize_table_ddl(driver, object_name, schema=schema, target_dialect=target_dialect)
|
|
2848
|
+
native = await self._get_native_object_ddl(
|
|
2849
|
+
driver,
|
|
2850
|
+
object_name,
|
|
2851
|
+
schema=schema,
|
|
2852
|
+
object_type=object_type,
|
|
2853
|
+
include_dependencies=include_dependencies,
|
|
2854
|
+
redact=redact,
|
|
2855
|
+
)
|
|
2856
|
+
if native is not None and native.status == MetadataSupport.SUPPORTED and native.ddl:
|
|
2857
|
+
return self._transpile_ddl_result(native, target_dialect=target_dialect)
|
|
2858
|
+
if is_table:
|
|
2859
|
+
return await self._synthesize_table_ddl(
|
|
2860
|
+
driver,
|
|
2861
|
+
object_name,
|
|
2862
|
+
schema=schema,
|
|
2863
|
+
target_dialect=target_dialect,
|
|
2864
|
+
warnings=native.warnings if native is not None else (),
|
|
2865
|
+
)
|
|
2866
|
+
if native is not None:
|
|
2867
|
+
return native
|
|
2868
|
+
return self._unsupported_ddl(object_name, schema=schema, object_type=object_type)
|
|
2869
|
+
|
|
2870
|
+
async def _replace_unfaithful_native_tables(
|
|
2871
|
+
self, driver: Any, schema: "str | None", items: "list[DDLResult]", warnings: "list[str]"
|
|
2872
|
+
) -> "list[DDLResult]":
|
|
2873
|
+
"""Replace unsupported native table items with DDL synthesized from schema-wide catalog queries."""
|
|
2874
|
+
replace_names = [
|
|
2875
|
+
item.identity.name
|
|
2876
|
+
for item in items
|
|
2877
|
+
if self._is_table_object_type(item.identity.object_type) and item.status != MetadataSupport.SUPPORTED
|
|
2878
|
+
]
|
|
2879
|
+
if not replace_names:
|
|
2880
|
+
return items
|
|
2881
|
+
catalog = await self._load_table_catalog(driver, schema, replace_names, warnings)
|
|
2882
|
+
source_dialect = type(self).resolve_ddl_dialect(self, driver)
|
|
2883
|
+
resolved: list[DDLResult] = []
|
|
2884
|
+
replaced_tables: set[tuple[str, str]] = set()
|
|
2885
|
+
for item in items:
|
|
2886
|
+
if self._is_table_object_type(item.identity.object_type) and item.status != MetadataSupport.SUPPORTED:
|
|
2887
|
+
table_schema = (
|
|
2888
|
+
None
|
|
2889
|
+
if schema is None
|
|
2890
|
+
and item.identity.schema is not None
|
|
2891
|
+
and item.identity.schema.lower() == "main"
|
|
2892
|
+
and _sqlglot_dialect(source_dialect) in {"sqlite", "duckdb"}
|
|
2893
|
+
else item.identity.schema
|
|
2894
|
+
)
|
|
2895
|
+
synthesized = self._synthesize_table_from_catalog(
|
|
2896
|
+
item.identity.name,
|
|
2897
|
+
table_schema,
|
|
2898
|
+
catalog,
|
|
2899
|
+
source_dialect=source_dialect,
|
|
2900
|
+
target_dialect=None,
|
|
2901
|
+
warnings=item.warnings,
|
|
2902
|
+
)
|
|
2903
|
+
resolved.append(self._with_dependencies(synthesized, item.dependencies))
|
|
2904
|
+
replaced_tables.add(((item.identity.schema or "").lower(), item.identity.name.lower()))
|
|
2905
|
+
continue
|
|
2906
|
+
resolved.append(item)
|
|
2907
|
+
return self._replace_synthesized_table_dependents(resolved, replaced_tables)
|
|
2908
|
+
|
|
2909
|
+
async def _collect_synthesized_schema_ddl(
|
|
2910
|
+
self,
|
|
2911
|
+
driver: Any,
|
|
2912
|
+
schema: "str | None",
|
|
2913
|
+
*,
|
|
2914
|
+
default_schema: "str | None" = None,
|
|
2915
|
+
domains: "set[str]",
|
|
2916
|
+
exclude_tables: "Sequence[str] | None",
|
|
2917
|
+
direction: "Literal['create', 'drop']",
|
|
2918
|
+
include_dependencies: bool,
|
|
2919
|
+
prefer_native: bool,
|
|
2920
|
+
redact: bool,
|
|
2921
|
+
target_dialect: "str | None",
|
|
2922
|
+
warnings: "list[str]",
|
|
2923
|
+
) -> "tuple[list[DDLResult], list[Any] | None]":
|
|
2924
|
+
"""Collect types, sequences, tables, and views for schema DDL.
|
|
2925
|
+
|
|
2926
|
+
Tables are synthesized from one schema-wide query per catalog domain. For ``drop`` only
|
|
2927
|
+
table identities are collected. Returns the DDL results plus the schema foreign keys when
|
|
2928
|
+
they were already loaded for every table, so callers can reuse them for ordering.
|
|
2929
|
+
"""
|
|
2930
|
+
resolved_default_schema = default_schema if default_schema is not None else schema
|
|
2931
|
+
source_dialect = type(self).resolve_ddl_dialect(self, driver)
|
|
2932
|
+
excluded_names = self._normalize_excluded_table_names(exclude_tables)
|
|
2933
|
+
results: list[DDLResult] = []
|
|
2934
|
+
loaded_foreign_keys: list[Any] | None = None
|
|
2935
|
+
grouped_columns: dict[str, list[Any]] = {}
|
|
2936
|
+
if "types" in domains:
|
|
2937
|
+
types = await self.get_types(driver, schema=schema)
|
|
2938
|
+
if types.capability.support == MetadataSupport.SUPPORTED:
|
|
2939
|
+
for row in types.items:
|
|
2940
|
+
type_ddl = self._build_type_ddl_from_row(
|
|
2941
|
+
row, default_schema=resolved_default_schema, dialect=source_dialect
|
|
2942
|
+
)
|
|
2943
|
+
if type_ddl is not None:
|
|
2944
|
+
results.append(type_ddl)
|
|
2945
|
+
else:
|
|
2946
|
+
warnings.append(self._uncollected_domain_warning("types", source_dialect))
|
|
2947
|
+
if "sequences" in domains:
|
|
2948
|
+
sequences = await self.get_sequences(driver, schema=schema)
|
|
2949
|
+
if sequences.capability.support == MetadataSupport.SUPPORTED:
|
|
2950
|
+
for row in sequences.items:
|
|
2951
|
+
sequence_ddl = self._build_sequence_ddl_from_row(
|
|
2952
|
+
row, default_schema=resolved_default_schema, dialect=source_dialect
|
|
2953
|
+
)
|
|
2954
|
+
if sequence_ddl is None:
|
|
2955
|
+
continue
|
|
2956
|
+
if direction == "create" and prefer_native and target_dialect is None:
|
|
2957
|
+
native_sequence = await self._get_native_object_ddl(
|
|
2958
|
+
driver,
|
|
2959
|
+
sequence_ddl.identity.name,
|
|
2960
|
+
schema=sequence_ddl.identity.schema,
|
|
2961
|
+
object_type="sequence",
|
|
2962
|
+
include_dependencies=include_dependencies,
|
|
2963
|
+
redact=redact,
|
|
2964
|
+
)
|
|
2965
|
+
if native_sequence is not None and native_sequence.status == MetadataSupport.SUPPORTED:
|
|
2966
|
+
sequence_ddl = native_sequence
|
|
2967
|
+
results.append(sequence_ddl)
|
|
2968
|
+
else:
|
|
2969
|
+
warnings.append(self._uncollected_domain_warning("sequences", source_dialect))
|
|
2970
|
+
if "tables" in domains:
|
|
2971
|
+
table_results, grouped_columns, loaded_foreign_keys = await self._collect_schema_table_ddl(
|
|
2972
|
+
driver,
|
|
2973
|
+
schema,
|
|
2974
|
+
default_schema=resolved_default_schema,
|
|
2975
|
+
excluded_names=excluded_names,
|
|
2976
|
+
direction=direction,
|
|
2977
|
+
include_dependencies=include_dependencies,
|
|
2978
|
+
prefer_native=prefer_native,
|
|
2979
|
+
redact=redact,
|
|
2980
|
+
target_dialect=target_dialect,
|
|
2981
|
+
source_dialect=source_dialect,
|
|
2982
|
+
warnings=warnings,
|
|
2983
|
+
)
|
|
2984
|
+
results.extend(table_results)
|
|
2985
|
+
if "views" in domains:
|
|
2986
|
+
views = await self.get_views(driver, schema=schema)
|
|
2987
|
+
if views.capability.support == MetadataSupport.SUPPORTED:
|
|
2988
|
+
for view_row in views.items:
|
|
2989
|
+
view_ddl = self._build_view_ddl_from_row(
|
|
2990
|
+
view_row, default_schema=resolved_default_schema, dialect=source_dialect
|
|
2991
|
+
)
|
|
2992
|
+
if view_ddl is None:
|
|
2993
|
+
warnings.append(
|
|
2994
|
+
f"Omitted a view from schema DDL because its definition is unavailable: {view_row!r}"
|
|
2995
|
+
)
|
|
2996
|
+
continue
|
|
2997
|
+
results.append(view_ddl)
|
|
2998
|
+
else:
|
|
2999
|
+
warnings.append(self._uncollected_domain_warning("views", source_dialect))
|
|
3000
|
+
return (
|
|
3001
|
+
self._link_schema_references(results, self._column_reference_text(grouped_columns)),
|
|
3002
|
+
loaded_foreign_keys,
|
|
3003
|
+
)
|
|
3004
|
+
|
|
3005
|
+
async def _collect_schema_table_ddl(
|
|
3006
|
+
self,
|
|
3007
|
+
driver: Any,
|
|
3008
|
+
schema: "str | None",
|
|
3009
|
+
*,
|
|
3010
|
+
default_schema: "str | None" = None,
|
|
3011
|
+
excluded_names: "set[str]",
|
|
3012
|
+
direction: "Literal['create', 'drop']",
|
|
3013
|
+
include_dependencies: bool,
|
|
3014
|
+
prefer_native: bool,
|
|
3015
|
+
redact: bool,
|
|
3016
|
+
target_dialect: "str | None",
|
|
3017
|
+
source_dialect: "str | None",
|
|
3018
|
+
warnings: "list[str]",
|
|
3019
|
+
) -> "tuple[list[DDLResult], dict[str, list[Any]], list[Any] | None]":
|
|
3020
|
+
"""Collect table DDL (or identities for drop) with schema-wide catalog queries.
|
|
3021
|
+
|
|
3022
|
+
Returns the table results, catalog columns grouped by table, and the schema foreign keys
|
|
3023
|
+
when they were loaded for every table.
|
|
3024
|
+
"""
|
|
3025
|
+
resolved_default_schema = default_schema if default_schema is not None else schema
|
|
3026
|
+
results: list[DDLResult] = []
|
|
3027
|
+
loaded_foreign_keys: list[Any] | None = None
|
|
3028
|
+
grouped_columns: dict[str, list[Any]] = {}
|
|
3029
|
+
table_refs: list[tuple[str, str | None]] = []
|
|
3030
|
+
for table_item in await self.get_tables(driver, schema=schema):
|
|
3031
|
+
table_name, table_schema = self._extract_table_name_and_schema(
|
|
3032
|
+
table_item, default_schema=resolved_default_schema
|
|
3033
|
+
)
|
|
3034
|
+
if table_name and table_name.lower() not in excluded_names:
|
|
3035
|
+
table_refs.append((table_name, table_schema))
|
|
3036
|
+
table_names = [name for name, _ in table_refs]
|
|
3037
|
+
if direction == "drop":
|
|
3038
|
+
columns = await self.get_columns(driver, table=None, schema=schema)
|
|
3039
|
+
grouped_columns = self._group_rows_by_table(columns, table_names) or {}
|
|
3040
|
+
results.extend(
|
|
3041
|
+
self._catalog_object_identity_result(name, "table", table_schema, source_dialect)
|
|
3042
|
+
for name, table_schema in table_refs
|
|
3043
|
+
)
|
|
3044
|
+
else:
|
|
3045
|
+
native_tables: dict[str, DDLResult] = {}
|
|
3046
|
+
native_warnings: dict[str, tuple[str, ...]] = {}
|
|
3047
|
+
if prefer_native and target_dialect is None:
|
|
3048
|
+
for name, table_schema in table_refs:
|
|
3049
|
+
native = await self._get_native_object_ddl(
|
|
3050
|
+
driver,
|
|
3051
|
+
name,
|
|
3052
|
+
schema=table_schema,
|
|
3053
|
+
object_type="table",
|
|
3054
|
+
include_dependencies=include_dependencies,
|
|
3055
|
+
redact=redact,
|
|
3056
|
+
)
|
|
3057
|
+
if native is not None and native.status == MetadataSupport.SUPPORTED and native.ddl:
|
|
3058
|
+
native_tables[name] = native
|
|
3059
|
+
elif native is not None:
|
|
3060
|
+
native_warnings[name] = native.warnings
|
|
3061
|
+
pending = [name for name in table_names if name not in native_tables]
|
|
3062
|
+
catalog: dict[str, dict[str, list[Any]]] = {}
|
|
3063
|
+
if pending:
|
|
3064
|
+
catalog = await self._load_table_catalog(driver, schema, pending, warnings)
|
|
3065
|
+
grouped_columns = catalog["columns"]
|
|
3066
|
+
if len(pending) == len(table_names):
|
|
3067
|
+
loaded_foreign_keys = [fk for rows in catalog["foreign_keys"].values() for fk in rows]
|
|
3068
|
+
for name, table_schema in table_refs:
|
|
3069
|
+
table_result = native_tables.get(name)
|
|
3070
|
+
if table_result is None:
|
|
3071
|
+
table_result = self._synthesize_table_from_catalog(
|
|
3072
|
+
name,
|
|
3073
|
+
table_schema,
|
|
3074
|
+
catalog,
|
|
3075
|
+
source_dialect=source_dialect,
|
|
3076
|
+
target_dialect=target_dialect,
|
|
3077
|
+
warnings=native_warnings.get(name, ()),
|
|
3078
|
+
)
|
|
3079
|
+
results.append(table_result)
|
|
3080
|
+
return (results, grouped_columns, loaded_foreign_keys)
|
|
3081
|
+
|
|
3082
|
+
async def _load_table_catalog(
|
|
3083
|
+
self, driver: Any, schema: "str | None", table_names: "list[str]", warnings: "list[str]"
|
|
3084
|
+
) -> "dict[str, dict[str, list[Any]]]":
|
|
3085
|
+
"""Load columns, constraints, foreign keys, and indexes for ``table_names`` grouped by table.
|
|
3086
|
+
|
|
3087
|
+
Each domain is fetched with one schema-wide call; a domain whose rows do not name their
|
|
3088
|
+
table falls back to one call per table.
|
|
3089
|
+
"""
|
|
3090
|
+
columns = await self.get_columns(driver, table=None, schema=schema)
|
|
3091
|
+
constraints_result = await self.get_constraints(driver, table=None, schema=schema)
|
|
3092
|
+
warnings.extend(constraints_result.warnings)
|
|
3093
|
+
constraints = (
|
|
3094
|
+
constraints_result.items if constraints_result.capability.support == MetadataSupport.SUPPORTED else ()
|
|
3095
|
+
)
|
|
3096
|
+
foreign_keys = await self.get_foreign_keys(driver, table=None, schema=schema)
|
|
3097
|
+
indexes = await self.get_indexes(driver, table=None, schema=schema)
|
|
3098
|
+
catalog: dict[str, dict[str, list[Any]]] = {}
|
|
3099
|
+
for domain, rows in (
|
|
3100
|
+
("columns", columns),
|
|
3101
|
+
("constraints", constraints),
|
|
3102
|
+
("foreign_keys", foreign_keys),
|
|
3103
|
+
("indexes", indexes),
|
|
3104
|
+
):
|
|
3105
|
+
grouped = self._group_rows_by_table(rows, table_names)
|
|
3106
|
+
if grouped is None:
|
|
3107
|
+
grouped = {}
|
|
3108
|
+
for table_name in table_names:
|
|
3109
|
+
grouped[table_name] = await self._load_table_rows(driver, domain, table_name, schema)
|
|
3110
|
+
catalog[domain] = grouped
|
|
3111
|
+
return catalog
|
|
3112
|
+
|
|
3113
|
+
async def _load_table_rows(self, driver: Any, domain: str, table_name: str, schema: "str | None") -> "list[Any]":
|
|
3114
|
+
"""Load one catalog domain for one table using its exact catalog name."""
|
|
3115
|
+
lookup_table = type(self).exact_catalog_identifier(self, driver, table_name)
|
|
3116
|
+
if domain == "columns":
|
|
3117
|
+
return list(await self.get_columns(driver, table=lookup_table, schema=schema))
|
|
3118
|
+
if domain == "foreign_keys":
|
|
3119
|
+
return list(await self.get_foreign_keys(driver, table=lookup_table, schema=schema))
|
|
3120
|
+
if domain == "indexes":
|
|
3121
|
+
return list(await self.get_indexes(driver, table=lookup_table, schema=schema))
|
|
3122
|
+
constraints_result = await self.get_constraints(driver, table=lookup_table, schema=schema)
|
|
3123
|
+
if constraints_result.capability.support != MetadataSupport.SUPPORTED:
|
|
3124
|
+
return []
|
|
3125
|
+
return list(constraints_result.items)
|
|
3126
|
+
|
|
3127
|
+
async def _synthesize_table_ddl(
|
|
3128
|
+
self,
|
|
3129
|
+
driver: Any,
|
|
3130
|
+
table_name: str,
|
|
3131
|
+
*,
|
|
3132
|
+
schema: "str | None" = None,
|
|
3133
|
+
target_dialect: "str | None" = None,
|
|
3134
|
+
warnings: tuple[str, ...] = (),
|
|
3135
|
+
) -> "DDLResult":
|
|
3136
|
+
"""Synthesize table DDL from exact catalog names using columns, constraints, foreign keys, and indexes."""
|
|
3137
|
+
lookup_table = type(self).exact_catalog_identifier(self, driver, table_name)
|
|
3138
|
+
lookup_schema = type(self).exact_catalog_identifier(self, driver, schema) if schema is not None else None
|
|
3139
|
+
columns = await self.get_columns(driver, table=lookup_table, schema=lookup_schema)
|
|
3140
|
+
if not columns:
|
|
3141
|
+
return self._unsupported_ddl(table_name, schema=schema, object_type="table", warnings=warnings)
|
|
3142
|
+
constraints_result = await self.get_constraints(driver, table=lookup_table, schema=lookup_schema)
|
|
3143
|
+
constraints = (
|
|
3144
|
+
constraints_result.items if constraints_result.capability.support == MetadataSupport.SUPPORTED else ()
|
|
3145
|
+
)
|
|
3146
|
+
warnings = (*warnings, *constraints_result.warnings)
|
|
3147
|
+
foreign_keys = await self.get_foreign_keys(driver, table=lookup_table, schema=lookup_schema)
|
|
3148
|
+
indexes = await self.get_indexes(driver, table=lookup_table, schema=lookup_schema)
|
|
3149
|
+
return self.build_synthesized_table_ddl(
|
|
3150
|
+
table_name,
|
|
3151
|
+
columns,
|
|
3152
|
+
schema=schema,
|
|
3153
|
+
constraints=constraints,
|
|
3154
|
+
foreign_keys=foreign_keys,
|
|
3155
|
+
indexes=indexes,
|
|
3156
|
+
target_dialect=target_dialect,
|
|
3157
|
+
source_dialect=type(self).resolve_ddl_dialect(self, driver),
|
|
3158
|
+
warnings=warnings,
|
|
3159
|
+
)
|
|
3160
|
+
|
|
3161
|
+
def _unsupported_metadata(self, domain: str) -> "MetadataResult":
|
|
3162
|
+
return MetadataResult.unsupported(domain)
|
|
3163
|
+
|
|
3164
|
+
def _unsupported_ddl(
|
|
3165
|
+
self, object_name: str, *, schema: "str | None", object_type: str, warnings: tuple[str, ...] = ()
|
|
3166
|
+
) -> "DDLResult":
|
|
3167
|
+
return DDLResult.unsupported(
|
|
3168
|
+
ObjectIdentity(object_name, object_type, schema=schema, dialect=self.dialect),
|
|
3169
|
+
warnings=(*warnings, f"{self.dialect} DDL extraction is not implemented"),
|
|
3170
|
+
)
|
|
3171
|
+
|
|
3172
|
+
|
|
3173
|
+
@mypyc_attr(allow_interpreted_subclasses=False)
|
|
3174
|
+
class _AsyncDriverTransaction(Generic[_AsyncDriverT]):
|
|
3175
|
+
"""Context manager that commits on success and rolls back on error.
|
|
3176
|
+
|
|
3177
|
+
Inside another SQLSpec transaction block on the same driver, the block runs in
|
|
3178
|
+
a savepoint that is released on success and rolled back to on error.
|
|
3179
|
+
"""
|
|
3180
|
+
|
|
3181
|
+
__slots__ = ("_driver", "_entered", "_savepoint")
|
|
3182
|
+
|
|
3183
|
+
def __init__(self, driver: "_AsyncDriverT") -> None:
|
|
3184
|
+
self._driver = driver
|
|
3185
|
+
self._savepoint: str | None = None
|
|
3186
|
+
self._entered = False
|
|
3187
|
+
|
|
3188
|
+
async def __aenter__(self) -> "_AsyncDriverT":
|
|
3189
|
+
driver = self._driver
|
|
3190
|
+
depth = driver._transaction_depth
|
|
3191
|
+
if depth > 0:
|
|
3192
|
+
name = f"sqlspec_sp_{depth}"
|
|
3193
|
+
try:
|
|
3194
|
+
await driver.create_savepoint(name)
|
|
3195
|
+
except NotImplementedError as exc:
|
|
3196
|
+
msg = f"{type(driver).__name__} does not support the savepoints used by nested transaction blocks."
|
|
3197
|
+
error = ImproperConfigurationError(msg)
|
|
3198
|
+
error.__cause__ = exc
|
|
3199
|
+
raise error from exc
|
|
3200
|
+
self._savepoint = name
|
|
3201
|
+
else:
|
|
3202
|
+
try:
|
|
3203
|
+
in_transaction = driver._connection_in_transaction()
|
|
3204
|
+
except NotImplementedError:
|
|
3205
|
+
in_transaction = False
|
|
3206
|
+
if not in_transaction:
|
|
3207
|
+
await driver.begin()
|
|
3208
|
+
driver._transaction_depth = depth + 1
|
|
3209
|
+
self._entered = True
|
|
3210
|
+
return driver
|
|
3211
|
+
|
|
3212
|
+
async def __aexit__(
|
|
3213
|
+
self, exc_type: "type[BaseException] | None", exc: "BaseException | None", traceback: "TracebackType | None"
|
|
3214
|
+
) -> "Literal[False]":
|
|
3215
|
+
driver = self._driver
|
|
3216
|
+
savepoint = self._savepoint
|
|
3217
|
+
entered = self._entered
|
|
3218
|
+
self._savepoint = None
|
|
3219
|
+
self._entered = False
|
|
3220
|
+
try:
|
|
3221
|
+
if savepoint is not None:
|
|
3222
|
+
if exc_type is None:
|
|
3223
|
+
await driver.release_savepoint(savepoint)
|
|
3224
|
+
else:
|
|
3225
|
+
await driver.rollback_to_savepoint(savepoint)
|
|
3226
|
+
return False
|
|
3227
|
+
if exc_type is not None:
|
|
3228
|
+
await driver.rollback()
|
|
3229
|
+
return False
|
|
3230
|
+
commit_error: BaseException | None = None
|
|
3231
|
+
try:
|
|
3232
|
+
await driver.commit()
|
|
3233
|
+
except BaseException as error:
|
|
3234
|
+
commit_error = error
|
|
3235
|
+
if commit_error is not None:
|
|
3236
|
+
try:
|
|
3237
|
+
await driver.rollback()
|
|
3238
|
+
except Exception:
|
|
3239
|
+
logger.debug("Rollback after a failed commit also failed", exc_info=True)
|
|
3240
|
+
raise commit_error
|
|
3241
|
+
return False
|
|
3242
|
+
finally:
|
|
3243
|
+
if entered and driver._transaction_depth > 0:
|
|
3244
|
+
driver._transaction_depth -= 1
|