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