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
|
@@ -0,0 +1,2253 @@
|
|
|
1
|
+
"""SQL statement and configuration management."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import re
|
|
5
|
+
from collections.abc import Mapping, Sequence
|
|
6
|
+
from functools import partial
|
|
7
|
+
from types import BuiltinFunctionType, FunctionType, MethodType
|
|
8
|
+
from typing import TYPE_CHECKING, Any, Final, TypeAlias
|
|
9
|
+
|
|
10
|
+
import sqlglot
|
|
11
|
+
from mypy_extensions import mypyc_attr
|
|
12
|
+
from sqlglot import Dialect, exp
|
|
13
|
+
from sqlglot.errors import ParseError, TokenError
|
|
14
|
+
|
|
15
|
+
import sqlspec.core._operators # noqa: F401 - register SQLGlot operator rendering before any SQL is generated
|
|
16
|
+
import sqlspec.exceptions
|
|
17
|
+
from sqlspec.core import _pipeline as pipeline
|
|
18
|
+
from sqlspec.core._ordering import apply_direction, default_nulls, ordered
|
|
19
|
+
from sqlspec.core._pool import get_processed_state_pool, get_sql_pool
|
|
20
|
+
from sqlspec.core.cache import FiltersView
|
|
21
|
+
from sqlspec.core.compiler import OperationProfile, OperationType
|
|
22
|
+
from sqlspec.core.explain import ExplainFormat, ExplainOptions
|
|
23
|
+
from sqlspec.core.hashing import hash_filters
|
|
24
|
+
from sqlspec.core.parameters._converter import ParameterConverter
|
|
25
|
+
from sqlspec.core.parameters._processor import ParameterProcessor, structural_fingerprint
|
|
26
|
+
from sqlspec.core.parameters._types import ParameterProfile, ParameterStyle, ParameterStyleConfig
|
|
27
|
+
from sqlspec.core.parameters._validator import ParameterValidator, unescape_qmark_operator
|
|
28
|
+
from sqlspec.core.query_modifiers import (
|
|
29
|
+
ConditionFactory,
|
|
30
|
+
apply_column_pruning,
|
|
31
|
+
apply_limit,
|
|
32
|
+
apply_offset,
|
|
33
|
+
apply_select_only,
|
|
34
|
+
apply_where,
|
|
35
|
+
create_between_condition,
|
|
36
|
+
create_condition,
|
|
37
|
+
create_in_condition,
|
|
38
|
+
create_not_in_condition,
|
|
39
|
+
expr_eq,
|
|
40
|
+
expr_gt,
|
|
41
|
+
expr_gte,
|
|
42
|
+
expr_ilike,
|
|
43
|
+
expr_is_not_null,
|
|
44
|
+
expr_is_null,
|
|
45
|
+
expr_like,
|
|
46
|
+
expr_lt,
|
|
47
|
+
expr_lte,
|
|
48
|
+
expr_neq,
|
|
49
|
+
extract_column_name,
|
|
50
|
+
safe_modify_with_cte,
|
|
51
|
+
sanitize_parameter_name,
|
|
52
|
+
wrap_as_subquery,
|
|
53
|
+
)
|
|
54
|
+
from sqlspec.core.splitter import contains_statement_terminator
|
|
55
|
+
from sqlspec.core.sqlcommenter import create_sqlcommenter_statement_transformer, format_wire_sqlcomment
|
|
56
|
+
from sqlspec.exceptions import with_cause
|
|
57
|
+
from sqlspec.observability._common import resolve_db_system
|
|
58
|
+
from sqlspec.typing import Empty, EmptyEnum
|
|
59
|
+
from sqlspec.utils.logging import get_logger
|
|
60
|
+
from sqlspec.utils.type_guards import is_statement_filter, supports_where
|
|
61
|
+
from sqlspec.utils.uuids import uuid4
|
|
62
|
+
|
|
63
|
+
if TYPE_CHECKING:
|
|
64
|
+
from collections.abc import Callable
|
|
65
|
+
|
|
66
|
+
from sqlglot.dialects.dialect import DialectType
|
|
67
|
+
|
|
68
|
+
from sqlspec.builder._base import QueryBuilder
|
|
69
|
+
from sqlspec.core.filters import StatementFilter
|
|
70
|
+
from sqlspec.core.parameters._declared import ParameterDeclaration
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
__all__ = (
|
|
74
|
+
"SQL",
|
|
75
|
+
"ProcessedState",
|
|
76
|
+
"Statement",
|
|
77
|
+
"StatementConfig",
|
|
78
|
+
"get_default_config",
|
|
79
|
+
"get_default_parameter_config",
|
|
80
|
+
)
|
|
81
|
+
logger = get_logger("sqlspec.core.statement")
|
|
82
|
+
|
|
83
|
+
RETURNS_ROWS_OPERATIONS: Final[frozenset[str]] = frozenset({"SELECT", "PRAGMA"})
|
|
84
|
+
"""Operation types that return rows independently of the operation profile."""
|
|
85
|
+
MODIFYING_OPERATIONS: Final[frozenset[str]] = frozenset({"INSERT", "UPDATE", "DELETE", "MERGE", "UPSERT"})
|
|
86
|
+
_ORDER_PARTS_COUNT: Final = 2
|
|
87
|
+
_MAX_PARAM_COLLISION_ATTEMPTS: Final = 1000
|
|
88
|
+
_STATEMENT_START_RE: Final = re.compile(
|
|
89
|
+
r"^\s*(?:DROP|DELETE|INSERT|UPDATE|ALTER|CREATE|TRUNCATE|GRANT|REVOKE|COMMIT|ROLLBACK|EXEC|EXECUTE|CALL|COPY|MERGE)\b",
|
|
90
|
+
re.IGNORECASE,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
SQL_CONFIG_SLOTS: Final = (
|
|
95
|
+
"dialect",
|
|
96
|
+
"enable_analysis",
|
|
97
|
+
"enable_caching",
|
|
98
|
+
"enable_column_pruning",
|
|
99
|
+
"enable_expression_simplification",
|
|
100
|
+
"enable_parameter_type_wrapping",
|
|
101
|
+
"enable_parsing",
|
|
102
|
+
"enable_sqlcommenter",
|
|
103
|
+
"enable_transformations",
|
|
104
|
+
"enable_validation",
|
|
105
|
+
"execution_mode",
|
|
106
|
+
"execution_args",
|
|
107
|
+
"output_transformer",
|
|
108
|
+
"sqlcommenter_attributes",
|
|
109
|
+
"sqlcommenter_enable_context",
|
|
110
|
+
"sqlcommenter_enable_traceparent",
|
|
111
|
+
"statement_transformers",
|
|
112
|
+
"parameter_config",
|
|
113
|
+
"parameter_converter",
|
|
114
|
+
"parameter_validator",
|
|
115
|
+
"_fingerprint_cache",
|
|
116
|
+
"_hash_cache",
|
|
117
|
+
"_is_frozen",
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
_PUBLIC_CONFIG_FIELDS: Final = frozenset(slot for slot in SQL_CONFIG_SLOTS if not slot.startswith("_"))
|
|
121
|
+
|
|
122
|
+
PROCESSED_STATE_SLOTS: Final = (
|
|
123
|
+
"compiled_sql",
|
|
124
|
+
"execution_parameters",
|
|
125
|
+
"expression_is_shared",
|
|
126
|
+
"parsed_expression",
|
|
127
|
+
"operation_type",
|
|
128
|
+
"input_named_parameters",
|
|
129
|
+
"applied_wrap_types",
|
|
130
|
+
"filter_hash",
|
|
131
|
+
"parameter_fingerprint",
|
|
132
|
+
"parameter_casts",
|
|
133
|
+
"parameter_profile",
|
|
134
|
+
"operation_profile",
|
|
135
|
+
"validation_errors",
|
|
136
|
+
"is_many",
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
SQL_SLOTS: Final = (
|
|
140
|
+
"_compiled_from_cache",
|
|
141
|
+
"_declared_parameters",
|
|
142
|
+
"_dialect",
|
|
143
|
+
"_filters",
|
|
144
|
+
"_hash",
|
|
145
|
+
"_is_cache_direct",
|
|
146
|
+
"_is_many",
|
|
147
|
+
"_is_script",
|
|
148
|
+
"_named_parameters",
|
|
149
|
+
"_original_parameters",
|
|
150
|
+
"_pooled",
|
|
151
|
+
"_positional_parameters",
|
|
152
|
+
"_processed_state",
|
|
153
|
+
"_raw_expression",
|
|
154
|
+
"_raw_sql",
|
|
155
|
+
"_rebind_processor",
|
|
156
|
+
"_sql_param_counters",
|
|
157
|
+
"_statement_config",
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@mypyc_attr(allow_interpreted_subclasses=False)
|
|
162
|
+
class ProcessedState:
|
|
163
|
+
"""Processing results for SQL statements.
|
|
164
|
+
|
|
165
|
+
Contains the compiled SQL, execution parameters, parsed expression,
|
|
166
|
+
operation type, and validation errors for a processed SQL statement.
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
__slots__ = PROCESSED_STATE_SLOTS
|
|
170
|
+
operation_type: "OperationType"
|
|
171
|
+
|
|
172
|
+
def __init__(
|
|
173
|
+
self,
|
|
174
|
+
compiled_sql: str,
|
|
175
|
+
execution_parameters: Any,
|
|
176
|
+
parsed_expression: "exp.Expr | None" = None,
|
|
177
|
+
operation_type: "OperationType" = "COMMAND",
|
|
178
|
+
input_named_parameters: "tuple[str, ...] | None" = None,
|
|
179
|
+
applied_wrap_types: bool = False,
|
|
180
|
+
filter_hash: int = 0,
|
|
181
|
+
parameter_fingerprint: Any | None = None,
|
|
182
|
+
parameter_casts: "dict[int, str] | None" = None,
|
|
183
|
+
validation_errors: "list[str] | None" = None,
|
|
184
|
+
parameter_profile: "ParameterProfile | None" = None,
|
|
185
|
+
operation_profile: "OperationProfile | None" = None,
|
|
186
|
+
is_many: bool = False,
|
|
187
|
+
expression_is_shared: bool = False,
|
|
188
|
+
) -> None:
|
|
189
|
+
self.compiled_sql = compiled_sql
|
|
190
|
+
self.execution_parameters = execution_parameters
|
|
191
|
+
self.parsed_expression = parsed_expression
|
|
192
|
+
self.operation_type = operation_type
|
|
193
|
+
self.input_named_parameters = input_named_parameters or ()
|
|
194
|
+
self.applied_wrap_types = applied_wrap_types
|
|
195
|
+
self.filter_hash = filter_hash
|
|
196
|
+
self.parameter_fingerprint = parameter_fingerprint
|
|
197
|
+
self.parameter_casts = parameter_casts or {}
|
|
198
|
+
self.validation_errors = validation_errors or []
|
|
199
|
+
self.parameter_profile = parameter_profile or ParameterProfile.empty()
|
|
200
|
+
self.operation_profile = operation_profile or OperationProfile.empty()
|
|
201
|
+
self.is_many = is_many
|
|
202
|
+
self.expression_is_shared = expression_is_shared
|
|
203
|
+
|
|
204
|
+
def __hash__(self) -> int:
|
|
205
|
+
return hash((self.compiled_sql, str(self.execution_parameters), self.operation_type))
|
|
206
|
+
|
|
207
|
+
def __reduce__(self) -> "tuple[Any, ...]":
|
|
208
|
+
"""Reconstruct via the public ctor so copy/pickle work on mypyc native classes."""
|
|
209
|
+
return (
|
|
210
|
+
ProcessedState,
|
|
211
|
+
(
|
|
212
|
+
self.compiled_sql,
|
|
213
|
+
self.execution_parameters,
|
|
214
|
+
self.parsed_expression,
|
|
215
|
+
self.operation_type,
|
|
216
|
+
self.input_named_parameters,
|
|
217
|
+
self.applied_wrap_types,
|
|
218
|
+
self.filter_hash,
|
|
219
|
+
self.parameter_fingerprint,
|
|
220
|
+
self.parameter_casts,
|
|
221
|
+
self.validation_errors,
|
|
222
|
+
self.parameter_profile,
|
|
223
|
+
self.operation_profile,
|
|
224
|
+
self.is_many,
|
|
225
|
+
self.expression_is_shared,
|
|
226
|
+
),
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
def ensure_owned_expression(self) -> "exp.Expr | None":
|
|
230
|
+
"""Return an owned SQLGlot expression, copying once if currently shared with a cache."""
|
|
231
|
+
expr = self.parsed_expression
|
|
232
|
+
if expr is not None and self.expression_is_shared:
|
|
233
|
+
expr = expr.copy()
|
|
234
|
+
self.parsed_expression = expr
|
|
235
|
+
self.expression_is_shared = False
|
|
236
|
+
return expr
|
|
237
|
+
|
|
238
|
+
def reset(self) -> None:
|
|
239
|
+
"""Reset processing state for reuse."""
|
|
240
|
+
self.compiled_sql = ""
|
|
241
|
+
self.execution_parameters = []
|
|
242
|
+
self.parsed_expression = None
|
|
243
|
+
self.operation_type = "COMMAND"
|
|
244
|
+
self.input_named_parameters = ()
|
|
245
|
+
self.applied_wrap_types = False
|
|
246
|
+
self.filter_hash = 0
|
|
247
|
+
self.parameter_fingerprint = None
|
|
248
|
+
self.parameter_casts.clear()
|
|
249
|
+
self.validation_errors.clear()
|
|
250
|
+
self.parameter_profile = ParameterProfile.empty()
|
|
251
|
+
self.operation_profile = OperationProfile.empty()
|
|
252
|
+
self.is_many = False
|
|
253
|
+
self.expression_is_shared = False
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
@mypyc_attr(allow_interpreted_subclasses=False)
|
|
257
|
+
class SQL:
|
|
258
|
+
"""SQL statement with parameter and filter support.
|
|
259
|
+
|
|
260
|
+
Represents a SQL statement that can be compiled with parameters and filters.
|
|
261
|
+
Supports both positional and named parameters, statement filtering,
|
|
262
|
+
and various execution modes including batch operations.
|
|
263
|
+
"""
|
|
264
|
+
|
|
265
|
+
__slots__ = SQL_SLOTS
|
|
266
|
+
|
|
267
|
+
_sql_param_counters: "dict[str, int]"
|
|
268
|
+
|
|
269
|
+
def __init__(
|
|
270
|
+
self,
|
|
271
|
+
statement: "str | exp.Expr | 'SQL'",
|
|
272
|
+
*parameters: "Any | StatementFilter | list[Any | StatementFilter]",
|
|
273
|
+
statement_config: "StatementConfig | None" = None,
|
|
274
|
+
is_many: bool | None = None,
|
|
275
|
+
declared_parameters: "tuple[ParameterDeclaration, ...]" = (),
|
|
276
|
+
**kwargs: Any,
|
|
277
|
+
) -> None:
|
|
278
|
+
"""Initialize SQL statement.
|
|
279
|
+
|
|
280
|
+
Args:
|
|
281
|
+
statement: SQL string, expression, or existing SQL object
|
|
282
|
+
*parameters: Parameters and filters
|
|
283
|
+
statement_config: Configuration
|
|
284
|
+
is_many: Mark as execute_many operation
|
|
285
|
+
declared_parameters: Parameter declarations to validate against at execute time
|
|
286
|
+
**kwargs: Additional parameters
|
|
287
|
+
"""
|
|
288
|
+
config = statement_config or self._create_auto_config(statement, parameters, kwargs)
|
|
289
|
+
self._statement_config = config
|
|
290
|
+
self._dialect = self._normalize_dialect(config.dialect)
|
|
291
|
+
self._compiled_from_cache = False
|
|
292
|
+
self._pooled = False
|
|
293
|
+
self._is_cache_direct = False
|
|
294
|
+
self._processed_state: EmptyEnum | ProcessedState = Empty
|
|
295
|
+
self._hash: int | None = None
|
|
296
|
+
self._filters: list[StatementFilter] = []
|
|
297
|
+
self._named_parameters: dict[str, Any] = {}
|
|
298
|
+
self._positional_parameters: list[Any] = []
|
|
299
|
+
self._sql_param_counters = {}
|
|
300
|
+
self._is_script = False
|
|
301
|
+
self._raw_expression: exp.Expr | None = None
|
|
302
|
+
self._rebind_processor: ParameterProcessor | None = None
|
|
303
|
+
self._declared_parameters: tuple[ParameterDeclaration, ...] = declared_parameters
|
|
304
|
+
|
|
305
|
+
if isinstance(statement, SQL):
|
|
306
|
+
self._init_from_sql_object(statement)
|
|
307
|
+
if is_many is not None:
|
|
308
|
+
self._is_many = is_many
|
|
309
|
+
else:
|
|
310
|
+
if isinstance(statement, str):
|
|
311
|
+
self._raw_sql = statement
|
|
312
|
+
else:
|
|
313
|
+
self._raw_sql = ""
|
|
314
|
+
self._raw_expression = statement
|
|
315
|
+
|
|
316
|
+
self._is_many = is_many if is_many is not None else self._should_auto_detect_many(parameters)
|
|
317
|
+
|
|
318
|
+
self._original_parameters = parameters
|
|
319
|
+
self._process_parameters(*parameters, **kwargs)
|
|
320
|
+
|
|
321
|
+
def __reduce__(self) -> "tuple[Any, ...]":
|
|
322
|
+
"""Reconstruct via the public ctor with stored raw SQL, parameters, and filters."""
|
|
323
|
+
return (
|
|
324
|
+
_rebuild_sql,
|
|
325
|
+
(
|
|
326
|
+
self._materialized_raw_sql(),
|
|
327
|
+
self._original_parameters,
|
|
328
|
+
tuple(self._filters),
|
|
329
|
+
self._statement_config,
|
|
330
|
+
self._is_many,
|
|
331
|
+
self._is_script,
|
|
332
|
+
dict(self._named_parameters),
|
|
333
|
+
self._declared_parameters,
|
|
334
|
+
),
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
def __hash__(self) -> int:
|
|
338
|
+
"""Hash value computation."""
|
|
339
|
+
if self._hash is None:
|
|
340
|
+
positional_tuple = tuple(self._positional_parameters)
|
|
341
|
+
named_tuple = tuple(sorted(self._named_parameters.items())) if self._named_parameters else ()
|
|
342
|
+
raw_sql = self._materialized_raw_sql()
|
|
343
|
+
is_many = self._is_many
|
|
344
|
+
is_script = self._is_script
|
|
345
|
+
self._hash = hash((
|
|
346
|
+
raw_sql,
|
|
347
|
+
positional_tuple,
|
|
348
|
+
named_tuple,
|
|
349
|
+
is_many,
|
|
350
|
+
is_script,
|
|
351
|
+
self._dialect,
|
|
352
|
+
hash_filters(self._filters),
|
|
353
|
+
))
|
|
354
|
+
return self._hash
|
|
355
|
+
|
|
356
|
+
def __eq__(self, other: object) -> bool:
|
|
357
|
+
"""Equality comparison."""
|
|
358
|
+
if not isinstance(other, SQL):
|
|
359
|
+
return False
|
|
360
|
+
return (
|
|
361
|
+
self._materialized_raw_sql() == other._materialized_raw_sql()
|
|
362
|
+
and self._positional_parameters == other._positional_parameters
|
|
363
|
+
and self._named_parameters == other._named_parameters
|
|
364
|
+
and self._is_many == other._is_many
|
|
365
|
+
and self._is_script == other._is_script
|
|
366
|
+
and self._dialect == other._dialect
|
|
367
|
+
and self._filters == other._filters
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
def __repr__(self) -> str:
|
|
371
|
+
"""String representation."""
|
|
372
|
+
params_parts = []
|
|
373
|
+
if self._positional_parameters:
|
|
374
|
+
params_parts.append(f"params={self._positional_parameters}")
|
|
375
|
+
if self._named_parameters:
|
|
376
|
+
params_parts.append(f"named_params={self._named_parameters}")
|
|
377
|
+
params_str = f", {', '.join(params_parts)}" if params_parts else ""
|
|
378
|
+
|
|
379
|
+
flags = []
|
|
380
|
+
if self._is_many:
|
|
381
|
+
flags.append("is_many")
|
|
382
|
+
if self._is_script:
|
|
383
|
+
flags.append("is_script")
|
|
384
|
+
flags_str = f", {', '.join(flags)}" if flags else ""
|
|
385
|
+
|
|
386
|
+
return f"SQL({self._materialized_raw_sql()!r}{params_str}{flags_str})"
|
|
387
|
+
|
|
388
|
+
@property
|
|
389
|
+
def sql(self) -> str:
|
|
390
|
+
"""Get the raw SQL string (alias of :attr:`raw_sql`)."""
|
|
391
|
+
return self._materialized_raw_sql()
|
|
392
|
+
|
|
393
|
+
@property
|
|
394
|
+
def raw_sql(self) -> str:
|
|
395
|
+
"""Get raw SQL string (public API).
|
|
396
|
+
|
|
397
|
+
Returns:
|
|
398
|
+
The raw SQL string
|
|
399
|
+
"""
|
|
400
|
+
return self._materialized_raw_sql()
|
|
401
|
+
|
|
402
|
+
@property
|
|
403
|
+
def parameters(self) -> Any:
|
|
404
|
+
"""Get the values that will be bound to the statement."""
|
|
405
|
+
mixed = self._mixed_parameter_inputs()
|
|
406
|
+
if mixed is not None:
|
|
407
|
+
return mixed[1]
|
|
408
|
+
if self._named_parameters:
|
|
409
|
+
return self._named_parameters
|
|
410
|
+
if self._positional_parameters:
|
|
411
|
+
return self._positional_parameters
|
|
412
|
+
if self._is_cache_direct and self._processed_state is not Empty:
|
|
413
|
+
exec_params = self._processed_state.execution_parameters
|
|
414
|
+
if isinstance(exec_params, dict):
|
|
415
|
+
return exec_params
|
|
416
|
+
if isinstance(exec_params, tuple):
|
|
417
|
+
return list(exec_params)
|
|
418
|
+
if isinstance(exec_params, list):
|
|
419
|
+
return exec_params
|
|
420
|
+
return []
|
|
421
|
+
|
|
422
|
+
@property
|
|
423
|
+
def positional_parameters(self) -> "list[Any]":
|
|
424
|
+
"""Get positional parameters (public API)."""
|
|
425
|
+
return self._positional_parameters or []
|
|
426
|
+
|
|
427
|
+
@property
|
|
428
|
+
def named_parameters(self) -> "dict[str, Any]":
|
|
429
|
+
"""Get named parameters (public API)."""
|
|
430
|
+
return self._named_parameters
|
|
431
|
+
|
|
432
|
+
@property
|
|
433
|
+
def original_parameters(self) -> Any:
|
|
434
|
+
"""Get original parameters (public API)."""
|
|
435
|
+
return self._original_parameters
|
|
436
|
+
|
|
437
|
+
@property
|
|
438
|
+
def declared_parameters(self) -> "tuple[ParameterDeclaration, ...]":
|
|
439
|
+
"""Get declared parameter metadata carried with this statement (public API)."""
|
|
440
|
+
return self._declared_parameters
|
|
441
|
+
|
|
442
|
+
@property
|
|
443
|
+
def operation_type(self) -> "OperationType":
|
|
444
|
+
"""SQL operation type."""
|
|
445
|
+
state = self._processed_state
|
|
446
|
+
if state is Empty:
|
|
447
|
+
return "COMMAND"
|
|
448
|
+
return state.operation_type
|
|
449
|
+
|
|
450
|
+
@property
|
|
451
|
+
def statement_config(self) -> "StatementConfig":
|
|
452
|
+
"""Statement configuration."""
|
|
453
|
+
return self._statement_config
|
|
454
|
+
|
|
455
|
+
@property
|
|
456
|
+
def expression(self) -> "exp.Expr | None":
|
|
457
|
+
"""SQLGlot expression.
|
|
458
|
+
|
|
459
|
+
This intentionally mirrors statement_expression for compatibility.
|
|
460
|
+
"""
|
|
461
|
+
state = self._processed_state
|
|
462
|
+
if state is not Empty:
|
|
463
|
+
return state.ensure_owned_expression()
|
|
464
|
+
return self._raw_expression
|
|
465
|
+
|
|
466
|
+
@property
|
|
467
|
+
def raw_expression(self) -> "exp.Expr | None":
|
|
468
|
+
"""Original expression supplied at construction, if available."""
|
|
469
|
+
return self._raw_expression
|
|
470
|
+
|
|
471
|
+
@property
|
|
472
|
+
def filters(self) -> "list[StatementFilter]":
|
|
473
|
+
"""Applied filters."""
|
|
474
|
+
return self._filters.copy()
|
|
475
|
+
|
|
476
|
+
@property
|
|
477
|
+
def is_processed(self) -> bool:
|
|
478
|
+
"""Check if SQL has been processed (public API)."""
|
|
479
|
+
state = self._processed_state
|
|
480
|
+
return state is not Empty
|
|
481
|
+
|
|
482
|
+
@property
|
|
483
|
+
def dialect(self) -> "str | None":
|
|
484
|
+
"""SQL dialect."""
|
|
485
|
+
return self._dialect
|
|
486
|
+
|
|
487
|
+
@property
|
|
488
|
+
def statement_expression(self) -> "exp.Expr | None":
|
|
489
|
+
"""Get parsed statement expression (public API).
|
|
490
|
+
|
|
491
|
+
This intentionally mirrors expression for compatibility.
|
|
492
|
+
|
|
493
|
+
Returns:
|
|
494
|
+
Parsed SQLGlot expression or None if not parsed
|
|
495
|
+
"""
|
|
496
|
+
state = self._processed_state
|
|
497
|
+
if state is not Empty:
|
|
498
|
+
return state.ensure_owned_expression()
|
|
499
|
+
return self._raw_expression
|
|
500
|
+
|
|
501
|
+
@property
|
|
502
|
+
def is_many(self) -> bool:
|
|
503
|
+
"""Check if this is execute_many."""
|
|
504
|
+
return self._is_many
|
|
505
|
+
|
|
506
|
+
@property
|
|
507
|
+
def is_script(self) -> bool:
|
|
508
|
+
"""Check if this is script execution."""
|
|
509
|
+
return self._is_script
|
|
510
|
+
|
|
511
|
+
@property
|
|
512
|
+
def validation_errors(self) -> "list[str]":
|
|
513
|
+
"""Validation errors."""
|
|
514
|
+
state = self._processed_state
|
|
515
|
+
if state is Empty:
|
|
516
|
+
return []
|
|
517
|
+
return state.validation_errors.copy()
|
|
518
|
+
|
|
519
|
+
@property
|
|
520
|
+
def has_errors(self) -> bool:
|
|
521
|
+
"""Check if there are validation errors."""
|
|
522
|
+
state = self._processed_state
|
|
523
|
+
if state is Empty:
|
|
524
|
+
return False
|
|
525
|
+
return bool(state.validation_errors)
|
|
526
|
+
|
|
527
|
+
def reset(self) -> None:
|
|
528
|
+
"""Reset SQL object for reuse in pooling scenarios."""
|
|
529
|
+
if self._pooled and not self._compiled_from_cache and self._processed_state is not Empty:
|
|
530
|
+
get_processed_state_pool().release(self._processed_state)
|
|
531
|
+
self._compiled_from_cache = False
|
|
532
|
+
self._is_cache_direct = False
|
|
533
|
+
self._processed_state = Empty
|
|
534
|
+
self._hash = None
|
|
535
|
+
self._filters.clear()
|
|
536
|
+
self._named_parameters.clear()
|
|
537
|
+
self._positional_parameters.clear()
|
|
538
|
+
self._sql_param_counters.clear()
|
|
539
|
+
self._original_parameters = ()
|
|
540
|
+
self._is_many = False
|
|
541
|
+
self._is_script = False
|
|
542
|
+
self._raw_expression = None
|
|
543
|
+
self._raw_sql = ""
|
|
544
|
+
self._statement_config = get_default_config()
|
|
545
|
+
self._dialect = self._normalize_dialect(self._statement_config.dialect)
|
|
546
|
+
self._rebind_processor = None
|
|
547
|
+
self._declared_parameters = ()
|
|
548
|
+
|
|
549
|
+
def get_filters_view(self) -> "FiltersView":
|
|
550
|
+
"""Get zero-copy filters view (public API).
|
|
551
|
+
|
|
552
|
+
Returns:
|
|
553
|
+
Read-only view of filters without copying
|
|
554
|
+
"""
|
|
555
|
+
return FiltersView(self._filters)
|
|
556
|
+
|
|
557
|
+
def get_processed_state(self) -> Any:
|
|
558
|
+
"""Get processed state (public API)."""
|
|
559
|
+
return self._processed_state
|
|
560
|
+
|
|
561
|
+
def returns_rows(self) -> bool:
|
|
562
|
+
"""Check if statement returns rows.
|
|
563
|
+
|
|
564
|
+
Returns:
|
|
565
|
+
True if the SQL statement returns result rows
|
|
566
|
+
"""
|
|
567
|
+
state = self._processed_state
|
|
568
|
+
if state is Empty:
|
|
569
|
+
self.compile()
|
|
570
|
+
state = self._processed_state
|
|
571
|
+
if state is Empty:
|
|
572
|
+
return False
|
|
573
|
+
|
|
574
|
+
profile = state.operation_profile
|
|
575
|
+
if profile.returns_rows:
|
|
576
|
+
return True
|
|
577
|
+
|
|
578
|
+
op_type = state.operation_type
|
|
579
|
+
if op_type in RETURNS_ROWS_OPERATIONS:
|
|
580
|
+
return True
|
|
581
|
+
|
|
582
|
+
expr = state.parsed_expression
|
|
583
|
+
if isinstance(expr, (exp.Insert, exp.Update, exp.Delete)):
|
|
584
|
+
returning = expr.args.get("returning")
|
|
585
|
+
return bool(returning) and not (isinstance(returning, exp.Returning) and returning.args.get("into"))
|
|
586
|
+
|
|
587
|
+
return False
|
|
588
|
+
|
|
589
|
+
def is_read_only(self) -> bool:
|
|
590
|
+
"""Return whether parsed SQL is provably safe for read replica routing."""
|
|
591
|
+
if self._is_many or self._is_script or not self._statement_config.enable_parsing:
|
|
592
|
+
return False
|
|
593
|
+
state = self._processed_state
|
|
594
|
+
if state is Empty:
|
|
595
|
+
self.compile()
|
|
596
|
+
state = self._processed_state
|
|
597
|
+
if state is Empty:
|
|
598
|
+
return False
|
|
599
|
+
return state.operation_profile.is_read_only
|
|
600
|
+
|
|
601
|
+
def is_modifying_operation(self) -> bool:
|
|
602
|
+
"""Check if the SQL statement is a modifying operation.
|
|
603
|
+
|
|
604
|
+
Returns:
|
|
605
|
+
True if the operation modifies data (INSERT/UPDATE/DELETE)
|
|
606
|
+
"""
|
|
607
|
+
state = self._processed_state
|
|
608
|
+
if state is Empty:
|
|
609
|
+
if not self._statement_config.enable_parsing:
|
|
610
|
+
return False
|
|
611
|
+
self.compile()
|
|
612
|
+
state = self._processed_state
|
|
613
|
+
if state is Empty:
|
|
614
|
+
return False
|
|
615
|
+
|
|
616
|
+
profile = state.operation_profile
|
|
617
|
+
if profile.modifies_rows:
|
|
618
|
+
return True
|
|
619
|
+
|
|
620
|
+
op_type = state.operation_type
|
|
621
|
+
if op_type in MODIFYING_OPERATIONS:
|
|
622
|
+
return True
|
|
623
|
+
|
|
624
|
+
if state.parsed_expression:
|
|
625
|
+
return isinstance(state.parsed_expression, (exp.Insert, exp.Update, exp.Delete, exp.Merge))
|
|
626
|
+
|
|
627
|
+
return False
|
|
628
|
+
|
|
629
|
+
def compile(self) -> "tuple[str, Any]":
|
|
630
|
+
"""Compile SQL statement with parameters.
|
|
631
|
+
|
|
632
|
+
Returns:
|
|
633
|
+
Tuple of compiled SQL string and execution parameters
|
|
634
|
+
"""
|
|
635
|
+
state = self._processed_state
|
|
636
|
+
if state is not Empty:
|
|
637
|
+
if not self._compiled_from_cache:
|
|
638
|
+
return state.compiled_sql, state.execution_parameters
|
|
639
|
+
if state.execution_parameters is not None and (
|
|
640
|
+
not self._statement_config.parameter_config.needs_static_script_compilation
|
|
641
|
+
and self._can_reuse_cached_state(state)
|
|
642
|
+
):
|
|
643
|
+
return self._rebind_cached_parameters(state)
|
|
644
|
+
|
|
645
|
+
try:
|
|
646
|
+
config = self._statement_config
|
|
647
|
+
if config.dialect is None and self._dialect is not None and Dialect.get(self._dialect) is not None:
|
|
648
|
+
config = config._with_dialect(self._dialect)
|
|
649
|
+
mixed = self._resolve_mixed_parameter_inputs()
|
|
650
|
+
raw_sql = mixed[0] if mixed is not None else self._materialized_raw_sql()
|
|
651
|
+
params = mixed[1] if mixed is not None else self._named_parameters or self._positional_parameters
|
|
652
|
+
is_many = self._is_many
|
|
653
|
+
param_fingerprint = structural_fingerprint(params, is_many=is_many)
|
|
654
|
+
pipeline_fingerprint: Any | None = (
|
|
655
|
+
None if config.parameter_config.needs_static_script_compilation else param_fingerprint
|
|
656
|
+
)
|
|
657
|
+
compiled_result = pipeline.compile_with_pipeline(
|
|
658
|
+
config,
|
|
659
|
+
raw_sql,
|
|
660
|
+
params,
|
|
661
|
+
is_many=is_many,
|
|
662
|
+
expression=None if mixed is not None else self._raw_expression,
|
|
663
|
+
param_fingerprint=pipeline_fingerprint,
|
|
664
|
+
)
|
|
665
|
+
|
|
666
|
+
new_state = self._build_processed_state(
|
|
667
|
+
compiled_sql=compiled_result.compiled_sql,
|
|
668
|
+
execution_parameters=compiled_result.execution_parameters,
|
|
669
|
+
parsed_expression=compiled_result.expression,
|
|
670
|
+
operation_type=compiled_result.operation_type,
|
|
671
|
+
input_named_parameters=compiled_result.input_named_parameters,
|
|
672
|
+
applied_wrap_types=compiled_result.applied_wrap_types,
|
|
673
|
+
filter_hash=hash_filters(self._filters),
|
|
674
|
+
parameter_fingerprint=param_fingerprint,
|
|
675
|
+
parameter_casts=compiled_result.parameter_casts,
|
|
676
|
+
parameter_profile=compiled_result.parameter_profile,
|
|
677
|
+
operation_profile=compiled_result.operation_profile,
|
|
678
|
+
validation_errors=[],
|
|
679
|
+
is_many=self._is_many,
|
|
680
|
+
expression_is_shared=compiled_result.expression is not None,
|
|
681
|
+
)
|
|
682
|
+
except sqlspec.exceptions.SQLSpecError:
|
|
683
|
+
raise
|
|
684
|
+
except RecursionError as e:
|
|
685
|
+
msg = "Statement nesting exceeds the supported depth"
|
|
686
|
+
raise with_cause(sqlspec.exceptions.SQLParsingError(msg), e) from e
|
|
687
|
+
except Exception as e:
|
|
688
|
+
new_state = self._handle_compile_failure(e)
|
|
689
|
+
|
|
690
|
+
self._processed_state = new_state
|
|
691
|
+
self._compiled_from_cache = False
|
|
692
|
+
return new_state.compiled_sql, new_state.execution_parameters
|
|
693
|
+
|
|
694
|
+
def as_script(self) -> "SQL":
|
|
695
|
+
"""Create copy marked for script execution.
|
|
696
|
+
|
|
697
|
+
Script execution binds no parameters, so any supplied parameters are
|
|
698
|
+
embedded statically into the SQL via sqlglot. The script copy forces
|
|
699
|
+
``needs_static_script_compilation`` so every adapter compiles bind-free.
|
|
700
|
+
|
|
701
|
+
Returns:
|
|
702
|
+
New SQL instance configured for script execution
|
|
703
|
+
"""
|
|
704
|
+
new_sql = self._copy_base(self._raw_expression or self._raw_sql)
|
|
705
|
+
new_sql._is_script = True
|
|
706
|
+
new_sql._statement_config = self._statement_config._with_script_mode()
|
|
707
|
+
return new_sql
|
|
708
|
+
|
|
709
|
+
def copy(self, statement: "str | exp.Expr | None" = None, parameters: Any | None = None, **kwargs: Any) -> "SQL":
|
|
710
|
+
"""Create copy with modifications.
|
|
711
|
+
|
|
712
|
+
Args:
|
|
713
|
+
statement: New SQL statement to use
|
|
714
|
+
parameters: New parameters to use
|
|
715
|
+
**kwargs: Additional modifications
|
|
716
|
+
|
|
717
|
+
Returns:
|
|
718
|
+
New SQL instance with modifications applied
|
|
719
|
+
"""
|
|
720
|
+
if statement is None and not kwargs and parameters is not None and not isinstance(parameters, (str, bytes)):
|
|
721
|
+
new_sql = self._create_empty_copy()
|
|
722
|
+
new_sql._process_parameters(*(parameters if isinstance(parameters, tuple) else (parameters,)))
|
|
723
|
+
return new_sql
|
|
724
|
+
|
|
725
|
+
statement_expression = self._raw_expression if statement is None else statement
|
|
726
|
+
statement_config = kwargs.pop("statement_config", self._statement_config)
|
|
727
|
+
is_many = kwargs.pop("is_many", self._is_many)
|
|
728
|
+
new_sql = SQL(
|
|
729
|
+
statement_expression or self._raw_sql,
|
|
730
|
+
*(parameters if parameters is not None else self._original_parameters),
|
|
731
|
+
statement_config=statement_config,
|
|
732
|
+
is_many=is_many,
|
|
733
|
+
**kwargs,
|
|
734
|
+
)
|
|
735
|
+
if parameters is None:
|
|
736
|
+
new_sql._named_parameters.update(self._named_parameters)
|
|
737
|
+
new_sql._positional_parameters = self._positional_parameters.copy()
|
|
738
|
+
new_sql._filters = self._filters.copy()
|
|
739
|
+
new_sql._declared_parameters = self._declared_parameters
|
|
740
|
+
return new_sql
|
|
741
|
+
|
|
742
|
+
def add_named_parameter(self, name: str, value: Any) -> "SQL":
|
|
743
|
+
"""Add a named parameter and return a new SQL instance.
|
|
744
|
+
|
|
745
|
+
Args:
|
|
746
|
+
name: Parameter name
|
|
747
|
+
value: Parameter value
|
|
748
|
+
|
|
749
|
+
Returns:
|
|
750
|
+
New SQL instance with the added parameter
|
|
751
|
+
"""
|
|
752
|
+
statement_seed = self._raw_expression or self._raw_sql
|
|
753
|
+
new_sql = self._copy_base(statement_seed)
|
|
754
|
+
new_sql._named_parameters[name] = value
|
|
755
|
+
return new_sql
|
|
756
|
+
|
|
757
|
+
def where(self, condition: "str | exp.Expr") -> "SQL":
|
|
758
|
+
"""Add WHERE condition to the SQL statement.
|
|
759
|
+
|
|
760
|
+
Args:
|
|
761
|
+
condition: WHERE condition as string or SQLGlot expression
|
|
762
|
+
|
|
763
|
+
Returns:
|
|
764
|
+
New SQL instance with the WHERE condition applied
|
|
765
|
+
|
|
766
|
+
Raises:
|
|
767
|
+
SQLParsingError: If the condition is empty, contains a NUL character,
|
|
768
|
+
contains a statement separator outside quoted text, or is a
|
|
769
|
+
statement rather than a condition.
|
|
770
|
+
"""
|
|
771
|
+
current_expr = self._current_expression()
|
|
772
|
+
|
|
773
|
+
condition_expr: exp.Expr
|
|
774
|
+
if isinstance(condition, str):
|
|
775
|
+
if not condition.strip() or "\x00" in condition or contains_statement_terminator(condition, self._dialect):
|
|
776
|
+
msg = "WHERE condition must be a single expression without NUL characters or statement separators"
|
|
777
|
+
raise sqlspec.exceptions.SQLParsingError(msg)
|
|
778
|
+
if not self._statement_config.enable_parsing:
|
|
779
|
+
condition_expr = _raw_condition(condition, self._dialect)
|
|
780
|
+
else:
|
|
781
|
+
try:
|
|
782
|
+
condition_expr = sqlglot.parse_one(condition, dialect=self._dialect)
|
|
783
|
+
except (ParseError, TokenError):
|
|
784
|
+
condition_expr = _raw_condition(condition, self._dialect)
|
|
785
|
+
else:
|
|
786
|
+
condition_expr = condition
|
|
787
|
+
if (
|
|
788
|
+
not isinstance(condition_expr, exp.Condition)
|
|
789
|
+
or condition_expr.find(exp.Command, exp.DDL, exp.DML, exp.Drop, exp.Alter, exp.TruncateTable) is not None
|
|
790
|
+
):
|
|
791
|
+
msg = f"WHERE condition must be an expression, got {type(condition_expr).__name__}"
|
|
792
|
+
raise sqlspec.exceptions.SQLParsingError(msg)
|
|
793
|
+
|
|
794
|
+
if isinstance(current_expr, (exp.Select, exp.Update, exp.Delete)) or (
|
|
795
|
+
not isinstance(current_expr, (exp.Query, exp.Values)) and supports_where(current_expr)
|
|
796
|
+
):
|
|
797
|
+
new_expr = current_expr.where(condition_expr, copy=False)
|
|
798
|
+
else:
|
|
799
|
+
new_expr = wrap_as_subquery(current_expr).where(condition_expr, copy=False)
|
|
800
|
+
|
|
801
|
+
return self._copy_with_expression(new_expr)
|
|
802
|
+
|
|
803
|
+
def where_eq(self, column: "str | exp.Column", value: Any) -> "SQL":
|
|
804
|
+
"""Add WHERE column = value condition.
|
|
805
|
+
|
|
806
|
+
``None`` renders ``column IS NULL``, because ``column = NULL`` is never true.
|
|
807
|
+
|
|
808
|
+
Args:
|
|
809
|
+
column: Column name or expression
|
|
810
|
+
value: Value to compare against
|
|
811
|
+
|
|
812
|
+
Returns:
|
|
813
|
+
New SQL instance with WHERE condition applied
|
|
814
|
+
"""
|
|
815
|
+
if value is None:
|
|
816
|
+
return self.where_is_null(column)
|
|
817
|
+
return self._where_comparison(column, value, expr_eq)
|
|
818
|
+
|
|
819
|
+
def where_neq(self, column: "str | exp.Column", value: Any) -> "SQL":
|
|
820
|
+
"""Add WHERE column != value condition.
|
|
821
|
+
|
|
822
|
+
``None`` renders ``column IS NOT NULL``, because ``column <> NULL`` is never true.
|
|
823
|
+
|
|
824
|
+
Args:
|
|
825
|
+
column: Column name or expression
|
|
826
|
+
value: Value to compare against
|
|
827
|
+
|
|
828
|
+
Returns:
|
|
829
|
+
New SQL instance with WHERE condition applied
|
|
830
|
+
"""
|
|
831
|
+
if value is None:
|
|
832
|
+
return self.where_is_not_null(column)
|
|
833
|
+
return self._where_comparison(column, value, expr_neq)
|
|
834
|
+
|
|
835
|
+
def where_lt(self, column: "str | exp.Column", value: Any) -> "SQL":
|
|
836
|
+
"""Add WHERE column < value condition.
|
|
837
|
+
|
|
838
|
+
Args:
|
|
839
|
+
column: Column name or expression
|
|
840
|
+
value: Value to compare against
|
|
841
|
+
|
|
842
|
+
Returns:
|
|
843
|
+
New SQL instance with WHERE condition applied
|
|
844
|
+
"""
|
|
845
|
+
return self._where_comparison(column, value, expr_lt)
|
|
846
|
+
|
|
847
|
+
def where_lte(self, column: "str | exp.Column", value: Any) -> "SQL":
|
|
848
|
+
"""Add WHERE column <= value condition.
|
|
849
|
+
|
|
850
|
+
Args:
|
|
851
|
+
column: Column name or expression
|
|
852
|
+
value: Value to compare against
|
|
853
|
+
|
|
854
|
+
Returns:
|
|
855
|
+
New SQL instance with WHERE condition applied
|
|
856
|
+
"""
|
|
857
|
+
return self._where_comparison(column, value, expr_lte)
|
|
858
|
+
|
|
859
|
+
def where_gt(self, column: "str | exp.Column", value: Any) -> "SQL":
|
|
860
|
+
"""Add WHERE column > value condition.
|
|
861
|
+
|
|
862
|
+
Args:
|
|
863
|
+
column: Column name or expression
|
|
864
|
+
value: Value to compare against
|
|
865
|
+
|
|
866
|
+
Returns:
|
|
867
|
+
New SQL instance with WHERE condition applied
|
|
868
|
+
"""
|
|
869
|
+
return self._where_comparison(column, value, expr_gt)
|
|
870
|
+
|
|
871
|
+
def where_gte(self, column: "str | exp.Column", value: Any) -> "SQL":
|
|
872
|
+
"""Add WHERE column >= value condition.
|
|
873
|
+
|
|
874
|
+
Args:
|
|
875
|
+
column: Column name or expression
|
|
876
|
+
value: Value to compare against
|
|
877
|
+
|
|
878
|
+
Returns:
|
|
879
|
+
New SQL instance with WHERE condition applied
|
|
880
|
+
"""
|
|
881
|
+
return self._where_comparison(column, value, expr_gte)
|
|
882
|
+
|
|
883
|
+
def where_like(self, column: "str | exp.Column", pattern: str) -> "SQL":
|
|
884
|
+
"""Add WHERE column LIKE pattern condition.
|
|
885
|
+
|
|
886
|
+
Args:
|
|
887
|
+
column: Column name or expression
|
|
888
|
+
pattern: LIKE pattern
|
|
889
|
+
|
|
890
|
+
Returns:
|
|
891
|
+
New SQL instance with WHERE condition applied
|
|
892
|
+
"""
|
|
893
|
+
return self._where_comparison(column, pattern, expr_like)
|
|
894
|
+
|
|
895
|
+
def where_ilike(self, column: "str | exp.Column", pattern: str) -> "SQL":
|
|
896
|
+
"""Add WHERE column ILIKE pattern condition (case-insensitive).
|
|
897
|
+
|
|
898
|
+
Args:
|
|
899
|
+
column: Column name or expression
|
|
900
|
+
pattern: ILIKE pattern
|
|
901
|
+
|
|
902
|
+
Returns:
|
|
903
|
+
New SQL instance with WHERE condition applied
|
|
904
|
+
"""
|
|
905
|
+
return self._where_comparison(column, pattern, expr_ilike)
|
|
906
|
+
|
|
907
|
+
def where_is_null(self, column: "str | exp.Column") -> "SQL":
|
|
908
|
+
"""Add WHERE column IS NULL condition.
|
|
909
|
+
|
|
910
|
+
Args:
|
|
911
|
+
column: Column name or expression
|
|
912
|
+
|
|
913
|
+
Returns:
|
|
914
|
+
New SQL instance with WHERE condition applied
|
|
915
|
+
"""
|
|
916
|
+
condition = create_condition(column, "_unused", expr_is_null)
|
|
917
|
+
return self._where_condition(condition)
|
|
918
|
+
|
|
919
|
+
def where_is_not_null(self, column: "str | exp.Column") -> "SQL":
|
|
920
|
+
"""Add WHERE column IS NOT NULL condition.
|
|
921
|
+
|
|
922
|
+
Args:
|
|
923
|
+
column: Column name or expression
|
|
924
|
+
|
|
925
|
+
Returns:
|
|
926
|
+
New SQL instance with WHERE condition applied
|
|
927
|
+
"""
|
|
928
|
+
condition = create_condition(column, "_unused", expr_is_not_null)
|
|
929
|
+
return self._where_condition(condition)
|
|
930
|
+
|
|
931
|
+
def where_in(self, column: "str | exp.Column", values: "Sequence[Any]") -> "SQL":
|
|
932
|
+
"""Add WHERE column IN (values) condition.
|
|
933
|
+
|
|
934
|
+
Args:
|
|
935
|
+
column: Column name or expression
|
|
936
|
+
values: Sequence of values for IN clause
|
|
937
|
+
|
|
938
|
+
Returns:
|
|
939
|
+
New SQL instance with WHERE condition applied
|
|
940
|
+
"""
|
|
941
|
+
return self._where_sequence_membership(column, values, "in", create_in_condition, empty_is_false=True)
|
|
942
|
+
|
|
943
|
+
def where_not_in(self, column: "str | exp.Column", values: "Sequence[Any]") -> "SQL":
|
|
944
|
+
"""Add WHERE column NOT IN (values) condition.
|
|
945
|
+
|
|
946
|
+
Args:
|
|
947
|
+
column: Column name or expression
|
|
948
|
+
values: Sequence of values for NOT IN clause
|
|
949
|
+
|
|
950
|
+
Returns:
|
|
951
|
+
New SQL instance with WHERE condition applied
|
|
952
|
+
"""
|
|
953
|
+
return self._where_sequence_membership(column, values, "not_in", create_not_in_condition, empty_is_false=False)
|
|
954
|
+
|
|
955
|
+
def where_between(self, column: "str | exp.Column", low: Any, high: Any) -> "SQL":
|
|
956
|
+
"""Add WHERE column BETWEEN low AND high condition.
|
|
957
|
+
|
|
958
|
+
Args:
|
|
959
|
+
column: Column name or expression
|
|
960
|
+
low: Lower bound value
|
|
961
|
+
high: Upper bound value
|
|
962
|
+
|
|
963
|
+
Returns:
|
|
964
|
+
New SQL instance with WHERE condition applied
|
|
965
|
+
"""
|
|
966
|
+
col_name = extract_column_name(column)
|
|
967
|
+
low_param = self._next_parameter_name(f"{col_name}_low")
|
|
968
|
+
high_param = self._next_parameter_name(f"{col_name}_high")
|
|
969
|
+
condition = create_between_condition(column, low_param, high_param)
|
|
970
|
+
new_sql = self._where_condition(condition)
|
|
971
|
+
new_sql._named_parameters[low_param] = low
|
|
972
|
+
new_sql._named_parameters[high_param] = high
|
|
973
|
+
return new_sql
|
|
974
|
+
|
|
975
|
+
def order_by(self, *items: "str | exp.Expr", desc: bool = False) -> "SQL":
|
|
976
|
+
"""Add ORDER BY clause to the SQL statement.
|
|
977
|
+
|
|
978
|
+
Args:
|
|
979
|
+
*items: ORDER BY expressions as strings or SQLGlot expressions
|
|
980
|
+
desc: Apply descending order to each item
|
|
981
|
+
|
|
982
|
+
Returns:
|
|
983
|
+
New SQL instance with ORDER BY applied
|
|
984
|
+
"""
|
|
985
|
+
if not items:
|
|
986
|
+
return self
|
|
987
|
+
|
|
988
|
+
current_expr = self._current_expression()
|
|
989
|
+
|
|
990
|
+
new_expr: exp.Expr = current_expr
|
|
991
|
+
dialect = self._dialect
|
|
992
|
+
enable_parsing = self._statement_config.enable_parsing
|
|
993
|
+
for item in items:
|
|
994
|
+
if isinstance(item, str):
|
|
995
|
+
order_expr = apply_direction(_parse_order_item(item, dialect, enable_parsing), desc)
|
|
996
|
+
else:
|
|
997
|
+
order_expr = apply_direction(item, desc)
|
|
998
|
+
if isinstance(new_expr, (exp.Select, exp.SetOperation)):
|
|
999
|
+
new_expr = new_expr.order_by(order_expr, copy=False)
|
|
1000
|
+
else:
|
|
1001
|
+
new_expr = wrap_as_subquery(new_expr).order_by(order_expr, copy=False)
|
|
1002
|
+
|
|
1003
|
+
return self._copy_with_expression(new_expr)
|
|
1004
|
+
|
|
1005
|
+
def limit(self, value: int) -> "SQL":
|
|
1006
|
+
"""Add LIMIT clause to the SQL statement.
|
|
1007
|
+
|
|
1008
|
+
Args:
|
|
1009
|
+
value: Maximum number of rows to return
|
|
1010
|
+
|
|
1011
|
+
Returns:
|
|
1012
|
+
New SQL instance with LIMIT applied
|
|
1013
|
+
"""
|
|
1014
|
+
expression = self._current_expression()
|
|
1015
|
+
new_expr = safe_modify_with_cte(expression, lambda e: apply_limit(e, value))
|
|
1016
|
+
return self._copy_with_expression(new_expr)
|
|
1017
|
+
|
|
1018
|
+
def offset(self, value: int) -> "SQL":
|
|
1019
|
+
"""Add OFFSET clause to the SQL statement.
|
|
1020
|
+
|
|
1021
|
+
Args:
|
|
1022
|
+
value: Number of rows to skip
|
|
1023
|
+
|
|
1024
|
+
Returns:
|
|
1025
|
+
New SQL instance with OFFSET applied
|
|
1026
|
+
"""
|
|
1027
|
+
expression = self._current_expression()
|
|
1028
|
+
new_expr = safe_modify_with_cte(expression, lambda e: apply_offset(e, value))
|
|
1029
|
+
return self._copy_with_expression(new_expr)
|
|
1030
|
+
|
|
1031
|
+
def paginate(self, page: int, page_size: int) -> "SQL":
|
|
1032
|
+
"""Add LIMIT and OFFSET for pagination.
|
|
1033
|
+
|
|
1034
|
+
Args:
|
|
1035
|
+
page: Page number (1-indexed)
|
|
1036
|
+
page_size: Number of items per page
|
|
1037
|
+
|
|
1038
|
+
Returns:
|
|
1039
|
+
New SQL instance with LIMIT and OFFSET applied
|
|
1040
|
+
"""
|
|
1041
|
+
if page < 1:
|
|
1042
|
+
msg = "paginate page must be >= 1"
|
|
1043
|
+
raise sqlspec.exceptions.SQLSpecError(msg)
|
|
1044
|
+
if page_size < 1:
|
|
1045
|
+
msg = "paginate page_size must be >= 1"
|
|
1046
|
+
raise sqlspec.exceptions.SQLSpecError(msg)
|
|
1047
|
+
offset_value = (page - 1) * page_size
|
|
1048
|
+
return self.limit(page_size).offset(offset_value)
|
|
1049
|
+
|
|
1050
|
+
def select_only(self, *columns: "str | exp.Expr", prune_columns: bool | None = None) -> "SQL":
|
|
1051
|
+
"""Replace SELECT columns with only the specified columns.
|
|
1052
|
+
|
|
1053
|
+
This is useful for narrowing down the columns returned by a query
|
|
1054
|
+
without modifying the FROM clause or WHERE conditions.
|
|
1055
|
+
|
|
1056
|
+
Args:
|
|
1057
|
+
*columns: Column names or expressions to select
|
|
1058
|
+
prune_columns: Remove unused columns from subqueries. When True,
|
|
1059
|
+
applies SQLGlot's qualify and pushdown_projections optimizations.
|
|
1060
|
+
Defaults to the config's enable_column_pruning setting.
|
|
1061
|
+
|
|
1062
|
+
Returns:
|
|
1063
|
+
New SQL instance with only the specified columns
|
|
1064
|
+
"""
|
|
1065
|
+
if not columns:
|
|
1066
|
+
return self
|
|
1067
|
+
|
|
1068
|
+
expression = self._current_expression()
|
|
1069
|
+
new_expr = safe_modify_with_cte(expression, lambda e: apply_select_only(e, columns))
|
|
1070
|
+
|
|
1071
|
+
should_prune = prune_columns if prune_columns is not None else self._statement_config.enable_column_pruning
|
|
1072
|
+
|
|
1073
|
+
if should_prune:
|
|
1074
|
+
if self._statement_config.enable_caching:
|
|
1075
|
+
expr_sql = new_expr.sql(dialect=self._dialect)
|
|
1076
|
+
cache_key = f"prune:{hashlib.blake2b(expr_sql.encode(), digest_size=16).hexdigest()}"
|
|
1077
|
+
else:
|
|
1078
|
+
cache_key = None
|
|
1079
|
+
new_expr = apply_column_pruning(new_expr, dialect=self._dialect, cache_key=cache_key)
|
|
1080
|
+
|
|
1081
|
+
return self._copy_with_expression(new_expr)
|
|
1082
|
+
|
|
1083
|
+
def explain(self, analyze: bool = False, verbose: bool = False, format: "str | None" = None) -> "SQL":
|
|
1084
|
+
"""Create an EXPLAIN statement for this SQL.
|
|
1085
|
+
|
|
1086
|
+
Wraps the current SQL statement in an EXPLAIN clause with
|
|
1087
|
+
dialect-aware syntax generation.
|
|
1088
|
+
|
|
1089
|
+
Args:
|
|
1090
|
+
analyze: Execute the statement and show actual runtime statistics
|
|
1091
|
+
verbose: Show additional information
|
|
1092
|
+
format: Output format (TEXT, JSON, XML, YAML, TREE, TRADITIONAL)
|
|
1093
|
+
|
|
1094
|
+
Returns:
|
|
1095
|
+
New SQL instance containing the EXPLAIN statement
|
|
1096
|
+
"""
|
|
1097
|
+
from sqlspec.builder._explain import Explain
|
|
1098
|
+
|
|
1099
|
+
fmt = None
|
|
1100
|
+
if format is not None:
|
|
1101
|
+
fmt = ExplainFormat(format.lower())
|
|
1102
|
+
|
|
1103
|
+
options = ExplainOptions(analyze=analyze, verbose=verbose, format=fmt)
|
|
1104
|
+
|
|
1105
|
+
explain_builder = Explain(self, dialect=self._dialect, options=options)
|
|
1106
|
+
explained = explain_builder.build()
|
|
1107
|
+
if self._positional_parameters:
|
|
1108
|
+
explained._positional_parameters = self._positional_parameters.copy()
|
|
1109
|
+
explained._original_parameters = self._original_parameters
|
|
1110
|
+
explained._is_many = self._is_many
|
|
1111
|
+
explained._declared_parameters = self._declared_parameters
|
|
1112
|
+
explained._hash = None
|
|
1113
|
+
return explained
|
|
1114
|
+
|
|
1115
|
+
def builder(self, dialect: "DialectType | None" = None) -> "QueryBuilder":
|
|
1116
|
+
"""Create a query builder seeded from this SQL statement.
|
|
1117
|
+
|
|
1118
|
+
Args:
|
|
1119
|
+
dialect: Optional SQL dialect override for parsing and rendering.
|
|
1120
|
+
|
|
1121
|
+
Returns:
|
|
1122
|
+
QueryBuilder instance initialized with the parsed statement.
|
|
1123
|
+
|
|
1124
|
+
Raises:
|
|
1125
|
+
SQLBuilderError: If the statement cannot be parsed.
|
|
1126
|
+
"""
|
|
1127
|
+
if self._is_many:
|
|
1128
|
+
msg = "QueryBuilder does not support execute_many SQL statements."
|
|
1129
|
+
raise sqlspec.exceptions.SQLBuilderError(msg)
|
|
1130
|
+
|
|
1131
|
+
from sqlspec.builder._base import ExpressionBuilder
|
|
1132
|
+
from sqlspec.builder._delete import Delete
|
|
1133
|
+
from sqlspec.builder._insert import Insert
|
|
1134
|
+
from sqlspec.builder._merge import Merge
|
|
1135
|
+
from sqlspec.builder._select import Select
|
|
1136
|
+
from sqlspec.builder._update import Update
|
|
1137
|
+
|
|
1138
|
+
builder_dialect = dialect or self._dialect
|
|
1139
|
+
lexical_dialect = self._normalize_dialect(builder_dialect)
|
|
1140
|
+
converter = self._statement_config.parameter_converter or ParameterConverter(
|
|
1141
|
+
self._statement_config.parameter_validator
|
|
1142
|
+
)
|
|
1143
|
+
raw_params = self.parameters
|
|
1144
|
+
raw_sql_for_builder = self._materialized_raw_sql()
|
|
1145
|
+
converted_sql, converted_params = converter.convert_placeholder_style(
|
|
1146
|
+
raw_sql_for_builder, raw_params, ParameterStyle.NAMED_COLON, is_many=False, dialect=lexical_dialect
|
|
1147
|
+
)
|
|
1148
|
+
state = self._processed_state
|
|
1149
|
+
|
|
1150
|
+
if (
|
|
1151
|
+
self._raw_expression is not None
|
|
1152
|
+
and converted_sql == raw_sql_for_builder
|
|
1153
|
+
and (builder_dialect == self._dialect)
|
|
1154
|
+
):
|
|
1155
|
+
expression = self._raw_expression.copy()
|
|
1156
|
+
elif (
|
|
1157
|
+
state is not Empty
|
|
1158
|
+
and state.parsed_expression is not None
|
|
1159
|
+
and converted_sql == raw_sql_for_builder
|
|
1160
|
+
and builder_dialect == self._dialect
|
|
1161
|
+
):
|
|
1162
|
+
expression = state.parsed_expression.copy()
|
|
1163
|
+
else:
|
|
1164
|
+
try:
|
|
1165
|
+
expression = sqlglot.parse_one(converted_sql, dialect=builder_dialect)
|
|
1166
|
+
except ParseError as exc:
|
|
1167
|
+
msg = f"Failed to parse SQL for builder: {exc}"
|
|
1168
|
+
raise with_cause(sqlspec.exceptions.SQLBuilderError(msg), exc) from exc
|
|
1169
|
+
|
|
1170
|
+
base_expression = expression
|
|
1171
|
+
ctes: list[exp.CTE] | None = None
|
|
1172
|
+
if isinstance(expression, exp.With):
|
|
1173
|
+
if expression.this is None:
|
|
1174
|
+
msg = "WITH expression does not include a base statement."
|
|
1175
|
+
raise sqlspec.exceptions.SQLBuilderError(msg)
|
|
1176
|
+
base_expression = expression.this
|
|
1177
|
+
ctes = list(expression.expressions)
|
|
1178
|
+
|
|
1179
|
+
builder: QueryBuilder
|
|
1180
|
+
if isinstance(base_expression, (exp.Select, exp.Union, exp.Except, exp.Intersect, exp.Values)):
|
|
1181
|
+
builder = Select(dialect=builder_dialect)
|
|
1182
|
+
builder.set_expression(base_expression)
|
|
1183
|
+
elif isinstance(base_expression, exp.Insert):
|
|
1184
|
+
builder = Insert(dialect=builder_dialect)
|
|
1185
|
+
builder.set_expression(base_expression)
|
|
1186
|
+
elif isinstance(base_expression, exp.Update):
|
|
1187
|
+
builder = Update(dialect=builder_dialect)
|
|
1188
|
+
builder.set_expression(base_expression)
|
|
1189
|
+
elif isinstance(base_expression, exp.Delete):
|
|
1190
|
+
builder = Delete(dialect=builder_dialect)
|
|
1191
|
+
builder.set_expression(base_expression)
|
|
1192
|
+
elif isinstance(base_expression, exp.Merge):
|
|
1193
|
+
builder = Merge(dialect=builder_dialect)
|
|
1194
|
+
builder.set_expression(base_expression)
|
|
1195
|
+
else:
|
|
1196
|
+
if not isinstance(base_expression, exp.Expression):
|
|
1197
|
+
msg = f"Unsupported expression type for builder: {type(base_expression).__name__}"
|
|
1198
|
+
raise sqlspec.exceptions.SQLBuilderError(msg)
|
|
1199
|
+
builder = ExpressionBuilder(base_expression, dialect=builder_dialect)
|
|
1200
|
+
|
|
1201
|
+
if ctes:
|
|
1202
|
+
builder.load_ctes(ctes)
|
|
1203
|
+
|
|
1204
|
+
if isinstance(converted_params, Mapping):
|
|
1205
|
+
builder.load_parameters(converted_params)
|
|
1206
|
+
return builder
|
|
1207
|
+
|
|
1208
|
+
if (
|
|
1209
|
+
converted_params
|
|
1210
|
+
and isinstance(converted_params, Sequence)
|
|
1211
|
+
and not isinstance(converted_params, (str, bytes, bytearray))
|
|
1212
|
+
):
|
|
1213
|
+
param_info = converter.validator.extract_parameters(converted_sql, dialect=lexical_dialect)
|
|
1214
|
+
param_map: dict[str, Any] = {}
|
|
1215
|
+
for index, param in enumerate(param_info):
|
|
1216
|
+
if index >= len(converted_params):
|
|
1217
|
+
break
|
|
1218
|
+
param_name = param.name or f"param_{param.ordinal}"
|
|
1219
|
+
param_map[param_name] = converted_params[index]
|
|
1220
|
+
builder.load_parameters(param_map)
|
|
1221
|
+
|
|
1222
|
+
return builder
|
|
1223
|
+
|
|
1224
|
+
@classmethod
|
|
1225
|
+
def _create_cached_direct(
|
|
1226
|
+
cls, sql: str, config: "StatementConfig", processed_state: "ProcessedState", *, pooled: bool = True
|
|
1227
|
+
) -> "SQL":
|
|
1228
|
+
"""Create a minimal SQL object for direct (fast-path) execution.
|
|
1229
|
+
|
|
1230
|
+
Bypasses standard __init__ and parameter processing.
|
|
1231
|
+
Only for use by direct execution paths.
|
|
1232
|
+
"""
|
|
1233
|
+
stmt = get_sql_pool().acquire()
|
|
1234
|
+
stmt._raw_sql = sql
|
|
1235
|
+
stmt._statement_config = config
|
|
1236
|
+
stmt._dialect = stmt._normalize_dialect(config.dialect)
|
|
1237
|
+
stmt._processed_state = processed_state
|
|
1238
|
+
stmt._pooled = pooled
|
|
1239
|
+
stmt._is_cache_direct = True
|
|
1240
|
+
stmt._is_many = False
|
|
1241
|
+
stmt._is_script = False
|
|
1242
|
+
stmt._rebind_processor = None
|
|
1243
|
+
return stmt
|
|
1244
|
+
|
|
1245
|
+
def _create_auto_config(
|
|
1246
|
+
self, _statement: "str | exp.Expr | 'SQL'", _parameters: tuple, _kwargs: "dict[str, Any]"
|
|
1247
|
+
) -> "StatementConfig":
|
|
1248
|
+
"""Create default StatementConfig when none provided.
|
|
1249
|
+
|
|
1250
|
+
Args:
|
|
1251
|
+
_statement: The SQL statement (unused)
|
|
1252
|
+
_parameters: Statement parameters (unused)
|
|
1253
|
+
_kwargs: Additional keyword arguments (unused)
|
|
1254
|
+
|
|
1255
|
+
Returns:
|
|
1256
|
+
Default StatementConfig instance
|
|
1257
|
+
"""
|
|
1258
|
+
return get_default_config()
|
|
1259
|
+
|
|
1260
|
+
@staticmethod
|
|
1261
|
+
def _normalize_dialect(dialect: "DialectType") -> "str | None":
|
|
1262
|
+
"""Convert dialect to string representation.
|
|
1263
|
+
|
|
1264
|
+
Args:
|
|
1265
|
+
dialect: Dialect type, string, or None
|
|
1266
|
+
|
|
1267
|
+
Returns:
|
|
1268
|
+
String representation of the dialect or None
|
|
1269
|
+
"""
|
|
1270
|
+
if dialect is None:
|
|
1271
|
+
return None
|
|
1272
|
+
if isinstance(dialect, str):
|
|
1273
|
+
return dialect.strip().lower() or None
|
|
1274
|
+
if isinstance(dialect, type) and issubclass(dialect, Dialect):
|
|
1275
|
+
return dialect.__name__.lower()
|
|
1276
|
+
return type(dialect).__name__.lower()
|
|
1277
|
+
|
|
1278
|
+
def _materialized_raw_sql(self) -> str:
|
|
1279
|
+
"""Return raw SQL, materializing deferred expression SQL when needed."""
|
|
1280
|
+
if self._raw_sql == "" and self._raw_expression is not None:
|
|
1281
|
+
dialect = self._dialect
|
|
1282
|
+
self._raw_sql = self._raw_expression.sql(dialect=str(dialect) if dialect else None)
|
|
1283
|
+
return self._raw_sql
|
|
1284
|
+
|
|
1285
|
+
def _init_from_sql_object(self, sql_obj: "SQL") -> None:
|
|
1286
|
+
"""Initialize instance attributes from existing SQL object.
|
|
1287
|
+
|
|
1288
|
+
Args:
|
|
1289
|
+
sql_obj: Existing SQL object to copy from
|
|
1290
|
+
"""
|
|
1291
|
+
self._raw_sql = sql_obj.raw_sql
|
|
1292
|
+
self._raw_expression = sql_obj.raw_expression
|
|
1293
|
+
self._filters = sql_obj.filters.copy()
|
|
1294
|
+
self._named_parameters = sql_obj.named_parameters.copy()
|
|
1295
|
+
self._positional_parameters = sql_obj.positional_parameters.copy()
|
|
1296
|
+
self._sql_param_counters = sql_obj._sql_param_counters.copy()
|
|
1297
|
+
self._is_many = sql_obj.is_many
|
|
1298
|
+
self._is_script = sql_obj.is_script
|
|
1299
|
+
self._declared_parameters = sql_obj._declared_parameters
|
|
1300
|
+
source_state = sql_obj.get_processed_state()
|
|
1301
|
+
if source_state is not Empty:
|
|
1302
|
+
self._processed_state = source_state
|
|
1303
|
+
|
|
1304
|
+
@staticmethod
|
|
1305
|
+
def _should_auto_detect_many(parameters: tuple) -> bool:
|
|
1306
|
+
"""Detect execute_many mode from parameter structure.
|
|
1307
|
+
|
|
1308
|
+
Args:
|
|
1309
|
+
parameters: Parameter tuple to analyze
|
|
1310
|
+
|
|
1311
|
+
Returns:
|
|
1312
|
+
True if parameters indicate batch execution
|
|
1313
|
+
"""
|
|
1314
|
+
if len(parameters) == 1 and isinstance(parameters[0], list):
|
|
1315
|
+
param_list = parameters[0]
|
|
1316
|
+
if not param_list:
|
|
1317
|
+
return False
|
|
1318
|
+
first_item = param_list[0]
|
|
1319
|
+
if isinstance(first_item, (tuple, list, dict)):
|
|
1320
|
+
return len(param_list) > 1
|
|
1321
|
+
return False
|
|
1322
|
+
|
|
1323
|
+
def _process_parameters(self, *parameters: Any, dialect: str | None = None, **kwargs: Any) -> None:
|
|
1324
|
+
"""Process and organize parameters and filters.
|
|
1325
|
+
|
|
1326
|
+
Args:
|
|
1327
|
+
*parameters: Variable parameters and filters
|
|
1328
|
+
dialect: SQL dialect override
|
|
1329
|
+
**kwargs: Additional named parameters
|
|
1330
|
+
"""
|
|
1331
|
+
if dialect is not None:
|
|
1332
|
+
self._dialect = self._normalize_dialect(dialect)
|
|
1333
|
+
|
|
1334
|
+
if "is_script" in kwargs:
|
|
1335
|
+
self._is_script = bool(kwargs.pop("is_script"))
|
|
1336
|
+
|
|
1337
|
+
self._filters.extend(self._extract_filters(parameters))
|
|
1338
|
+
self._normalize_parameters(parameters)
|
|
1339
|
+
self._named_parameters.update(kwargs)
|
|
1340
|
+
|
|
1341
|
+
@staticmethod
|
|
1342
|
+
def _extract_filters(parameters: "tuple[Any, ...]") -> "list[StatementFilter]":
|
|
1343
|
+
return [p for p in parameters if is_statement_filter(p)]
|
|
1344
|
+
|
|
1345
|
+
def _add_parameter(self, param: Any) -> None:
|
|
1346
|
+
if isinstance(param, dict):
|
|
1347
|
+
self._named_parameters.update(param)
|
|
1348
|
+
elif isinstance(param, (list, tuple)):
|
|
1349
|
+
if self._is_many:
|
|
1350
|
+
self._positional_parameters = list(param)
|
|
1351
|
+
else:
|
|
1352
|
+
self._positional_parameters.extend(param)
|
|
1353
|
+
else:
|
|
1354
|
+
self._positional_parameters.append(param)
|
|
1355
|
+
|
|
1356
|
+
def _normalize_parameters(self, parameters: "tuple[Any, ...]") -> None:
|
|
1357
|
+
if not parameters:
|
|
1358
|
+
return
|
|
1359
|
+
|
|
1360
|
+
if len(parameters) == 1:
|
|
1361
|
+
param = parameters[0]
|
|
1362
|
+
if isinstance(param, (str, int, float, bool)) or param is None:
|
|
1363
|
+
self._positional_parameters.append(param)
|
|
1364
|
+
return
|
|
1365
|
+
|
|
1366
|
+
if is_statement_filter(param):
|
|
1367
|
+
return
|
|
1368
|
+
|
|
1369
|
+
self._add_parameter(param)
|
|
1370
|
+
return
|
|
1371
|
+
|
|
1372
|
+
has_filter = any(is_statement_filter(p) for p in parameters)
|
|
1373
|
+
if not has_filter:
|
|
1374
|
+
self._positional_parameters.extend(parameters)
|
|
1375
|
+
return
|
|
1376
|
+
|
|
1377
|
+
actual_params = [p for p in parameters if not is_statement_filter(p)]
|
|
1378
|
+
if not actual_params:
|
|
1379
|
+
return
|
|
1380
|
+
|
|
1381
|
+
if len(actual_params) == 1:
|
|
1382
|
+
self._add_parameter(actual_params[0])
|
|
1383
|
+
else:
|
|
1384
|
+
self._positional_parameters.extend(actual_params)
|
|
1385
|
+
|
|
1386
|
+
def _mixed_parameter_inputs(self) -> "tuple[str, dict[str, Any]] | None":
|
|
1387
|
+
"""Normalize coexisting positional and named values without losing either."""
|
|
1388
|
+
positional, named = self._positional_parameters, self._named_parameters
|
|
1389
|
+
if not positional or not named or self._is_many:
|
|
1390
|
+
return None
|
|
1391
|
+
raw = self._materialized_raw_sql()
|
|
1392
|
+
infos = self._statement_config.parameter_validator.extract_parameters(raw, dialect=self._dialect)
|
|
1393
|
+
ordinal_styles = {ParameterStyle.QMARK, ParameterStyle.POSITIONAL_PYFORMAT}
|
|
1394
|
+
index_styles = {ParameterStyle.NUMERIC, ParameterStyle.POSITIONAL_COLON}
|
|
1395
|
+
positional_styles = ordinal_styles | index_styles
|
|
1396
|
+
styles = {info.style for info in infos if info.style in positional_styles}
|
|
1397
|
+
unbound = [info for info in infos if info.style not in positional_styles and info.name not in named]
|
|
1398
|
+
if len(styles) > 1 or (styles & index_styles and unbound):
|
|
1399
|
+
return None
|
|
1400
|
+
selected = [info for info in infos if info.style in positional_styles or info.name not in named]
|
|
1401
|
+
if not selected:
|
|
1402
|
+
return None
|
|
1403
|
+
slots: dict[str, int] = {}
|
|
1404
|
+
indexes: list[int] = []
|
|
1405
|
+
counter = 0
|
|
1406
|
+
for info in selected:
|
|
1407
|
+
if info.style in index_styles:
|
|
1408
|
+
index = int(info.name or "0") - 1
|
|
1409
|
+
elif info.style in ordinal_styles:
|
|
1410
|
+
index = counter
|
|
1411
|
+
counter += 1
|
|
1412
|
+
elif info.name in slots:
|
|
1413
|
+
index = slots[info.name]
|
|
1414
|
+
else:
|
|
1415
|
+
index = counter
|
|
1416
|
+
slots[info.name or ""] = index
|
|
1417
|
+
counter += 1
|
|
1418
|
+
if index < 0 or index >= len(positional):
|
|
1419
|
+
return None
|
|
1420
|
+
indexes.append(index)
|
|
1421
|
+
if not styles & index_styles and counter != len(positional):
|
|
1422
|
+
return None
|
|
1423
|
+
names = {index: name for name, index in slots.items()}
|
|
1424
|
+
used = set(named) | set(slots)
|
|
1425
|
+
for index in indexes:
|
|
1426
|
+
if index not in names:
|
|
1427
|
+
name = f"param_{index}"
|
|
1428
|
+
while name in used:
|
|
1429
|
+
name += "_p"
|
|
1430
|
+
names[index] = name
|
|
1431
|
+
used.add(name)
|
|
1432
|
+
for info, index in list(zip(selected, indexes, strict=True))[::-1]:
|
|
1433
|
+
if info.style in positional_styles:
|
|
1434
|
+
raw = raw[: info.position] + ":" + names[index] + raw[info.position + len(info.placeholder_text) :]
|
|
1435
|
+
return raw, {**{name: positional[index] for index, name in names.items()}, **named}
|
|
1436
|
+
|
|
1437
|
+
def _resolve_mixed_parameter_inputs(self) -> "tuple[str, dict[str, Any]] | None":
|
|
1438
|
+
mixed = self._mixed_parameter_inputs()
|
|
1439
|
+
if mixed is None and self._positional_parameters and self._named_parameters and not self._is_many:
|
|
1440
|
+
msg = "Cannot combine positional and named parameters when placeholder styles or counts do not match."
|
|
1441
|
+
raise sqlspec.exceptions.SQLSpecError(msg)
|
|
1442
|
+
return mixed
|
|
1443
|
+
|
|
1444
|
+
def _rebind_cached_parameters(self, state: "ProcessedState") -> "tuple[str, Any]":
|
|
1445
|
+
mixed = self._resolve_mixed_parameter_inputs()
|
|
1446
|
+
params = mixed[1] if mixed is not None else self._named_parameters or self._positional_parameters
|
|
1447
|
+
if self._rebind_processor is None:
|
|
1448
|
+
self._rebind_processor = _get_rebind_processor(self._statement_config)
|
|
1449
|
+
processor = self._rebind_processor
|
|
1450
|
+
rebound_params = processor.transform_cached_parameters(
|
|
1451
|
+
params,
|
|
1452
|
+
state.parameter_profile,
|
|
1453
|
+
self._statement_config.parameter_config,
|
|
1454
|
+
input_named_parameters=state.input_named_parameters,
|
|
1455
|
+
is_many=self._is_many,
|
|
1456
|
+
apply_wrap_types=state.applied_wrap_types,
|
|
1457
|
+
)
|
|
1458
|
+
compiled_sql = state.compiled_sql
|
|
1459
|
+
if self._statement_config.enable_sqlcommenter:
|
|
1460
|
+
compiled_sql = format_wire_sqlcomment(compiled_sql, self._statement_config)
|
|
1461
|
+
output_transformer = self._statement_config.output_transformer
|
|
1462
|
+
if output_transformer:
|
|
1463
|
+
compiled_sql, rebound_params = output_transformer(compiled_sql, rebound_params)
|
|
1464
|
+
if state.parsed_expression is not None:
|
|
1465
|
+
state.expression_is_shared = True
|
|
1466
|
+
self._processed_state = self._build_processed_state(
|
|
1467
|
+
compiled_sql=compiled_sql,
|
|
1468
|
+
execution_parameters=rebound_params,
|
|
1469
|
+
parsed_expression=state.parsed_expression,
|
|
1470
|
+
operation_type=state.operation_type,
|
|
1471
|
+
input_named_parameters=state.input_named_parameters,
|
|
1472
|
+
applied_wrap_types=state.applied_wrap_types,
|
|
1473
|
+
filter_hash=state.filter_hash,
|
|
1474
|
+
parameter_fingerprint=state.parameter_fingerprint,
|
|
1475
|
+
parameter_casts=state.parameter_casts,
|
|
1476
|
+
parameter_profile=state.parameter_profile,
|
|
1477
|
+
operation_profile=state.operation_profile,
|
|
1478
|
+
validation_errors=state.validation_errors.copy(),
|
|
1479
|
+
is_many=state.is_many,
|
|
1480
|
+
expression_is_shared=state.parsed_expression is not None,
|
|
1481
|
+
)
|
|
1482
|
+
self._compiled_from_cache = False
|
|
1483
|
+
return compiled_sql, rebound_params
|
|
1484
|
+
|
|
1485
|
+
def _can_reuse_cached_state(self, state: "ProcessedState") -> bool:
|
|
1486
|
+
if self._statement_config.parameter_config.ast_transformer is not None:
|
|
1487
|
+
return False
|
|
1488
|
+
cached_fingerprint = state.parameter_fingerprint
|
|
1489
|
+
if cached_fingerprint is None:
|
|
1490
|
+
return False
|
|
1491
|
+
if state.is_many != self._is_many:
|
|
1492
|
+
return False
|
|
1493
|
+
if state.filter_hash != hash_filters(self._filters):
|
|
1494
|
+
return False
|
|
1495
|
+
mixed = self._mixed_parameter_inputs()
|
|
1496
|
+
params = mixed[1] if mixed is not None else self._named_parameters or self._positional_parameters
|
|
1497
|
+
return bool(structural_fingerprint(params, is_many=self._is_many) == cached_fingerprint)
|
|
1498
|
+
|
|
1499
|
+
def _create_empty_copy(self) -> "SQL":
|
|
1500
|
+
"""Create a shell copy with shared immutable state but empty mutable state."""
|
|
1501
|
+
new_sql = get_sql_pool().acquire()
|
|
1502
|
+
new_sql._raw_sql = self._raw_sql
|
|
1503
|
+
new_sql._raw_expression = self._raw_expression
|
|
1504
|
+
new_sql._statement_config = self._statement_config
|
|
1505
|
+
new_sql._dialect = self._dialect
|
|
1506
|
+
new_sql._is_many = self._is_many
|
|
1507
|
+
new_sql._is_script = self._is_script
|
|
1508
|
+
new_sql._original_parameters = ()
|
|
1509
|
+
new_sql._pooled = True
|
|
1510
|
+
|
|
1511
|
+
source_state = self._processed_state
|
|
1512
|
+
if source_state is not Empty:
|
|
1513
|
+
if source_state.parsed_expression is not None:
|
|
1514
|
+
source_state.expression_is_shared = True
|
|
1515
|
+
new_sql._compiled_from_cache = True
|
|
1516
|
+
new_sql._processed_state = source_state
|
|
1517
|
+
else:
|
|
1518
|
+
new_sql._compiled_from_cache = False
|
|
1519
|
+
new_sql._processed_state = Empty
|
|
1520
|
+
new_sql._hash = None
|
|
1521
|
+
new_sql._filters = self._filters.copy()
|
|
1522
|
+
new_sql._named_parameters = {}
|
|
1523
|
+
new_sql._positional_parameters = []
|
|
1524
|
+
new_sql._sql_param_counters = self._sql_param_counters.copy()
|
|
1525
|
+
new_sql._declared_parameters = self._declared_parameters
|
|
1526
|
+
new_sql._rebind_processor = self._rebind_processor
|
|
1527
|
+
|
|
1528
|
+
return new_sql
|
|
1529
|
+
|
|
1530
|
+
def _build_processed_state(
|
|
1531
|
+
self,
|
|
1532
|
+
*,
|
|
1533
|
+
compiled_sql: str,
|
|
1534
|
+
execution_parameters: Any,
|
|
1535
|
+
parsed_expression: "exp.Expr | None",
|
|
1536
|
+
operation_type: "OperationType",
|
|
1537
|
+
input_named_parameters: "tuple[str, ...] | None",
|
|
1538
|
+
applied_wrap_types: bool,
|
|
1539
|
+
filter_hash: int,
|
|
1540
|
+
parameter_fingerprint: Any | None,
|
|
1541
|
+
parameter_casts: "dict[int, str] | None",
|
|
1542
|
+
parameter_profile: "ParameterProfile | None",
|
|
1543
|
+
operation_profile: "OperationProfile | None",
|
|
1544
|
+
validation_errors: "list[str] | None",
|
|
1545
|
+
is_many: bool,
|
|
1546
|
+
expression_is_shared: bool = False,
|
|
1547
|
+
) -> "ProcessedState":
|
|
1548
|
+
state = get_processed_state_pool().acquire()
|
|
1549
|
+
ProcessedState.__init__(
|
|
1550
|
+
state,
|
|
1551
|
+
compiled_sql=compiled_sql,
|
|
1552
|
+
execution_parameters=execution_parameters,
|
|
1553
|
+
parsed_expression=parsed_expression,
|
|
1554
|
+
operation_type=operation_type,
|
|
1555
|
+
input_named_parameters=input_named_parameters,
|
|
1556
|
+
applied_wrap_types=applied_wrap_types,
|
|
1557
|
+
filter_hash=filter_hash,
|
|
1558
|
+
parameter_fingerprint=parameter_fingerprint,
|
|
1559
|
+
parameter_casts=parameter_casts,
|
|
1560
|
+
validation_errors=validation_errors,
|
|
1561
|
+
parameter_profile=parameter_profile,
|
|
1562
|
+
operation_profile=operation_profile,
|
|
1563
|
+
is_many=is_many,
|
|
1564
|
+
expression_is_shared=expression_is_shared,
|
|
1565
|
+
)
|
|
1566
|
+
return state
|
|
1567
|
+
|
|
1568
|
+
def _handle_compile_failure(self, error: Exception) -> ProcessedState:
|
|
1569
|
+
logger.debug("Processing failed, using fallback: %s", error, exc_info=(type(error), error, error.__traceback__))
|
|
1570
|
+
mixed = self._mixed_parameter_inputs()
|
|
1571
|
+
params = mixed[1] if mixed is not None else self._named_parameters.copy() or self._positional_parameters.copy()
|
|
1572
|
+
return self._build_processed_state(
|
|
1573
|
+
compiled_sql=mixed[0] if mixed is not None else self._materialized_raw_sql(),
|
|
1574
|
+
execution_parameters=params,
|
|
1575
|
+
parsed_expression=None,
|
|
1576
|
+
operation_type="COMMAND",
|
|
1577
|
+
input_named_parameters=(),
|
|
1578
|
+
applied_wrap_types=False,
|
|
1579
|
+
filter_hash=hash_filters(self._filters),
|
|
1580
|
+
parameter_fingerprint=structural_fingerprint(params, is_many=self._is_many),
|
|
1581
|
+
parameter_casts={},
|
|
1582
|
+
parameter_profile=ParameterProfile.empty(),
|
|
1583
|
+
operation_profile=OperationProfile.empty(),
|
|
1584
|
+
validation_errors=[str(error)],
|
|
1585
|
+
is_many=self._is_many,
|
|
1586
|
+
)
|
|
1587
|
+
|
|
1588
|
+
def _next_parameter_name(self, base_name: str) -> str:
|
|
1589
|
+
"""Generate unique parameter name with param_ prefix.
|
|
1590
|
+
|
|
1591
|
+
Uses param_ prefix to avoid collision with user-provided parameters.
|
|
1592
|
+
Auto-generated parameters are namespaced to prevent conflicts.
|
|
1593
|
+
|
|
1594
|
+
Args:
|
|
1595
|
+
base_name: The base name for the parameter
|
|
1596
|
+
|
|
1597
|
+
Returns:
|
|
1598
|
+
A unique parameter name that doesn't exist in current parameters
|
|
1599
|
+
"""
|
|
1600
|
+
prefixed_base = f"param_{sanitize_parameter_name(base_name)}"
|
|
1601
|
+
current_index = self._sql_param_counters.get(prefixed_base, 0)
|
|
1602
|
+
|
|
1603
|
+
if prefixed_base not in self._named_parameters:
|
|
1604
|
+
self._sql_param_counters[prefixed_base] = current_index
|
|
1605
|
+
return prefixed_base
|
|
1606
|
+
|
|
1607
|
+
next_index = current_index + 1
|
|
1608
|
+
candidate = f"{prefixed_base}_{next_index}"
|
|
1609
|
+
|
|
1610
|
+
while candidate in self._named_parameters:
|
|
1611
|
+
next_index += 1
|
|
1612
|
+
if next_index > _MAX_PARAM_COLLISION_ATTEMPTS:
|
|
1613
|
+
return f"{prefixed_base}_{uuid4().hex[:8]}"
|
|
1614
|
+
candidate = f"{prefixed_base}_{next_index}"
|
|
1615
|
+
|
|
1616
|
+
self._sql_param_counters[prefixed_base] = next_index
|
|
1617
|
+
return candidate
|
|
1618
|
+
|
|
1619
|
+
def _get_shared_expression(self) -> "exp.Expr | None":
|
|
1620
|
+
"""Return the parsed or raw SQLGlot expression without copying; callers must not mutate it."""
|
|
1621
|
+
state = self._processed_state
|
|
1622
|
+
if state is not Empty:
|
|
1623
|
+
return state.parsed_expression
|
|
1624
|
+
return self._raw_expression
|
|
1625
|
+
|
|
1626
|
+
def _current_expression(self) -> exp.Expr:
|
|
1627
|
+
"""Get the current expression or parse the raw SQL.
|
|
1628
|
+
|
|
1629
|
+
Preserves authoring-time parameter names for dynamic query modifiers,
|
|
1630
|
+
then falls back to cached parsed expressions.
|
|
1631
|
+
|
|
1632
|
+
Returns:
|
|
1633
|
+
The SQLGlot expression for this statement
|
|
1634
|
+
"""
|
|
1635
|
+
raw_sql = self._raw_sql
|
|
1636
|
+
state = self._processed_state
|
|
1637
|
+
if (
|
|
1638
|
+
state is not Empty
|
|
1639
|
+
and (
|
|
1640
|
+
state.input_named_parameters
|
|
1641
|
+
or self._positional_parameters
|
|
1642
|
+
or self._named_parameters
|
|
1643
|
+
or not state.parameter_profile.is_empty()
|
|
1644
|
+
)
|
|
1645
|
+
and self._raw_expression is None
|
|
1646
|
+
and raw_sql
|
|
1647
|
+
and self._statement_config.enable_parsing
|
|
1648
|
+
):
|
|
1649
|
+
try:
|
|
1650
|
+
parsed = sqlglot.parse_one(
|
|
1651
|
+
unescape_qmark_operator(raw_sql, dialect=self._dialect)[0], dialect=self._dialect
|
|
1652
|
+
)
|
|
1653
|
+
if isinstance(parsed, exp.Expr):
|
|
1654
|
+
return parsed
|
|
1655
|
+
except ParseError:
|
|
1656
|
+
pass
|
|
1657
|
+
parsed_expression = state.parsed_expression if state is not Empty else None
|
|
1658
|
+
if parsed_expression is not None:
|
|
1659
|
+
return parsed_expression.copy()
|
|
1660
|
+
raw_expression = self._raw_expression
|
|
1661
|
+
if raw_expression is not None:
|
|
1662
|
+
return raw_expression.copy()
|
|
1663
|
+
if not self._statement_config.enable_parsing:
|
|
1664
|
+
return self._wrapped_raw_sql_expression(raw_sql)
|
|
1665
|
+
try:
|
|
1666
|
+
parsed = sqlglot.parse_one(
|
|
1667
|
+
unescape_qmark_operator(raw_sql, dialect=self._dialect)[0], dialect=self._dialect
|
|
1668
|
+
)
|
|
1669
|
+
if isinstance(parsed, exp.Expr):
|
|
1670
|
+
return parsed
|
|
1671
|
+
return self._wrapped_raw_sql_expression(raw_sql)
|
|
1672
|
+
except ParseError:
|
|
1673
|
+
return self._wrapped_raw_sql_expression(raw_sql)
|
|
1674
|
+
|
|
1675
|
+
def _wrapped_raw_sql_expression(self, raw_sql: str) -> exp.Expr:
|
|
1676
|
+
if not raw_sql.strip():
|
|
1677
|
+
msg = "Cannot build an expression from an empty SQL statement."
|
|
1678
|
+
raise sqlspec.exceptions.SQLParsingError(msg)
|
|
1679
|
+
try:
|
|
1680
|
+
return (
|
|
1681
|
+
exp
|
|
1682
|
+
.Select()
|
|
1683
|
+
.select("*")
|
|
1684
|
+
.from_("(" + unescape_qmark_operator(raw_sql, dialect=self._dialect)[0] + ") AS filtered")
|
|
1685
|
+
)
|
|
1686
|
+
except ParseError as exc:
|
|
1687
|
+
msg = f"Failed to parse SQL statement: {exc}"
|
|
1688
|
+
raise with_cause(sqlspec.exceptions.SQLParsingError(msg), exc) from exc
|
|
1689
|
+
|
|
1690
|
+
def _filter_expression(self) -> exp.Expr:
|
|
1691
|
+
"""Return a mutable expression copy for statement filters.
|
|
1692
|
+
|
|
1693
|
+
Filter implementations may modify the returned expression in place. The
|
|
1694
|
+
expression is detached from cached processed state and raw expressions.
|
|
1695
|
+
"""
|
|
1696
|
+
return self._current_expression()
|
|
1697
|
+
|
|
1698
|
+
def _copy_with_expression(self, new_expr: "exp.Expr") -> "SQL":
|
|
1699
|
+
"""Create a new SQL instance with a modified expression.
|
|
1700
|
+
|
|
1701
|
+
Args:
|
|
1702
|
+
new_expr: The new SQLGlot expression
|
|
1703
|
+
|
|
1704
|
+
Returns:
|
|
1705
|
+
New SQL instance with the expression and copied state
|
|
1706
|
+
"""
|
|
1707
|
+
new_sql = self._copy_base(new_expr)
|
|
1708
|
+
new_sql._sql_param_counters = self._sql_param_counters.copy()
|
|
1709
|
+
return new_sql
|
|
1710
|
+
|
|
1711
|
+
def _take_pending_filters(self) -> "tuple[SQL, list[StatementFilter]]":
|
|
1712
|
+
if not self._filters:
|
|
1713
|
+
return self, []
|
|
1714
|
+
copied = self._copy_base(self._raw_expression or self._raw_sql)
|
|
1715
|
+
copied._filters = []
|
|
1716
|
+
return copied, self._filters.copy()
|
|
1717
|
+
|
|
1718
|
+
def _copy_base(self, statement_seed: "str | exp.Expr") -> "SQL":
|
|
1719
|
+
new_sql = SQL(
|
|
1720
|
+
statement_seed,
|
|
1721
|
+
*self._original_parameters,
|
|
1722
|
+
statement_config=self._statement_config,
|
|
1723
|
+
is_many=self._is_many,
|
|
1724
|
+
declared_parameters=self._declared_parameters,
|
|
1725
|
+
)
|
|
1726
|
+
new_sql._named_parameters.update(self._named_parameters)
|
|
1727
|
+
new_sql._positional_parameters = self._positional_parameters.copy()
|
|
1728
|
+
new_sql._filters = self._filters.copy()
|
|
1729
|
+
return new_sql
|
|
1730
|
+
|
|
1731
|
+
def _where_condition(self, condition: exp.Expr) -> "SQL":
|
|
1732
|
+
expression = self._current_expression()
|
|
1733
|
+
new_expr = safe_modify_with_cte(expression, lambda e: apply_where(e, condition))
|
|
1734
|
+
return self._copy_with_expression(new_expr)
|
|
1735
|
+
|
|
1736
|
+
def _where_comparison(self, column: "str | exp.Column", value: Any, condition_factory: "ConditionFactory") -> "SQL":
|
|
1737
|
+
col_name = extract_column_name(column)
|
|
1738
|
+
param_name = self._next_parameter_name(col_name)
|
|
1739
|
+
condition = create_condition(column, param_name, condition_factory)
|
|
1740
|
+
new_sql = self._where_condition(condition)
|
|
1741
|
+
new_sql._named_parameters[param_name] = value
|
|
1742
|
+
return new_sql
|
|
1743
|
+
|
|
1744
|
+
def _where_sequence_membership(
|
|
1745
|
+
self,
|
|
1746
|
+
column: "str | exp.Column",
|
|
1747
|
+
values: "Sequence[Any]",
|
|
1748
|
+
parameter_suffix: str,
|
|
1749
|
+
condition_factory: "Callable[[str | exp.Column, list[str]], exp.Expr]",
|
|
1750
|
+
*,
|
|
1751
|
+
empty_is_false: bool,
|
|
1752
|
+
) -> "SQL":
|
|
1753
|
+
if not values:
|
|
1754
|
+
if not empty_is_false:
|
|
1755
|
+
return self
|
|
1756
|
+
false_condition = exp.EQ(this=exp.Literal.number(1), expression=exp.Literal.number(0))
|
|
1757
|
+
return self._where_condition(false_condition)
|
|
1758
|
+
|
|
1759
|
+
col_name = extract_column_name(column)
|
|
1760
|
+
param_names: list[str] = []
|
|
1761
|
+
param_values: dict[str, Any] = {}
|
|
1762
|
+
for index, value in enumerate(values):
|
|
1763
|
+
param_name = self._next_parameter_name(f"{col_name}_{parameter_suffix}_{index}")
|
|
1764
|
+
param_names.append(param_name)
|
|
1765
|
+
param_values[param_name] = value
|
|
1766
|
+
|
|
1767
|
+
condition = condition_factory(column, param_names)
|
|
1768
|
+
new_sql = self._where_condition(condition)
|
|
1769
|
+
new_sql._named_parameters.update(param_values)
|
|
1770
|
+
return new_sql
|
|
1771
|
+
|
|
1772
|
+
|
|
1773
|
+
@mypyc_attr(allow_interpreted_subclasses=False)
|
|
1774
|
+
class StatementConfig:
|
|
1775
|
+
"""Configuration for SQL statement processing.
|
|
1776
|
+
|
|
1777
|
+
Controls SQL parsing, validation, transformations, parameter handling,
|
|
1778
|
+
and other processing options for SQL statements.
|
|
1779
|
+
"""
|
|
1780
|
+
|
|
1781
|
+
__slots__ = (
|
|
1782
|
+
*SQL_CONFIG_SLOTS,
|
|
1783
|
+
"_cached_pipeline",
|
|
1784
|
+
"_cached_pipeline_epoch",
|
|
1785
|
+
"_dialect_variants",
|
|
1786
|
+
"_has_output_transformer",
|
|
1787
|
+
"_has_transformers",
|
|
1788
|
+
"_has_uncacheable_transformers",
|
|
1789
|
+
"_script_variant",
|
|
1790
|
+
"_user_statement_transformers",
|
|
1791
|
+
)
|
|
1792
|
+
|
|
1793
|
+
def __init__(
|
|
1794
|
+
self,
|
|
1795
|
+
parameter_config: "ParameterStyleConfig | None" = None,
|
|
1796
|
+
enable_parsing: bool = True,
|
|
1797
|
+
enable_validation: bool = True,
|
|
1798
|
+
enable_transformations: bool = True,
|
|
1799
|
+
enable_analysis: bool = False,
|
|
1800
|
+
enable_expression_simplification: bool = False,
|
|
1801
|
+
enable_column_pruning: bool = False,
|
|
1802
|
+
enable_parameter_type_wrapping: bool = True,
|
|
1803
|
+
enable_caching: bool = True,
|
|
1804
|
+
parameter_converter: "ParameterConverter | None" = None,
|
|
1805
|
+
parameter_validator: "ParameterValidator | None" = None,
|
|
1806
|
+
dialect: "DialectType | None" = None,
|
|
1807
|
+
execution_mode: "str | None" = None,
|
|
1808
|
+
execution_args: "dict[str, Any] | None" = None,
|
|
1809
|
+
output_transformer: "Callable[[str, Any], tuple[str, Any]] | None" = None,
|
|
1810
|
+
statement_transformers: "Sequence[Callable[[exp.Expr, Any], tuple[exp.Expr, Any]]] | None" = None,
|
|
1811
|
+
enable_sqlcommenter: bool = False,
|
|
1812
|
+
sqlcommenter_attributes: "dict[str, str | None] | None" = None,
|
|
1813
|
+
sqlcommenter_enable_traceparent: bool = False,
|
|
1814
|
+
sqlcommenter_enable_context: bool = False,
|
|
1815
|
+
) -> None:
|
|
1816
|
+
"""Initialize StatementConfig.
|
|
1817
|
+
|
|
1818
|
+
Args:
|
|
1819
|
+
parameter_config: Parameter style configuration
|
|
1820
|
+
enable_parsing: Enable SQL parsing
|
|
1821
|
+
enable_validation: Run SQL validators
|
|
1822
|
+
enable_transformations: Apply SQL transformers
|
|
1823
|
+
enable_analysis: Run SQL analyzers
|
|
1824
|
+
enable_expression_simplification: Apply expression simplification
|
|
1825
|
+
enable_column_pruning: Remove unused columns from subqueries during select_only
|
|
1826
|
+
enable_parameter_type_wrapping: Wrap parameters with type information
|
|
1827
|
+
enable_caching: Cache processed SQL statements
|
|
1828
|
+
parameter_converter: Handles parameter style conversions
|
|
1829
|
+
parameter_validator: Validates parameter usage and styles
|
|
1830
|
+
dialect: SQL dialect
|
|
1831
|
+
execution_mode: Special execution mode
|
|
1832
|
+
execution_args: Arguments for special execution modes
|
|
1833
|
+
output_transformer: Optional output transformation function
|
|
1834
|
+
statement_transformers: Optional AST transformers executed during compilation
|
|
1835
|
+
enable_sqlcommenter: Auto-append Google SQLCommenter attributes to SQL
|
|
1836
|
+
sqlcommenter_attributes: Static key-value pairs for SQLCommenter comments
|
|
1837
|
+
sqlcommenter_enable_traceparent: Auto-populate W3C traceparent from OpenTelemetry
|
|
1838
|
+
sqlcommenter_enable_context: Read request-scoped attrs from SQLCommenterContext
|
|
1839
|
+
"""
|
|
1840
|
+
self.enable_parsing = enable_parsing
|
|
1841
|
+
self.enable_validation = enable_validation
|
|
1842
|
+
self.enable_transformations = enable_transformations
|
|
1843
|
+
self.enable_analysis = enable_analysis
|
|
1844
|
+
self.enable_expression_simplification = enable_expression_simplification
|
|
1845
|
+
self.enable_column_pruning = enable_column_pruning
|
|
1846
|
+
self.enable_parameter_type_wrapping = enable_parameter_type_wrapping
|
|
1847
|
+
self.enable_caching = enable_caching
|
|
1848
|
+
if parameter_converter is None:
|
|
1849
|
+
if parameter_validator is None:
|
|
1850
|
+
parameter_validator = ParameterValidator()
|
|
1851
|
+
self.parameter_converter = ParameterConverter(parameter_validator)
|
|
1852
|
+
else:
|
|
1853
|
+
self.parameter_converter = parameter_converter
|
|
1854
|
+
|
|
1855
|
+
if parameter_validator is None:
|
|
1856
|
+
self.parameter_validator = self.parameter_converter.validator
|
|
1857
|
+
else:
|
|
1858
|
+
self.parameter_validator = parameter_validator
|
|
1859
|
+
self.parameter_converter.validator = parameter_validator
|
|
1860
|
+
self.parameter_config = parameter_config or ParameterStyleConfig(
|
|
1861
|
+
default_parameter_style=ParameterStyle.QMARK, supported_parameter_styles={ParameterStyle.QMARK}
|
|
1862
|
+
)
|
|
1863
|
+
|
|
1864
|
+
self.dialect = dialect
|
|
1865
|
+
self.execution_mode = execution_mode
|
|
1866
|
+
self.execution_args = execution_args
|
|
1867
|
+
self.enable_sqlcommenter = enable_sqlcommenter
|
|
1868
|
+
self.sqlcommenter_attributes = sqlcommenter_attributes
|
|
1869
|
+
self.sqlcommenter_enable_traceparent = sqlcommenter_enable_traceparent
|
|
1870
|
+
self.sqlcommenter_enable_context = sqlcommenter_enable_context
|
|
1871
|
+
self.output_transformer = output_transformer
|
|
1872
|
+
|
|
1873
|
+
self._user_statement_transformers = tuple(statement_transformers) if statement_transformers else ()
|
|
1874
|
+
all_transformers: list[Callable[..., Any]] = list(self._user_statement_transformers)
|
|
1875
|
+
if enable_sqlcommenter:
|
|
1876
|
+
effective_attrs = dict(sqlcommenter_attributes) if sqlcommenter_attributes else {}
|
|
1877
|
+
if "db_driver" not in effective_attrs and dialect:
|
|
1878
|
+
effective_attrs["db_driver"] = resolve_db_system(str(dialect))
|
|
1879
|
+
self.sqlcommenter_attributes = effective_attrs or None
|
|
1880
|
+
|
|
1881
|
+
sc_transformer = create_sqlcommenter_statement_transformer(
|
|
1882
|
+
attributes=effective_attrs,
|
|
1883
|
+
enable_traceparent=sqlcommenter_enable_traceparent,
|
|
1884
|
+
enable_context=sqlcommenter_enable_context,
|
|
1885
|
+
)
|
|
1886
|
+
all_transformers.append(sc_transformer)
|
|
1887
|
+
|
|
1888
|
+
self.statement_transformers = tuple(all_transformers)
|
|
1889
|
+
self._fingerprint_cache: str | None = None
|
|
1890
|
+
self._hash_cache: int | None = None
|
|
1891
|
+
self._is_frozen = False
|
|
1892
|
+
self._cached_pipeline: Any | None = None
|
|
1893
|
+
self._cached_pipeline_epoch: int = 0
|
|
1894
|
+
self._dialect_variants: dict[str, StatementConfig] | None = None
|
|
1895
|
+
self._script_variant: StatementConfig | None = None
|
|
1896
|
+
self._has_transformers = bool(self._user_statement_transformers)
|
|
1897
|
+
self._has_output_transformer = self.output_transformer is not None
|
|
1898
|
+
self._has_uncacheable_transformers = _config_has_uncacheable_transformers(
|
|
1899
|
+
self.parameter_config, self.output_transformer, self.statement_transformers
|
|
1900
|
+
)
|
|
1901
|
+
|
|
1902
|
+
def __hash__(self) -> int:
|
|
1903
|
+
"""Hash based on configuration settings."""
|
|
1904
|
+
if self._hash_cache is None:
|
|
1905
|
+
self._hash_cache = hash((
|
|
1906
|
+
self.enable_parsing,
|
|
1907
|
+
self.enable_validation,
|
|
1908
|
+
self.enable_transformations,
|
|
1909
|
+
self.enable_analysis,
|
|
1910
|
+
self.enable_expression_simplification,
|
|
1911
|
+
self.enable_column_pruning,
|
|
1912
|
+
self.enable_parameter_type_wrapping,
|
|
1913
|
+
self.enable_caching,
|
|
1914
|
+
str(self.dialect),
|
|
1915
|
+
hash(self.parameter_config),
|
|
1916
|
+
self.execution_mode,
|
|
1917
|
+
self.output_transformer,
|
|
1918
|
+
self.statement_transformers,
|
|
1919
|
+
))
|
|
1920
|
+
return self._hash_cache
|
|
1921
|
+
|
|
1922
|
+
def __reduce__(self) -> "tuple[Any, ...]":
|
|
1923
|
+
"""Reconstruct via the public ctor so copy/pickle work on mypyc native classes."""
|
|
1924
|
+
return (
|
|
1925
|
+
StatementConfig,
|
|
1926
|
+
(
|
|
1927
|
+
self.parameter_config,
|
|
1928
|
+
self.enable_parsing,
|
|
1929
|
+
self.enable_validation,
|
|
1930
|
+
self.enable_transformations,
|
|
1931
|
+
self.enable_analysis,
|
|
1932
|
+
self.enable_expression_simplification,
|
|
1933
|
+
self.enable_column_pruning,
|
|
1934
|
+
self.enable_parameter_type_wrapping,
|
|
1935
|
+
self.enable_caching,
|
|
1936
|
+
self.parameter_converter,
|
|
1937
|
+
self.parameter_validator,
|
|
1938
|
+
self.dialect,
|
|
1939
|
+
self.execution_mode,
|
|
1940
|
+
self.execution_args,
|
|
1941
|
+
self.output_transformer,
|
|
1942
|
+
self._user_statement_transformers,
|
|
1943
|
+
self.enable_sqlcommenter,
|
|
1944
|
+
self.sqlcommenter_attributes,
|
|
1945
|
+
self.sqlcommenter_enable_traceparent,
|
|
1946
|
+
self.sqlcommenter_enable_context,
|
|
1947
|
+
),
|
|
1948
|
+
)
|
|
1949
|
+
|
|
1950
|
+
def __repr__(self) -> str:
|
|
1951
|
+
"""String representation of the StatementConfig instance."""
|
|
1952
|
+
field_strs = [
|
|
1953
|
+
f"parameter_config={self.parameter_config!r}",
|
|
1954
|
+
f"enable_parsing={self.enable_parsing!r}",
|
|
1955
|
+
f"enable_validation={self.enable_validation!r}",
|
|
1956
|
+
f"enable_transformations={self.enable_transformations!r}",
|
|
1957
|
+
f"enable_analysis={self.enable_analysis!r}",
|
|
1958
|
+
f"enable_expression_simplification={self.enable_expression_simplification!r}",
|
|
1959
|
+
f"enable_column_pruning={self.enable_column_pruning!r}",
|
|
1960
|
+
f"enable_parameter_type_wrapping={self.enable_parameter_type_wrapping!r}",
|
|
1961
|
+
f"enable_caching={self.enable_caching!r}",
|
|
1962
|
+
f"parameter_converter={self.parameter_converter!r}",
|
|
1963
|
+
f"parameter_validator={self.parameter_validator!r}",
|
|
1964
|
+
f"dialect={self.dialect!r}",
|
|
1965
|
+
f"execution_mode={self.execution_mode!r}",
|
|
1966
|
+
f"execution_args={self.execution_args!r}",
|
|
1967
|
+
f"output_transformer={self.output_transformer!r}",
|
|
1968
|
+
f"statement_transformers={self.statement_transformers!r}",
|
|
1969
|
+
]
|
|
1970
|
+
return f"{self.__class__.__name__}({', '.join(field_strs)})"
|
|
1971
|
+
|
|
1972
|
+
def __eq__(self, other: object) -> bool:
|
|
1973
|
+
"""Equality comparison."""
|
|
1974
|
+
if not isinstance(other, type(self)):
|
|
1975
|
+
return False
|
|
1976
|
+
|
|
1977
|
+
if not self._compare_parameter_configs(self.parameter_config, other.parameter_config):
|
|
1978
|
+
return False
|
|
1979
|
+
|
|
1980
|
+
return (
|
|
1981
|
+
self.enable_parsing == other.enable_parsing
|
|
1982
|
+
and self.enable_validation == other.enable_validation
|
|
1983
|
+
and self.enable_transformations == other.enable_transformations
|
|
1984
|
+
and self.enable_analysis == other.enable_analysis
|
|
1985
|
+
and self.enable_expression_simplification == other.enable_expression_simplification
|
|
1986
|
+
and self.enable_column_pruning == other.enable_column_pruning
|
|
1987
|
+
and self.enable_parameter_type_wrapping == other.enable_parameter_type_wrapping
|
|
1988
|
+
and self.enable_caching == other.enable_caching
|
|
1989
|
+
and self.dialect == other.dialect
|
|
1990
|
+
and self.execution_mode == other.execution_mode
|
|
1991
|
+
and self.execution_args == other.execution_args
|
|
1992
|
+
and self.output_transformer == other.output_transformer
|
|
1993
|
+
and self.statement_transformers == other.statement_transformers
|
|
1994
|
+
)
|
|
1995
|
+
|
|
1996
|
+
def freeze(self) -> None:
|
|
1997
|
+
"""Mark the configuration as immutable to enable caching."""
|
|
1998
|
+
self._is_frozen = True
|
|
1999
|
+
|
|
2000
|
+
def replace(self, **kwargs: Any) -> "StatementConfig":
|
|
2001
|
+
"""Immutable update pattern.
|
|
2002
|
+
|
|
2003
|
+
Args:
|
|
2004
|
+
**kwargs: Attributes to update
|
|
2005
|
+
|
|
2006
|
+
Returns:
|
|
2007
|
+
New StatementConfig instance with updated attributes
|
|
2008
|
+
"""
|
|
2009
|
+
for key in kwargs:
|
|
2010
|
+
if key not in _PUBLIC_CONFIG_FIELDS:
|
|
2011
|
+
msg = f"{key!r} is not a field in {type(self).__name__}"
|
|
2012
|
+
raise TypeError(msg)
|
|
2013
|
+
|
|
2014
|
+
current_kwargs: dict[str, Any] = {
|
|
2015
|
+
"parameter_config": self.parameter_config,
|
|
2016
|
+
"enable_parsing": self.enable_parsing,
|
|
2017
|
+
"enable_validation": self.enable_validation,
|
|
2018
|
+
"enable_transformations": self.enable_transformations,
|
|
2019
|
+
"enable_analysis": self.enable_analysis,
|
|
2020
|
+
"enable_expression_simplification": self.enable_expression_simplification,
|
|
2021
|
+
"enable_column_pruning": self.enable_column_pruning,
|
|
2022
|
+
"enable_parameter_type_wrapping": self.enable_parameter_type_wrapping,
|
|
2023
|
+
"enable_caching": self.enable_caching,
|
|
2024
|
+
"parameter_converter": self.parameter_converter,
|
|
2025
|
+
"parameter_validator": self.parameter_validator,
|
|
2026
|
+
"dialect": self.dialect,
|
|
2027
|
+
"execution_mode": self.execution_mode,
|
|
2028
|
+
"execution_args": self.execution_args,
|
|
2029
|
+
"output_transformer": self.output_transformer,
|
|
2030
|
+
"statement_transformers": self._user_statement_transformers,
|
|
2031
|
+
"enable_sqlcommenter": self.enable_sqlcommenter,
|
|
2032
|
+
"sqlcommenter_attributes": self.sqlcommenter_attributes,
|
|
2033
|
+
"sqlcommenter_enable_traceparent": self.sqlcommenter_enable_traceparent,
|
|
2034
|
+
"sqlcommenter_enable_context": self.sqlcommenter_enable_context,
|
|
2035
|
+
}
|
|
2036
|
+
current_kwargs.update(kwargs)
|
|
2037
|
+
return type(self)(**current_kwargs)
|
|
2038
|
+
|
|
2039
|
+
def _with_dialect(self, dialect: str) -> "StatementConfig":
|
|
2040
|
+
"""Return this configuration with ``dialect`` set.
|
|
2041
|
+
|
|
2042
|
+
Frozen configurations reuse one derived configuration per dialect, so its cached fingerprint and
|
|
2043
|
+
processing caches carry over between statements.
|
|
2044
|
+
|
|
2045
|
+
Args:
|
|
2046
|
+
dialect: SQLGlot dialect name.
|
|
2047
|
+
|
|
2048
|
+
Returns:
|
|
2049
|
+
Configuration whose ``dialect`` is ``dialect``.
|
|
2050
|
+
"""
|
|
2051
|
+
if not self._is_frozen:
|
|
2052
|
+
return self.replace(dialect=dialect)
|
|
2053
|
+
variants = self._dialect_variants
|
|
2054
|
+
if variants is None:
|
|
2055
|
+
variants = {}
|
|
2056
|
+
self._dialect_variants = variants
|
|
2057
|
+
derived = variants.get(dialect)
|
|
2058
|
+
if derived is None:
|
|
2059
|
+
derived = self.replace(dialect=dialect)
|
|
2060
|
+
derived.freeze()
|
|
2061
|
+
variants[dialect] = derived
|
|
2062
|
+
return derived
|
|
2063
|
+
|
|
2064
|
+
def _with_script_mode(self) -> "StatementConfig":
|
|
2065
|
+
"""Return this configuration with static script compilation enabled.
|
|
2066
|
+
|
|
2067
|
+
Frozen configurations reuse one derived configuration so its cached fingerprint and
|
|
2068
|
+
processing caches carry over between script executions.
|
|
2069
|
+
|
|
2070
|
+
Returns:
|
|
2071
|
+
Configuration whose ``parameter_config.needs_static_script_compilation`` is True.
|
|
2072
|
+
"""
|
|
2073
|
+
if self.parameter_config.needs_static_script_compilation:
|
|
2074
|
+
return self
|
|
2075
|
+
if not self._is_frozen:
|
|
2076
|
+
return self.replace(parameter_config=self.parameter_config.replace(needs_static_script_compilation=True))
|
|
2077
|
+
derived = self._script_variant
|
|
2078
|
+
if derived is None:
|
|
2079
|
+
derived = self.replace(parameter_config=self.parameter_config.replace(needs_static_script_compilation=True))
|
|
2080
|
+
derived.freeze()
|
|
2081
|
+
self._script_variant = derived
|
|
2082
|
+
return derived
|
|
2083
|
+
|
|
2084
|
+
def _compare_parameter_configs(self, config1: Any, config2: Any) -> bool:
|
|
2085
|
+
"""Compare parameter configs."""
|
|
2086
|
+
return bool(
|
|
2087
|
+
config1.default_parameter_style == config2.default_parameter_style
|
|
2088
|
+
and config1.supported_parameter_styles == config2.supported_parameter_styles
|
|
2089
|
+
and config1.supported_execution_parameter_styles == config2.supported_execution_parameter_styles
|
|
2090
|
+
and config1.default_execution_parameter_style == config2.default_execution_parameter_style
|
|
2091
|
+
and config1.type_coercion_map == config2.type_coercion_map
|
|
2092
|
+
and config1.has_native_list_expansion == config2.has_native_list_expansion
|
|
2093
|
+
and config1.needs_static_script_compilation == config2.needs_static_script_compilation
|
|
2094
|
+
and config1.allow_mixed_parameter_styles == config2.allow_mixed_parameter_styles
|
|
2095
|
+
and config1.preserve_parameter_format == config2.preserve_parameter_format
|
|
2096
|
+
and config1.preserve_original_params_for_many == config2.preserve_original_params_for_many
|
|
2097
|
+
and config1.output_transformer == config2.output_transformer
|
|
2098
|
+
and config1.ast_transformer == config2.ast_transformer
|
|
2099
|
+
and config1.json_serializer == config2.json_serializer
|
|
2100
|
+
and config1.json_deserializer == config2.json_deserializer
|
|
2101
|
+
and config1.strict_named_parameters == config2.strict_named_parameters
|
|
2102
|
+
)
|
|
2103
|
+
|
|
2104
|
+
|
|
2105
|
+
_DEFAULT_CONFIG: "StatementConfig | None" = None
|
|
2106
|
+
_REBIND_PROCESSORS: "dict[tuple[int, int], tuple[Any, Any, ParameterProcessor]]" = {}
|
|
2107
|
+
_REBIND_PROCESSOR_CACHE_MAX_SIZE: Final[int] = 256
|
|
2108
|
+
|
|
2109
|
+
|
|
2110
|
+
def get_default_config() -> StatementConfig:
|
|
2111
|
+
"""Get default statement configuration.
|
|
2112
|
+
|
|
2113
|
+
Returns:
|
|
2114
|
+
Cached StatementConfig singleton with default settings.
|
|
2115
|
+
"""
|
|
2116
|
+
global _DEFAULT_CONFIG
|
|
2117
|
+
if _DEFAULT_CONFIG is None:
|
|
2118
|
+
_DEFAULT_CONFIG = StatementConfig()
|
|
2119
|
+
_DEFAULT_CONFIG.freeze()
|
|
2120
|
+
return _DEFAULT_CONFIG
|
|
2121
|
+
|
|
2122
|
+
|
|
2123
|
+
def get_default_parameter_config() -> ParameterStyleConfig:
|
|
2124
|
+
"""Get default parameter configuration.
|
|
2125
|
+
|
|
2126
|
+
Returns:
|
|
2127
|
+
ParameterStyleConfig with QMARK style as default
|
|
2128
|
+
"""
|
|
2129
|
+
return ParameterStyleConfig(
|
|
2130
|
+
default_parameter_style=ParameterStyle.QMARK, supported_parameter_styles={ParameterStyle.QMARK}
|
|
2131
|
+
)
|
|
2132
|
+
|
|
2133
|
+
|
|
2134
|
+
Statement: TypeAlias = str | exp.Expr | SQL
|
|
2135
|
+
|
|
2136
|
+
|
|
2137
|
+
def _rebuild_sql(
|
|
2138
|
+
raw_sql: str,
|
|
2139
|
+
original_parameters: "tuple[Any, ...]",
|
|
2140
|
+
filters: "tuple[Any, ...]",
|
|
2141
|
+
statement_config: "StatementConfig",
|
|
2142
|
+
is_many: bool,
|
|
2143
|
+
is_script: bool,
|
|
2144
|
+
named_parameters: "dict[str, Any]",
|
|
2145
|
+
declared_parameters: "tuple[ParameterDeclaration, ...]",
|
|
2146
|
+
) -> "SQL":
|
|
2147
|
+
"""Reconstruct a SQL instance from pickled / deepcopied state."""
|
|
2148
|
+
new_sql = SQL(
|
|
2149
|
+
raw_sql,
|
|
2150
|
+
*original_parameters,
|
|
2151
|
+
statement_config=statement_config,
|
|
2152
|
+
is_many=is_many,
|
|
2153
|
+
declared_parameters=declared_parameters,
|
|
2154
|
+
)
|
|
2155
|
+
if filters:
|
|
2156
|
+
new_sql._filters.extend(filters)
|
|
2157
|
+
if named_parameters:
|
|
2158
|
+
new_sql._named_parameters.update(named_parameters)
|
|
2159
|
+
if is_script:
|
|
2160
|
+
new_sql._is_script = True
|
|
2161
|
+
return new_sql
|
|
2162
|
+
|
|
2163
|
+
|
|
2164
|
+
def _get_rebind_processor(config: "StatementConfig") -> ParameterProcessor:
|
|
2165
|
+
"""Return a shared stateless ParameterProcessor for cached-statement rebinding."""
|
|
2166
|
+
converter = config.parameter_converter
|
|
2167
|
+
validator = config.parameter_validator
|
|
2168
|
+
key = (id(converter), id(validator))
|
|
2169
|
+
cached = _REBIND_PROCESSORS.get(key)
|
|
2170
|
+
if cached is not None and cached[0] is converter and cached[1] is validator:
|
|
2171
|
+
return cached[2]
|
|
2172
|
+
if len(_REBIND_PROCESSORS) >= _REBIND_PROCESSOR_CACHE_MAX_SIZE:
|
|
2173
|
+
_REBIND_PROCESSORS.clear()
|
|
2174
|
+
processor = ParameterProcessor(converter=converter, validator=validator, cache_max_size=0)
|
|
2175
|
+
_REBIND_PROCESSORS[key] = (converter, validator, processor)
|
|
2176
|
+
return processor
|
|
2177
|
+
|
|
2178
|
+
|
|
2179
|
+
def _parse_order_item(order_item: str, dialect: "str | None", enable_parsing: bool) -> exp.Expr:
|
|
2180
|
+
"""Parse a single ORDER BY item string into a SQLGlot expression."""
|
|
2181
|
+
if "\x00" in order_item or contains_statement_terminator(order_item, dialect):
|
|
2182
|
+
msg = "ORDER BY item must not contain NUL characters or statement separators"
|
|
2183
|
+
raise sqlspec.exceptions.SQLParsingError(msg)
|
|
2184
|
+
normalized = order_item.strip()
|
|
2185
|
+
if not normalized:
|
|
2186
|
+
return exp.column(order_item, copy=False)
|
|
2187
|
+
|
|
2188
|
+
if enable_parsing:
|
|
2189
|
+
try:
|
|
2190
|
+
parsed = sqlglot.parse_one(normalized, dialect=dialect, into=exp.Ordered)
|
|
2191
|
+
except (ParseError, TokenError):
|
|
2192
|
+
parsed = None
|
|
2193
|
+
if parsed is not None:
|
|
2194
|
+
if parsed.find(exp.Command, exp.DDL, exp.DML, exp.Transaction) is not None:
|
|
2195
|
+
msg = "ORDER BY item must be an ordering expression"
|
|
2196
|
+
raise sqlspec.exceptions.SQLParsingError(msg)
|
|
2197
|
+
return default_nulls(parsed, normalized, dialect)
|
|
2198
|
+
|
|
2199
|
+
parts = normalized.rsplit(None, 1)
|
|
2200
|
+
if len(parts) == _ORDER_PARTS_COUNT and parts[1].lower() in {"asc", "desc"}:
|
|
2201
|
+
base_expr = exp.column(parts[0], copy=False) if parts[0] else exp.column(normalized, copy=False)
|
|
2202
|
+
return ordered(base_expr, desc=True if parts[1].lower() == "desc" else None)
|
|
2203
|
+
|
|
2204
|
+
return exp.column(normalized, copy=False)
|
|
2205
|
+
|
|
2206
|
+
|
|
2207
|
+
def _raw_condition(condition: str, dialect: "str | None" = None) -> exp.Expr:
|
|
2208
|
+
"""Wrap an unparsed condition fragment, requiring it to be a single expression."""
|
|
2209
|
+
if contains_statement_terminator(condition, dialect) or _STATEMENT_START_RE.match(condition) is not None:
|
|
2210
|
+
msg = "WHERE condition must be a single expression without statement separators"
|
|
2211
|
+
raise sqlspec.exceptions.SQLParsingError(msg)
|
|
2212
|
+
return exp.Paren(this=exp.Var(this=condition))
|
|
2213
|
+
|
|
2214
|
+
|
|
2215
|
+
def _is_uncacheable_callable(func: Any) -> bool:
|
|
2216
|
+
pending: list[Any] = [func]
|
|
2217
|
+
seen_ids: set[int] = set()
|
|
2218
|
+
while pending:
|
|
2219
|
+
current = pending.pop()
|
|
2220
|
+
if current is None:
|
|
2221
|
+
continue
|
|
2222
|
+
obj_id = id(current)
|
|
2223
|
+
if obj_id in seen_ids:
|
|
2224
|
+
continue
|
|
2225
|
+
seen_ids.add(obj_id)
|
|
2226
|
+
if isinstance(current, (FunctionType, BuiltinFunctionType)):
|
|
2227
|
+
qualname = getattr(current, "__qualname__", "") or ""
|
|
2228
|
+
if "<locals>" in qualname or getattr(current, "__closure__", None) is not None:
|
|
2229
|
+
return True
|
|
2230
|
+
continue
|
|
2231
|
+
if isinstance(current, MethodType):
|
|
2232
|
+
pending.append(current.__self__)
|
|
2233
|
+
pending.append(current.__func__)
|
|
2234
|
+
continue
|
|
2235
|
+
if isinstance(current, partial):
|
|
2236
|
+
return True
|
|
2237
|
+
current_type = type(current)
|
|
2238
|
+
if (
|
|
2239
|
+
getattr(current_type, "__hash__", None) is object.__hash__
|
|
2240
|
+
or getattr(current_type, "__eq__", None) is object.__eq__
|
|
2241
|
+
):
|
|
2242
|
+
return True
|
|
2243
|
+
return False
|
|
2244
|
+
|
|
2245
|
+
|
|
2246
|
+
def _config_has_uncacheable_transformers(
|
|
2247
|
+
param_config: "ParameterStyleConfig", output_transformer: Any, statement_transformers: "tuple[Any, ...]"
|
|
2248
|
+
) -> bool:
|
|
2249
|
+
if param_config.ast_transformer is not None:
|
|
2250
|
+
return True
|
|
2251
|
+
if _is_uncacheable_callable(output_transformer) or _is_uncacheable_callable(param_config.output_transformer):
|
|
2252
|
+
return True
|
|
2253
|
+
return any(_is_uncacheable_callable(transformer) for transformer in statement_transformers)
|