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,1672 @@
|
|
|
1
|
+
"""DuckDB ADK store for Google Agent Development Kit.
|
|
2
|
+
|
|
3
|
+
DuckDB is an OLAP database optimized for analytical queries. This adapter provides:
|
|
4
|
+
- Embedded session storage with zero-configuration setup
|
|
5
|
+
- Excellent performance for analytical queries on session data
|
|
6
|
+
- Native JSON type support for flexible state storage
|
|
7
|
+
- Perfect for development, testing, and analytical workloads
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import contextlib
|
|
11
|
+
from collections.abc import Mapping
|
|
12
|
+
from datetime import UTC, datetime, timedelta
|
|
13
|
+
from typing import TYPE_CHECKING, Any, Final, Literal, NotRequired, TypedDict, cast
|
|
14
|
+
|
|
15
|
+
from sqlspec.config import ADKConfig
|
|
16
|
+
from sqlspec.exceptions import SerializationConflictError
|
|
17
|
+
from sqlspec.extensions.adk import BaseSyncADKStore, StoredEvent, StoredSession, normalize_session_list_options
|
|
18
|
+
from sqlspec.extensions.adk.converters import merge_scoped_state
|
|
19
|
+
from sqlspec.extensions.adk.memory.store import BaseSyncADKMemoryStore
|
|
20
|
+
from sqlspec.utils.logging import get_logger
|
|
21
|
+
from sqlspec.utils.serializers import from_json, to_json
|
|
22
|
+
from sqlspec.utils.text import split_qualified_identifier
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from collections.abc import Sequence
|
|
26
|
+
|
|
27
|
+
from sqlspec.adapters.duckdb.config import DuckDBConfig
|
|
28
|
+
from sqlspec.extensions.adk import SessionOrderBy, StoredMemory
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
__all__ = ("DuckDBADKConfig", "DuckDBADKFTSOptions", "DuckDBADKMemoryStore", "DuckDBADKStore")
|
|
32
|
+
|
|
33
|
+
logger = get_logger("sqlspec.adapters.duckdb.adk.store")
|
|
34
|
+
|
|
35
|
+
DUCKDB_TABLE_NOT_FOUND_ERROR: Final = "does not exist"
|
|
36
|
+
_MAX_STATE_MERGE_ATTEMPTS: Final[int] = 32
|
|
37
|
+
DUCKDB_EVENT_PROJECTION_STRUCT: Final = "STRUCT(author VARCHAR, node_info STRUCT(path VARCHAR))"
|
|
38
|
+
DUCKDB_FTS_ALLOWED_OPTIONS: Final = ("stemmer", "stopwords", "ignore", "strip_accents", "lower", "overwrite")
|
|
39
|
+
DUCKDB_FTS_CREATE_OPTION_ORDER: Final = ("stemmer", "stopwords", "ignore", "strip_accents", "lower", "overwrite")
|
|
40
|
+
DUCKDB_FTS_REFRESH_OPTION_ORDER: Final = ("overwrite", "stemmer", "stopwords", "ignore", "strip_accents", "lower")
|
|
41
|
+
DUCKDB_FTS_DEFAULT_OPTIONS: Final[dict[str, str | int]] = {
|
|
42
|
+
"stemmer": "porter",
|
|
43
|
+
"stopwords": "english",
|
|
44
|
+
"strip_accents": 1,
|
|
45
|
+
"lower": 1,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class DuckDBADKFTSOptions(TypedDict):
|
|
50
|
+
"""DuckDB FTS ``PRAGMA create_fts_index`` options for ADK memory search."""
|
|
51
|
+
|
|
52
|
+
stemmer: NotRequired[str]
|
|
53
|
+
"""Stemmer name. Defaults to ``"porter"``."""
|
|
54
|
+
|
|
55
|
+
stopwords: NotRequired[str]
|
|
56
|
+
"""Stopword table/name. Defaults to ``"english"``."""
|
|
57
|
+
|
|
58
|
+
ignore: NotRequired[str]
|
|
59
|
+
"""Regular expression ignored by DuckDB tokenization."""
|
|
60
|
+
|
|
61
|
+
strip_accents: NotRequired[bool | int]
|
|
62
|
+
"""Whether DuckDB strips accents during tokenization. Defaults to ``1``."""
|
|
63
|
+
|
|
64
|
+
lower: NotRequired[bool | int]
|
|
65
|
+
"""Whether DuckDB lowercases text during tokenization. Defaults to ``1``."""
|
|
66
|
+
|
|
67
|
+
overwrite: NotRequired[bool | int]
|
|
68
|
+
"""Whether initial FTS index creation overwrites an existing index. Defaults to ``0``."""
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class DuckDBADKConfig(ADKConfig):
|
|
72
|
+
"""DuckDB-specific ADK extension settings.
|
|
73
|
+
|
|
74
|
+
Use these keys inside ``extension_config["adk"]`` with the DuckDB ADK stores.
|
|
75
|
+
Shared ADK table and service settings are inherited from :class:`ADKConfig`.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
enable_event_generated_columns: NotRequired[bool]
|
|
79
|
+
"""Create DuckDB virtual generated columns for common ADK event JSON paths."""
|
|
80
|
+
|
|
81
|
+
enable_event_generated_column_indexes: NotRequired[bool]
|
|
82
|
+
"""Index generated event projection columns when generated columns are enabled."""
|
|
83
|
+
|
|
84
|
+
memory_fts_options: NotRequired[DuckDBADKFTSOptions]
|
|
85
|
+
"""DuckDB FTS ``PRAGMA create_fts_index`` options for ADK memory search."""
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class DuckDBADKStore(BaseSyncADKStore["DuckDBConfig"]):
|
|
89
|
+
"""DuckDB ADK store for Google Agent Development Kit.
|
|
90
|
+
|
|
91
|
+
Implements session and event storage for Google Agent Development Kit
|
|
92
|
+
using DuckDB's synchronous driver with a synchronous public API.
|
|
93
|
+
Provides:
|
|
94
|
+
- Session state management with native JSON type
|
|
95
|
+
- Event history with single JSON blob (event_data) plus indexed scalars
|
|
96
|
+
- Native TIMESTAMPTZ type support
|
|
97
|
+
- Manual cascade delete (DuckDB has no FK CASCADE)
|
|
98
|
+
- Columnar storage for analytical queries
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
config: DuckDBConfig with extension_config["adk"] settings.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
__slots__ = ()
|
|
105
|
+
|
|
106
|
+
_max_table_name_parts = 2
|
|
107
|
+
|
|
108
|
+
def __init__(self, config: "DuckDBConfig", *, read_config: "DuckDBConfig | None" = None) -> None:
|
|
109
|
+
"""Initialize DuckDB ADK store.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
read_config: Optional compatible reader for pure reads.
|
|
113
|
+
config: DuckDBConfig instance.
|
|
114
|
+
"""
|
|
115
|
+
super().__init__(config, read_config=read_config)
|
|
116
|
+
|
|
117
|
+
def create_tables(self) -> None:
|
|
118
|
+
"""Create both sessions and events tables if they don't exist."""
|
|
119
|
+
if not self.create_schema_enabled:
|
|
120
|
+
self.reconcile_schema()
|
|
121
|
+
return
|
|
122
|
+
|
|
123
|
+
self._create_tables()
|
|
124
|
+
|
|
125
|
+
def create_session(
|
|
126
|
+
self,
|
|
127
|
+
session_id: str,
|
|
128
|
+
app_name: str,
|
|
129
|
+
user_id: str,
|
|
130
|
+
state: "dict[str, Any]",
|
|
131
|
+
owner_id: "Any | None" = None,
|
|
132
|
+
*,
|
|
133
|
+
app_state_delta: "dict[str, Any] | None" = None,
|
|
134
|
+
user_state_delta: "dict[str, Any] | None" = None,
|
|
135
|
+
) -> StoredSession:
|
|
136
|
+
"""Create a new session and optionally merge scoped state deltas.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
session_id: Unique session identifier.
|
|
140
|
+
app_name: Application name.
|
|
141
|
+
user_id: User identifier.
|
|
142
|
+
state: Initial session state.
|
|
143
|
+
owner_id: Optional owner ID value for owner_id_column (if configured).
|
|
144
|
+
app_state_delta: Optional app-scoped state delta to merge.
|
|
145
|
+
user_state_delta: Optional user-scoped state delta to merge.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
Created session record with merged scoped state.
|
|
149
|
+
"""
|
|
150
|
+
return self._create_session(
|
|
151
|
+
session_id,
|
|
152
|
+
app_name,
|
|
153
|
+
user_id,
|
|
154
|
+
state,
|
|
155
|
+
owner_id,
|
|
156
|
+
app_state_delta=app_state_delta,
|
|
157
|
+
user_state_delta=user_state_delta,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
def get_session(
|
|
161
|
+
self, app_name: str, user_id: str, session_id: str, *, renew_for: "int | timedelta | None" = None
|
|
162
|
+
) -> "StoredSession | None":
|
|
163
|
+
"""Get session by ID.
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
app_name: Application name.
|
|
167
|
+
user_id: User identifier.
|
|
168
|
+
session_id: Session identifier.
|
|
169
|
+
renew_for: If positive, touch the session update timestamp.
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
Session record or None if not found.
|
|
173
|
+
"""
|
|
174
|
+
return self._get_session(app_name, user_id, session_id, renew_for=renew_for, read=renew_for is None)
|
|
175
|
+
|
|
176
|
+
def update_session_state(self, app_name: str, user_id: str, session_id: str, state: "dict[str, Any]") -> None:
|
|
177
|
+
"""Update session state.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
app_name: Application name.
|
|
181
|
+
user_id: User identifier.
|
|
182
|
+
session_id: Session identifier.
|
|
183
|
+
state: New state dictionary (replaces existing state).
|
|
184
|
+
"""
|
|
185
|
+
self._update_session_state(app_name, user_id, session_id, state)
|
|
186
|
+
|
|
187
|
+
def list_sessions(
|
|
188
|
+
self,
|
|
189
|
+
app_name: str,
|
|
190
|
+
user_id: "str | None" = None,
|
|
191
|
+
*,
|
|
192
|
+
order_by: "SessionOrderBy" = "update_time",
|
|
193
|
+
descending: bool = True,
|
|
194
|
+
limit: "int | None" = None,
|
|
195
|
+
offset: "int | None" = None,
|
|
196
|
+
) -> "list[StoredSession]":
|
|
197
|
+
"""List sessions for an app, optionally filtered by user.
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
app_name: Application name.
|
|
201
|
+
user_id: User identifier. If None, lists all sessions for the app.
|
|
202
|
+
order_by: Timestamp column to sort on.
|
|
203
|
+
descending: Sort direction for the timestamp column and the id tie-break.
|
|
204
|
+
limit: Maximum number of sessions to return.
|
|
205
|
+
offset: Number of leading rows to skip.
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
List of session records.
|
|
209
|
+
"""
|
|
210
|
+
return self._list_sessions(
|
|
211
|
+
app_name, user_id, order_by=order_by, descending=descending, limit=limit, offset=offset, read=True
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
def delete_session(self, app_name: str, user_id: str, session_id: str) -> None:
|
|
215
|
+
"""Delete session and all associated events.
|
|
216
|
+
|
|
217
|
+
Args:
|
|
218
|
+
app_name: Application name.
|
|
219
|
+
user_id: User identifier.
|
|
220
|
+
session_id: Session identifier.
|
|
221
|
+
"""
|
|
222
|
+
self._delete_session(app_name, user_id, session_id)
|
|
223
|
+
|
|
224
|
+
def append_event(self, event_record: StoredEvent) -> None:
|
|
225
|
+
"""Append an event to a session.
|
|
226
|
+
|
|
227
|
+
Args:
|
|
228
|
+
event_record: Event record to store.
|
|
229
|
+
"""
|
|
230
|
+
self._append_event(event_record)
|
|
231
|
+
|
|
232
|
+
def append_event_and_update_state(
|
|
233
|
+
self,
|
|
234
|
+
event_record: StoredEvent,
|
|
235
|
+
app_name: str,
|
|
236
|
+
user_id: str,
|
|
237
|
+
session_id: str,
|
|
238
|
+
state: "dict[str, Any]",
|
|
239
|
+
*,
|
|
240
|
+
app_state_delta: "dict[str, Any] | None" = None,
|
|
241
|
+
user_state_delta: "dict[str, Any] | None" = None,
|
|
242
|
+
) -> StoredSession:
|
|
243
|
+
"""Atomically append an event and update the session's durable state.
|
|
244
|
+
|
|
245
|
+
The event insert and state update succeed together or fail together
|
|
246
|
+
within a single DuckDB transaction; the updated StoredSession is
|
|
247
|
+
returned with merged scoped state.
|
|
248
|
+
|
|
249
|
+
Args:
|
|
250
|
+
event_record: Event record to store.
|
|
251
|
+
app_name: Application name.
|
|
252
|
+
user_id: User identifier.
|
|
253
|
+
session_id: Session identifier whose state should be updated.
|
|
254
|
+
state: Post-append durable session-scoped state snapshot.
|
|
255
|
+
app_state_delta: Optional app-scoped state delta to merge.
|
|
256
|
+
user_state_delta: Optional user-scoped state delta to merge.
|
|
257
|
+
"""
|
|
258
|
+
return self._append_event_and_update_state(
|
|
259
|
+
event_record,
|
|
260
|
+
app_name,
|
|
261
|
+
user_id,
|
|
262
|
+
session_id,
|
|
263
|
+
state,
|
|
264
|
+
app_state_delta=app_state_delta,
|
|
265
|
+
user_state_delta=user_state_delta,
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
def get_events(
|
|
269
|
+
self,
|
|
270
|
+
app_name: str,
|
|
271
|
+
user_id: str,
|
|
272
|
+
session_id: str,
|
|
273
|
+
after_timestamp: "datetime | None" = None,
|
|
274
|
+
limit: "int | None" = None,
|
|
275
|
+
) -> "list[StoredEvent]":
|
|
276
|
+
"""Get events for a session.
|
|
277
|
+
|
|
278
|
+
Args:
|
|
279
|
+
app_name: Application name.
|
|
280
|
+
user_id: User identifier.
|
|
281
|
+
session_id: Session identifier.
|
|
282
|
+
after_timestamp: Only return events after this time.
|
|
283
|
+
limit: Maximum number of events to return.
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
List of event records ordered by timestamp ASC.
|
|
287
|
+
"""
|
|
288
|
+
return self._get_events(app_name, user_id, session_id, after_timestamp, limit, read=True)
|
|
289
|
+
|
|
290
|
+
def delete_expired_events(self, before: "datetime", app_name: "str | None" = None) -> int:
|
|
291
|
+
"""Delete events older than a timestamp, optionally scoped to one application."""
|
|
292
|
+
return self._delete_expired_events(before, app_name)
|
|
293
|
+
|
|
294
|
+
def delete_idle_sessions(self, updated_before: "datetime", app_name: "str | None" = None) -> int:
|
|
295
|
+
"""Delete sessions older than a timestamp, optionally scoped to one application."""
|
|
296
|
+
return self._delete_idle_sessions(updated_before, app_name)
|
|
297
|
+
|
|
298
|
+
def delete_idle_user_states(self, updated_before: "datetime", app_name: "str | None" = None) -> int:
|
|
299
|
+
"""Delete user state rows older than a timestamp, optionally scoped to one application."""
|
|
300
|
+
return self._delete_idle_user_states(updated_before, app_name)
|
|
301
|
+
|
|
302
|
+
def get_app_state(self, app_name: str) -> "dict[str, Any] | None":
|
|
303
|
+
"""Return app-scoped state."""
|
|
304
|
+
return self._get_app_state(app_name)
|
|
305
|
+
|
|
306
|
+
def get_user_state(self, app_name: str, user_id: str) -> "dict[str, Any] | None":
|
|
307
|
+
"""Return user-scoped state."""
|
|
308
|
+
return self._get_user_state(app_name, user_id)
|
|
309
|
+
|
|
310
|
+
def upsert_app_state(self, app_name: str, state: "dict[str, Any]") -> None:
|
|
311
|
+
"""Insert or replace app-scoped state."""
|
|
312
|
+
self._upsert_app_state(app_name, state)
|
|
313
|
+
|
|
314
|
+
def upsert_user_state(self, app_name: str, user_id: str, state: "dict[str, Any]") -> None:
|
|
315
|
+
"""Insert or replace user-scoped state."""
|
|
316
|
+
self._upsert_user_state(app_name, user_id, state)
|
|
317
|
+
|
|
318
|
+
def get_metadata(self, key: str) -> "str | None":
|
|
319
|
+
"""Return a metadata value."""
|
|
320
|
+
return self._get_metadata(key)
|
|
321
|
+
|
|
322
|
+
def set_metadata(self, key: str, value: str) -> None:
|
|
323
|
+
"""Set a metadata value."""
|
|
324
|
+
self._set_metadata(key, value)
|
|
325
|
+
|
|
326
|
+
def reconcile_companion_objects_sync(self, driver: Any) -> None:
|
|
327
|
+
"""Create missing session and event companion indexes without committing."""
|
|
328
|
+
for statement in self._companion_index_statements():
|
|
329
|
+
driver.execute(statement)
|
|
330
|
+
|
|
331
|
+
def _session_index_statements(self) -> list[str]:
|
|
332
|
+
"""Return canonical CREATE INDEX statements for the sessions table."""
|
|
333
|
+
return [
|
|
334
|
+
f"CREATE INDEX IF NOT EXISTS {_duckdb_index_name(self._session_table, 'app_user')} ON {self._session_table}(app_name, user_id)"
|
|
335
|
+
]
|
|
336
|
+
|
|
337
|
+
def _event_generated_column_index_statements(self) -> list[str]:
|
|
338
|
+
"""Return optional generated-column index statements for the events table."""
|
|
339
|
+
adk_config = _adk_config(self._config)
|
|
340
|
+
if not (
|
|
341
|
+
adk_config.get("enable_event_generated_columns", False)
|
|
342
|
+
and adk_config.get("enable_event_generated_column_indexes", False)
|
|
343
|
+
):
|
|
344
|
+
return []
|
|
345
|
+
|
|
346
|
+
return [
|
|
347
|
+
f"CREATE INDEX IF NOT EXISTS {_duckdb_index_name(self._events_table, 'author_gc')} ON {self._events_table}(session_id, author_gc, timestamp ASC)",
|
|
348
|
+
f"CREATE INDEX IF NOT EXISTS {_duckdb_index_name(self._events_table, 'node_path_gc')} ON {self._events_table}(session_id, node_path_gc, timestamp ASC)",
|
|
349
|
+
]
|
|
350
|
+
|
|
351
|
+
def _event_index_statements(self) -> list[str]:
|
|
352
|
+
"""Return canonical CREATE INDEX statements for the events table."""
|
|
353
|
+
return [
|
|
354
|
+
f"CREATE INDEX IF NOT EXISTS {_duckdb_index_name(self._events_table, 'session')} ON {self._events_table}(session_id, timestamp ASC)",
|
|
355
|
+
f"CREATE INDEX IF NOT EXISTS {_duckdb_index_name(self._events_table, 'app_timestamp')} ON {self._events_table}(app_name, timestamp ASC)",
|
|
356
|
+
*self._event_generated_column_index_statements(),
|
|
357
|
+
]
|
|
358
|
+
|
|
359
|
+
def _companion_index_statements(self) -> list[str]:
|
|
360
|
+
"""Return canonical CREATE INDEX statements for sessions and events tables."""
|
|
361
|
+
return [*self._session_index_statements(), *self._event_index_statements()]
|
|
362
|
+
|
|
363
|
+
def _sessions_table_ddl(self) -> str:
|
|
364
|
+
"""Get DuckDB CREATE TABLE SQL for sessions.
|
|
365
|
+
|
|
366
|
+
Returns:
|
|
367
|
+
SQL statement to create adk_sessions table with indexes.
|
|
368
|
+
"""
|
|
369
|
+
owner_id_line = ""
|
|
370
|
+
if self._owner_id_column_ddl:
|
|
371
|
+
owner_id_line = f",\n {self._owner_id_column_ddl}"
|
|
372
|
+
|
|
373
|
+
index_lines = "\n".join(f" {stmt};" for stmt in self._session_index_statements())
|
|
374
|
+
return (
|
|
375
|
+
f"\n CREATE TABLE IF NOT EXISTS {self._session_table} (\n"
|
|
376
|
+
f" id VARCHAR PRIMARY KEY,\n"
|
|
377
|
+
f" app_name VARCHAR NOT NULL,\n"
|
|
378
|
+
f" user_id VARCHAR NOT NULL{owner_id_line},\n"
|
|
379
|
+
f" state JSON NOT NULL,\n"
|
|
380
|
+
f" create_time TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,\n"
|
|
381
|
+
f" update_time TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP\n"
|
|
382
|
+
f" );\n"
|
|
383
|
+
f"{index_lines}\n"
|
|
384
|
+
f" "
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
def _events_table_ddl(self) -> str:
|
|
388
|
+
"""Get DuckDB CREATE TABLE SQL for events.
|
|
389
|
+
|
|
390
|
+
Returns:
|
|
391
|
+
SQL statement to create adk_event table with indexes.
|
|
392
|
+
"""
|
|
393
|
+
generated_columns = self._event_generated_columns_sql()
|
|
394
|
+
index_lines = "\n".join(f" {stmt};" for stmt in self._event_index_statements())
|
|
395
|
+
return (
|
|
396
|
+
f"\n CREATE TABLE IF NOT EXISTS {self._events_table} (\n"
|
|
397
|
+
f" id VARCHAR PRIMARY KEY,\n"
|
|
398
|
+
f" app_name VARCHAR NOT NULL,\n"
|
|
399
|
+
f" user_id VARCHAR NOT NULL,\n"
|
|
400
|
+
f" session_id VARCHAR NOT NULL,\n"
|
|
401
|
+
f" invocation_id VARCHAR,\n"
|
|
402
|
+
f" timestamp TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,\n"
|
|
403
|
+
f" event_data JSON NOT NULL{generated_columns},\n"
|
|
404
|
+
f" FOREIGN KEY (session_id) REFERENCES {self._session_table}(id)\n"
|
|
405
|
+
f" );\n"
|
|
406
|
+
f"{index_lines}\n"
|
|
407
|
+
f" "
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
def _event_generated_columns_sql(self) -> str:
|
|
411
|
+
"""Return DuckDB ADK generated event projection columns."""
|
|
412
|
+
adk_config = _adk_config(self._config)
|
|
413
|
+
if not adk_config.get("enable_event_generated_columns", False):
|
|
414
|
+
return ""
|
|
415
|
+
|
|
416
|
+
return f""",
|
|
417
|
+
author_gc VARCHAR GENERATED ALWAYS AS ((event_data::{DUCKDB_EVENT_PROJECTION_STRUCT}).author) VIRTUAL,
|
|
418
|
+
node_path_gc VARCHAR GENERATED ALWAYS AS ((event_data::{DUCKDB_EVENT_PROJECTION_STRUCT}).node_info.path) VIRTUAL"""
|
|
419
|
+
|
|
420
|
+
def _event_generated_column_indexes_sql(self) -> str:
|
|
421
|
+
"""Return optional indexes for generated event projection columns."""
|
|
422
|
+
statements = self._event_generated_column_index_statements()
|
|
423
|
+
if not statements:
|
|
424
|
+
return ""
|
|
425
|
+
return "\n".join(f" {stmt};" for stmt in statements)
|
|
426
|
+
|
|
427
|
+
def _app_states_table_ddl(self) -> str:
|
|
428
|
+
"""Get DuckDB CREATE TABLE SQL for app-scoped state."""
|
|
429
|
+
return f"""
|
|
430
|
+
CREATE TABLE IF NOT EXISTS {self._app_state_table} (
|
|
431
|
+
app_name VARCHAR PRIMARY KEY,
|
|
432
|
+
state JSON NOT NULL,
|
|
433
|
+
update_time TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
434
|
+
)
|
|
435
|
+
"""
|
|
436
|
+
|
|
437
|
+
def _user_states_table_ddl(self) -> str:
|
|
438
|
+
"""Get DuckDB CREATE TABLE SQL for user-scoped state."""
|
|
439
|
+
return f"""
|
|
440
|
+
CREATE TABLE IF NOT EXISTS {self._user_state_table} (
|
|
441
|
+
app_name VARCHAR NOT NULL,
|
|
442
|
+
user_id VARCHAR NOT NULL,
|
|
443
|
+
state JSON NOT NULL,
|
|
444
|
+
update_time TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
445
|
+
PRIMARY KEY (app_name, user_id)
|
|
446
|
+
)
|
|
447
|
+
"""
|
|
448
|
+
|
|
449
|
+
def _metadata_table_ddl(self) -> str:
|
|
450
|
+
"""Get DuckDB CREATE TABLE SQL for internal ADK metadata."""
|
|
451
|
+
return f"""
|
|
452
|
+
CREATE TABLE IF NOT EXISTS {self._metadata_table} (
|
|
453
|
+
key VARCHAR PRIMARY KEY,
|
|
454
|
+
value VARCHAR NOT NULL
|
|
455
|
+
)
|
|
456
|
+
"""
|
|
457
|
+
|
|
458
|
+
def _drop_app_states_table_sql(self) -> str:
|
|
459
|
+
"""Get DuckDB DROP TABLE SQL for app-scoped state."""
|
|
460
|
+
return f"DROP TABLE IF EXISTS {self._app_state_table}"
|
|
461
|
+
|
|
462
|
+
def _drop_user_states_table_sql(self) -> str:
|
|
463
|
+
"""Get DuckDB DROP TABLE SQL for user-scoped state."""
|
|
464
|
+
return f"DROP TABLE IF EXISTS {self._user_state_table}"
|
|
465
|
+
|
|
466
|
+
def _drop_metadata_table_sql(self) -> str:
|
|
467
|
+
"""Get DuckDB DROP TABLE SQL for internal ADK metadata."""
|
|
468
|
+
return f"DROP TABLE IF EXISTS {self._metadata_table}"
|
|
469
|
+
|
|
470
|
+
def _drop_tables_sql(self) -> "list[str]":
|
|
471
|
+
"""Get DuckDB DROP TABLE SQL statements.
|
|
472
|
+
|
|
473
|
+
Returns:
|
|
474
|
+
List of SQL statements to drop tables and indexes.
|
|
475
|
+
"""
|
|
476
|
+
return [
|
|
477
|
+
self._drop_metadata_table_sql(),
|
|
478
|
+
self._drop_user_states_table_sql(),
|
|
479
|
+
self._drop_app_states_table_sql(),
|
|
480
|
+
f"DROP TABLE IF EXISTS {self._events_table}",
|
|
481
|
+
f"DROP TABLE IF EXISTS {self._session_table}",
|
|
482
|
+
]
|
|
483
|
+
|
|
484
|
+
def _create_tables(self) -> None:
|
|
485
|
+
"""Synchronous implementation of create_tables."""
|
|
486
|
+
with self._config.provide_connection() as conn:
|
|
487
|
+
conn.execute(self._sessions_table_ddl())
|
|
488
|
+
conn.execute(self._events_table_ddl())
|
|
489
|
+
conn.execute(self._app_states_table_ddl())
|
|
490
|
+
conn.execute(self._user_states_table_ddl())
|
|
491
|
+
conn.execute(self._metadata_table_ddl())
|
|
492
|
+
conn.commit()
|
|
493
|
+
|
|
494
|
+
def _create_session(
|
|
495
|
+
self,
|
|
496
|
+
session_id: str,
|
|
497
|
+
app_name: str,
|
|
498
|
+
user_id: str,
|
|
499
|
+
state: "dict[str, Any]",
|
|
500
|
+
owner_id: "Any | None" = None,
|
|
501
|
+
*,
|
|
502
|
+
app_state_delta: "dict[str, Any] | None" = None,
|
|
503
|
+
user_state_delta: "dict[str, Any] | None" = None,
|
|
504
|
+
) -> StoredSession:
|
|
505
|
+
"""Synchronous implementation of create_session."""
|
|
506
|
+
now = datetime.now(UTC)
|
|
507
|
+
session_state = dict(state)
|
|
508
|
+
state_json = to_json(session_state)
|
|
509
|
+
|
|
510
|
+
params: tuple[Any, ...]
|
|
511
|
+
if self._owner_id_column_name:
|
|
512
|
+
sql = f"""
|
|
513
|
+
INSERT INTO {self._session_table}
|
|
514
|
+
(id, app_name, user_id, {self._owner_id_column_name}, state, create_time, update_time)
|
|
515
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
516
|
+
"""
|
|
517
|
+
params = (session_id, app_name, user_id, owner_id, state_json, now, now)
|
|
518
|
+
else:
|
|
519
|
+
sql = f"""
|
|
520
|
+
INSERT INTO {self._session_table} (id, app_name, user_id, state, create_time, update_time)
|
|
521
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
522
|
+
"""
|
|
523
|
+
params = (session_id, app_name, user_id, state_json, now, now)
|
|
524
|
+
|
|
525
|
+
has_deltas = bool(app_state_delta or user_state_delta)
|
|
526
|
+
max_attempts = _MAX_STATE_MERGE_ATTEMPTS if has_deltas else 1
|
|
527
|
+
with self._config.provide_connection() as conn:
|
|
528
|
+
for _ in range(max_attempts):
|
|
529
|
+
scoped_started = False
|
|
530
|
+
in_tx = False
|
|
531
|
+
try:
|
|
532
|
+
conn.execute("BEGIN TRANSACTION")
|
|
533
|
+
in_tx = True
|
|
534
|
+
conn.execute(sql, params)
|
|
535
|
+
scoped_started = True
|
|
536
|
+
current_app_state = (
|
|
537
|
+
self._apply_app_state_delta(conn, app_name, app_state_delta)
|
|
538
|
+
if app_state_delta
|
|
539
|
+
else self._select_state(
|
|
540
|
+
conn, f"SELECT state FROM {self._app_state_table} WHERE app_name = ?", (app_name,)
|
|
541
|
+
)
|
|
542
|
+
)
|
|
543
|
+
current_user_state = (
|
|
544
|
+
self._apply_user_state_delta(conn, app_name, user_id, user_state_delta)
|
|
545
|
+
if user_state_delta
|
|
546
|
+
else self._select_state(
|
|
547
|
+
conn,
|
|
548
|
+
f"SELECT state FROM {self._user_state_table} WHERE app_name = ? AND user_id = ?",
|
|
549
|
+
(app_name, user_id),
|
|
550
|
+
)
|
|
551
|
+
)
|
|
552
|
+
if (app_state_delta and current_app_state is None) or (
|
|
553
|
+
user_state_delta and current_user_state is None
|
|
554
|
+
):
|
|
555
|
+
conn.rollback()
|
|
556
|
+
in_tx = False
|
|
557
|
+
continue
|
|
558
|
+
conn.commit()
|
|
559
|
+
in_tx = False
|
|
560
|
+
return StoredSession(
|
|
561
|
+
id=session_id,
|
|
562
|
+
app_name=app_name,
|
|
563
|
+
user_id=user_id,
|
|
564
|
+
state=merge_scoped_state(session_state, current_app_state, current_user_state),
|
|
565
|
+
create_time=now,
|
|
566
|
+
update_time=now,
|
|
567
|
+
)
|
|
568
|
+
except Exception as exc:
|
|
569
|
+
if in_tx:
|
|
570
|
+
with contextlib.suppress(Exception):
|
|
571
|
+
conn.rollback()
|
|
572
|
+
if scoped_started and _is_retryable_error(exc, allow_unique_conflict=has_deltas):
|
|
573
|
+
continue
|
|
574
|
+
raise
|
|
575
|
+
msg = f"Failed to merge scoped state during create_session after {max_attempts} attempts."
|
|
576
|
+
raise SerializationConflictError(msg)
|
|
577
|
+
|
|
578
|
+
def _get_session(
|
|
579
|
+
self,
|
|
580
|
+
app_name: str,
|
|
581
|
+
user_id: str,
|
|
582
|
+
session_id: str,
|
|
583
|
+
*,
|
|
584
|
+
renew_for: "int | timedelta | None" = None,
|
|
585
|
+
read: bool = False,
|
|
586
|
+
) -> "StoredSession | None":
|
|
587
|
+
"""Synchronous implementation of get_session."""
|
|
588
|
+
select_sql = f"""
|
|
589
|
+
SELECT id, app_name, user_id, state, create_time, update_time
|
|
590
|
+
FROM {self._session_table}
|
|
591
|
+
WHERE app_name = ? AND user_id = ? AND id = ?
|
|
592
|
+
"""
|
|
593
|
+
params: list[Any] = [app_name, user_id, session_id]
|
|
594
|
+
|
|
595
|
+
try:
|
|
596
|
+
with self._provide_replica_connection(primary=not read) as conn:
|
|
597
|
+
if self._is_renewal_requested(renew_for):
|
|
598
|
+
renew_sql = f"""
|
|
599
|
+
UPDATE {self._session_table}
|
|
600
|
+
SET update_time = ?
|
|
601
|
+
WHERE app_name = ? AND user_id = ? AND id = ?
|
|
602
|
+
"""
|
|
603
|
+
conn.execute(renew_sql, [datetime.now(UTC), app_name, user_id, session_id])
|
|
604
|
+
conn.commit()
|
|
605
|
+
cursor = conn.execute(select_sql, params)
|
|
606
|
+
row = cursor.fetchone()
|
|
607
|
+
|
|
608
|
+
if row is None:
|
|
609
|
+
return None
|
|
610
|
+
|
|
611
|
+
session_id_val, app_name, user_id, state_data, create_time, update_time = row
|
|
612
|
+
|
|
613
|
+
state = from_json(state_data) if state_data else {}
|
|
614
|
+
|
|
615
|
+
return StoredSession(
|
|
616
|
+
id=session_id_val,
|
|
617
|
+
app_name=app_name,
|
|
618
|
+
user_id=user_id,
|
|
619
|
+
state=state,
|
|
620
|
+
create_time=create_time,
|
|
621
|
+
update_time=update_time,
|
|
622
|
+
)
|
|
623
|
+
except Exception as e:
|
|
624
|
+
if DUCKDB_TABLE_NOT_FOUND_ERROR in str(e):
|
|
625
|
+
return None
|
|
626
|
+
raise
|
|
627
|
+
|
|
628
|
+
def _update_session_state(self, app_name: str, user_id: str, session_id: str, state: "dict[str, Any]") -> None:
|
|
629
|
+
"""Synchronous implementation of update_session_state."""
|
|
630
|
+
now = datetime.now(UTC)
|
|
631
|
+
state_json = to_json(state)
|
|
632
|
+
|
|
633
|
+
sql = f"""
|
|
634
|
+
UPDATE {self._session_table}
|
|
635
|
+
SET state = ?, update_time = ?
|
|
636
|
+
WHERE app_name = ? AND user_id = ? AND id = ?
|
|
637
|
+
"""
|
|
638
|
+
|
|
639
|
+
with self._config.provide_connection() as conn:
|
|
640
|
+
conn.execute(sql, (state_json, now, app_name, user_id, session_id))
|
|
641
|
+
conn.commit()
|
|
642
|
+
|
|
643
|
+
def _delete_session(self, app_name: str, user_id: str, session_id: str) -> None:
|
|
644
|
+
"""Synchronous implementation of delete_session."""
|
|
645
|
+
owner_check_sql = f"SELECT 1 FROM {self._session_table} WHERE app_name = ? AND user_id = ? AND id = ?"
|
|
646
|
+
delete_events_sql = f"DELETE FROM {self._events_table} WHERE app_name = ? AND user_id = ? AND session_id = ?"
|
|
647
|
+
delete_session_sql = f"DELETE FROM {self._session_table} WHERE app_name = ? AND user_id = ? AND id = ?"
|
|
648
|
+
|
|
649
|
+
with self._config.provide_connection() as conn:
|
|
650
|
+
if conn.execute(owner_check_sql, (app_name, user_id, session_id)).fetchone() is None:
|
|
651
|
+
return
|
|
652
|
+
conn.begin()
|
|
653
|
+
try:
|
|
654
|
+
conn.execute(delete_events_sql, (app_name, user_id, session_id))
|
|
655
|
+
conn.commit()
|
|
656
|
+
conn.begin()
|
|
657
|
+
conn.execute(delete_session_sql, (app_name, user_id, session_id))
|
|
658
|
+
conn.commit()
|
|
659
|
+
except Exception:
|
|
660
|
+
conn.rollback()
|
|
661
|
+
raise
|
|
662
|
+
|
|
663
|
+
def _list_sessions(
|
|
664
|
+
self,
|
|
665
|
+
app_name: str,
|
|
666
|
+
user_id: "str | None" = None,
|
|
667
|
+
*,
|
|
668
|
+
order_by: "SessionOrderBy" = "update_time",
|
|
669
|
+
descending: bool = True,
|
|
670
|
+
limit: "int | None" = None,
|
|
671
|
+
offset: "int | None" = None,
|
|
672
|
+
read: bool = False,
|
|
673
|
+
) -> "list[StoredSession]":
|
|
674
|
+
"""Synchronous implementation of list_sessions."""
|
|
675
|
+
column, direction, page_limit, page_offset = normalize_session_list_options(order_by, descending, limit, offset)
|
|
676
|
+
if page_limit == 0:
|
|
677
|
+
return []
|
|
678
|
+
|
|
679
|
+
sql, params = _session_list_query(
|
|
680
|
+
self._session_table, app_name, user_id, column, direction, page_limit, page_offset
|
|
681
|
+
)
|
|
682
|
+
|
|
683
|
+
try:
|
|
684
|
+
with self._provide_replica_connection(primary=not read) as conn:
|
|
685
|
+
cursor = conn.execute(sql, params)
|
|
686
|
+
rows = cursor.fetchall()
|
|
687
|
+
|
|
688
|
+
return [
|
|
689
|
+
StoredSession(
|
|
690
|
+
id=row[0],
|
|
691
|
+
app_name=row[1],
|
|
692
|
+
user_id=row[2],
|
|
693
|
+
state=from_json(row[3]) if row[3] else {},
|
|
694
|
+
create_time=row[4],
|
|
695
|
+
update_time=row[5],
|
|
696
|
+
)
|
|
697
|
+
for row in rows
|
|
698
|
+
]
|
|
699
|
+
except Exception as e:
|
|
700
|
+
if DUCKDB_TABLE_NOT_FOUND_ERROR in str(e):
|
|
701
|
+
return []
|
|
702
|
+
raise
|
|
703
|
+
|
|
704
|
+
def _append_event(self, event_record: StoredEvent) -> None:
|
|
705
|
+
"""Synchronous implementation of append_event."""
|
|
706
|
+
app_name = event_record["app_name"]
|
|
707
|
+
user_id = event_record["user_id"]
|
|
708
|
+
session_id = event_record["session_id"]
|
|
709
|
+
event_data_str = to_json(event_record["event_data"])
|
|
710
|
+
|
|
711
|
+
sql = f"""
|
|
712
|
+
INSERT INTO {self._events_table}
|
|
713
|
+
(id, app_name, user_id, session_id, invocation_id, timestamp, event_data)
|
|
714
|
+
SELECT ?, ?, ?, ?, ?, ?, ?
|
|
715
|
+
WHERE EXISTS (
|
|
716
|
+
SELECT 1 FROM {self._session_table}
|
|
717
|
+
WHERE id = ? AND app_name = ? AND user_id = ?
|
|
718
|
+
)
|
|
719
|
+
RETURNING 1
|
|
720
|
+
"""
|
|
721
|
+
|
|
722
|
+
with self._config.provide_connection() as conn:
|
|
723
|
+
cursor = conn.execute(
|
|
724
|
+
sql,
|
|
725
|
+
(
|
|
726
|
+
event_record["id"],
|
|
727
|
+
app_name,
|
|
728
|
+
user_id,
|
|
729
|
+
session_id,
|
|
730
|
+
event_record["invocation_id"],
|
|
731
|
+
event_record["timestamp"],
|
|
732
|
+
event_data_str,
|
|
733
|
+
session_id,
|
|
734
|
+
app_name,
|
|
735
|
+
user_id,
|
|
736
|
+
),
|
|
737
|
+
)
|
|
738
|
+
inserted = cursor.fetchone()
|
|
739
|
+
conn.commit()
|
|
740
|
+
if inserted is None:
|
|
741
|
+
msg = f"Session {session_id} not found for app={app_name!r}, user={user_id!r}"
|
|
742
|
+
raise ValueError(msg)
|
|
743
|
+
|
|
744
|
+
def _append_event_and_update_state(
|
|
745
|
+
self,
|
|
746
|
+
event_record: StoredEvent,
|
|
747
|
+
app_name: str,
|
|
748
|
+
user_id: str,
|
|
749
|
+
session_id: str,
|
|
750
|
+
state: "dict[str, Any]",
|
|
751
|
+
*,
|
|
752
|
+
app_state_delta: "dict[str, Any] | None" = None,
|
|
753
|
+
user_state_delta: "dict[str, Any] | None" = None,
|
|
754
|
+
) -> StoredSession:
|
|
755
|
+
"""Synchronous implementation of append_event_and_update_state."""
|
|
756
|
+
if (event_record["app_name"], event_record["user_id"], event_record["session_id"]) != (
|
|
757
|
+
app_name,
|
|
758
|
+
user_id,
|
|
759
|
+
session_id,
|
|
760
|
+
):
|
|
761
|
+
msg = (
|
|
762
|
+
f"Event scope ({event_record['app_name']!r}, {event_record['user_id']!r}, "
|
|
763
|
+
f"{event_record['session_id']!r}) does not match target ({app_name!r}, {user_id!r}, {session_id!r})."
|
|
764
|
+
)
|
|
765
|
+
raise ValueError(msg)
|
|
766
|
+
|
|
767
|
+
session_state = dict(state)
|
|
768
|
+
state_json = to_json(session_state)
|
|
769
|
+
event_data_str = to_json(event_record["event_data"])
|
|
770
|
+
|
|
771
|
+
insert_sql = f"""
|
|
772
|
+
INSERT INTO {self._events_table}
|
|
773
|
+
(id, app_name, user_id, session_id, invocation_id, timestamp, event_data)
|
|
774
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
775
|
+
"""
|
|
776
|
+
|
|
777
|
+
update_sql = f"""
|
|
778
|
+
UPDATE {self._session_table}
|
|
779
|
+
SET state = ?, update_time = ?
|
|
780
|
+
WHERE app_name = ? AND user_id = ? AND id = ?
|
|
781
|
+
"""
|
|
782
|
+
select_sql = f"""
|
|
783
|
+
SELECT id, app_name, user_id, state, create_time, update_time
|
|
784
|
+
FROM {self._session_table}
|
|
785
|
+
WHERE app_name = ? AND user_id = ? AND id = ?
|
|
786
|
+
"""
|
|
787
|
+
|
|
788
|
+
has_deltas = bool(app_state_delta or user_state_delta)
|
|
789
|
+
max_attempts = _MAX_STATE_MERGE_ATTEMPTS if has_deltas else 1
|
|
790
|
+
with self._config.provide_connection() as conn:
|
|
791
|
+
for _ in range(max_attempts):
|
|
792
|
+
now = datetime.now(UTC)
|
|
793
|
+
in_tx = False
|
|
794
|
+
try:
|
|
795
|
+
conn.execute("BEGIN TRANSACTION")
|
|
796
|
+
in_tx = True
|
|
797
|
+
conn.execute(update_sql, (state_json, now, app_name, user_id, session_id))
|
|
798
|
+
row = conn.execute(select_sql, (app_name, user_id, session_id)).fetchone()
|
|
799
|
+
if row is None:
|
|
800
|
+
_raise_session_not_found(session_id)
|
|
801
|
+
assert row is not None
|
|
802
|
+
conn.execute(
|
|
803
|
+
insert_sql,
|
|
804
|
+
(
|
|
805
|
+
event_record["id"],
|
|
806
|
+
event_record["app_name"],
|
|
807
|
+
event_record["user_id"],
|
|
808
|
+
event_record["session_id"],
|
|
809
|
+
event_record["invocation_id"],
|
|
810
|
+
event_record["timestamp"],
|
|
811
|
+
event_data_str,
|
|
812
|
+
),
|
|
813
|
+
)
|
|
814
|
+
merged_app_state: dict[str, Any] | None = None
|
|
815
|
+
if app_state_delta:
|
|
816
|
+
merged_app_state = self._apply_app_state_delta(conn, app_name, app_state_delta)
|
|
817
|
+
if merged_app_state is None:
|
|
818
|
+
conn.rollback()
|
|
819
|
+
in_tx = False
|
|
820
|
+
continue
|
|
821
|
+
merged_user_state: dict[str, Any] | None = None
|
|
822
|
+
if user_state_delta:
|
|
823
|
+
merged_user_state = self._apply_user_state_delta(conn, app_name, user_id, user_state_delta)
|
|
824
|
+
if merged_user_state is None:
|
|
825
|
+
conn.rollback()
|
|
826
|
+
in_tx = False
|
|
827
|
+
continue
|
|
828
|
+
conn.commit()
|
|
829
|
+
in_tx = False
|
|
830
|
+
session_id_val, row_app_name, row_user_id, state_data, create_time, update_time = row
|
|
831
|
+
stored_session_state = from_json(state_data) if isinstance(state_data, str) else state_data
|
|
832
|
+
return StoredSession(
|
|
833
|
+
id=session_id_val,
|
|
834
|
+
app_name=row_app_name,
|
|
835
|
+
user_id=row_user_id,
|
|
836
|
+
state=merge_scoped_state(stored_session_state or {}, merged_app_state, merged_user_state),
|
|
837
|
+
create_time=create_time,
|
|
838
|
+
update_time=update_time,
|
|
839
|
+
)
|
|
840
|
+
except Exception as exc:
|
|
841
|
+
if in_tx:
|
|
842
|
+
with contextlib.suppress(Exception):
|
|
843
|
+
conn.rollback()
|
|
844
|
+
if _is_retryable_error(exc, allow_unique_conflict=has_deltas):
|
|
845
|
+
continue
|
|
846
|
+
raise
|
|
847
|
+
msg = f"Failed to merge scoped state during append_event_and_update_state after {max_attempts} attempts."
|
|
848
|
+
raise SerializationConflictError(msg)
|
|
849
|
+
|
|
850
|
+
def _select_state(self, conn: Any, sql: str, params: "tuple[Any, ...]") -> "dict[str, Any] | None":
|
|
851
|
+
try:
|
|
852
|
+
row = conn.execute(sql, params).fetchone()
|
|
853
|
+
except Exception as exc:
|
|
854
|
+
if DUCKDB_TABLE_NOT_FOUND_ERROR in str(exc):
|
|
855
|
+
return None
|
|
856
|
+
raise
|
|
857
|
+
if row is None:
|
|
858
|
+
return None
|
|
859
|
+
return cast("dict[str, Any]", from_json(row[0]) if isinstance(row[0], str) else row[0])
|
|
860
|
+
|
|
861
|
+
def _apply_app_state_delta(self, conn: Any, app_name: str, delta: "dict[str, Any]") -> "dict[str, Any] | None":
|
|
862
|
+
return self._apply_state_delta(
|
|
863
|
+
conn,
|
|
864
|
+
table=self._app_state_table,
|
|
865
|
+
where_sql="app_name = ?",
|
|
866
|
+
insert_cols="app_name",
|
|
867
|
+
insert_vals="?",
|
|
868
|
+
conflict_cols="app_name",
|
|
869
|
+
key_params=(app_name,),
|
|
870
|
+
delta=delta,
|
|
871
|
+
)
|
|
872
|
+
|
|
873
|
+
def _apply_user_state_delta(
|
|
874
|
+
self, conn: Any, app_name: str, user_id: str, delta: "dict[str, Any]"
|
|
875
|
+
) -> "dict[str, Any] | None":
|
|
876
|
+
return self._apply_state_delta(
|
|
877
|
+
conn,
|
|
878
|
+
table=self._user_state_table,
|
|
879
|
+
where_sql="app_name = ? AND user_id = ?",
|
|
880
|
+
insert_cols="app_name, user_id",
|
|
881
|
+
insert_vals="?, ?",
|
|
882
|
+
conflict_cols="app_name, user_id",
|
|
883
|
+
key_params=(app_name, user_id),
|
|
884
|
+
delta=delta,
|
|
885
|
+
)
|
|
886
|
+
|
|
887
|
+
def _apply_state_delta(
|
|
888
|
+
self,
|
|
889
|
+
conn: Any,
|
|
890
|
+
*,
|
|
891
|
+
table: str,
|
|
892
|
+
where_sql: str,
|
|
893
|
+
insert_cols: str,
|
|
894
|
+
insert_vals: str,
|
|
895
|
+
conflict_cols: str,
|
|
896
|
+
key_params: "tuple[Any, ...]",
|
|
897
|
+
delta: "dict[str, Any]",
|
|
898
|
+
) -> "dict[str, Any] | None":
|
|
899
|
+
row = conn.execute(f"SELECT state, update_time FROM {table} WHERE {where_sql}", key_params).fetchone()
|
|
900
|
+
if row is None:
|
|
901
|
+
merged = dict(delta)
|
|
902
|
+
now = datetime.now(UTC)
|
|
903
|
+
inserted = conn.execute(
|
|
904
|
+
f"INSERT INTO {table} ({insert_cols}, state, update_time) VALUES ({insert_vals}, ?, ?) "
|
|
905
|
+
f"ON CONFLICT({conflict_cols}) DO NOTHING RETURNING state",
|
|
906
|
+
(*key_params, to_json(merged), now),
|
|
907
|
+
).fetchone()
|
|
908
|
+
return merged if inserted is not None else None
|
|
909
|
+
existing = cast("dict[str, Any]", from_json(row[0]) if isinstance(row[0], str) else (row[0] or {}))
|
|
910
|
+
expected_update_time = row[1]
|
|
911
|
+
merged = {**existing, **delta}
|
|
912
|
+
new_update_time = _next_monotonic_timestamp(expected_update_time)
|
|
913
|
+
updated = conn.execute(
|
|
914
|
+
f"UPDATE {table} SET state = ?, update_time = ? WHERE {where_sql} AND update_time = ? RETURNING state",
|
|
915
|
+
(to_json(merged), new_update_time, *key_params, expected_update_time),
|
|
916
|
+
).fetchone()
|
|
917
|
+
return merged if updated is not None else None
|
|
918
|
+
|
|
919
|
+
def _get_events(
|
|
920
|
+
self,
|
|
921
|
+
app_name: str,
|
|
922
|
+
user_id: str,
|
|
923
|
+
session_id: str,
|
|
924
|
+
after_timestamp: "datetime | None" = None,
|
|
925
|
+
limit: "int | None" = None,
|
|
926
|
+
*,
|
|
927
|
+
read: bool = False,
|
|
928
|
+
) -> "list[StoredEvent]":
|
|
929
|
+
"""Synchronous implementation of get_events."""
|
|
930
|
+
if limit == 0:
|
|
931
|
+
return []
|
|
932
|
+
|
|
933
|
+
where_clauses = ["s.app_name = ?", "s.user_id = ?", "s.id = ?"]
|
|
934
|
+
params: list[Any] = [app_name, user_id, session_id]
|
|
935
|
+
|
|
936
|
+
if after_timestamp is not None:
|
|
937
|
+
where_clauses.append("e.timestamp > ?")
|
|
938
|
+
params.append(after_timestamp)
|
|
939
|
+
|
|
940
|
+
where_clause = " AND ".join(where_clauses)
|
|
941
|
+
if limit is not None:
|
|
942
|
+
params.append(limit)
|
|
943
|
+
order_and_limit = "ORDER BY e.timestamp DESC, e.rowid DESC LIMIT ?"
|
|
944
|
+
else:
|
|
945
|
+
order_and_limit = "ORDER BY e.timestamp ASC"
|
|
946
|
+
|
|
947
|
+
sql = f"""
|
|
948
|
+
SELECT e.id, e.session_id, e.invocation_id, e.timestamp, e.event_data, s.app_name, s.user_id
|
|
949
|
+
FROM {self._events_table} e
|
|
950
|
+
JOIN {self._session_table} s ON e.session_id = s.id AND e.app_name = s.app_name AND e.user_id = s.user_id
|
|
951
|
+
WHERE {where_clause}
|
|
952
|
+
{order_and_limit}
|
|
953
|
+
"""
|
|
954
|
+
|
|
955
|
+
try:
|
|
956
|
+
with self._provide_replica_connection(primary=not read) as conn:
|
|
957
|
+
cursor = conn.execute(sql, params)
|
|
958
|
+
rows = cursor.fetchall()
|
|
959
|
+
if limit is not None:
|
|
960
|
+
rows = list(reversed(rows))
|
|
961
|
+
|
|
962
|
+
return [
|
|
963
|
+
StoredEvent(
|
|
964
|
+
id=row[0],
|
|
965
|
+
session_id=row[1],
|
|
966
|
+
invocation_id=row[2],
|
|
967
|
+
timestamp=row[3],
|
|
968
|
+
event_data=from_json(row[4]) if isinstance(row[4], str) else row[4],
|
|
969
|
+
app_name=row[5],
|
|
970
|
+
user_id=row[6],
|
|
971
|
+
)
|
|
972
|
+
for row in rows
|
|
973
|
+
]
|
|
974
|
+
except Exception as e:
|
|
975
|
+
if DUCKDB_TABLE_NOT_FOUND_ERROR in str(e):
|
|
976
|
+
return []
|
|
977
|
+
raise
|
|
978
|
+
|
|
979
|
+
def _delete_expired_events(self, before: "datetime", app_name: "str | None" = None) -> int:
|
|
980
|
+
where = "WHERE timestamp < ?"
|
|
981
|
+
params: tuple[Any, ...] = (before,)
|
|
982
|
+
if app_name is not None:
|
|
983
|
+
where += " AND app_name = ?"
|
|
984
|
+
params = (before, app_name)
|
|
985
|
+
delete_sql = f"DELETE FROM {self._events_table} {where} RETURNING 1"
|
|
986
|
+
|
|
987
|
+
try:
|
|
988
|
+
with self._config.provide_connection() as conn:
|
|
989
|
+
cursor = conn.execute(delete_sql, params)
|
|
990
|
+
count = len(cursor.fetchall())
|
|
991
|
+
conn.commit()
|
|
992
|
+
return count
|
|
993
|
+
except Exception as e:
|
|
994
|
+
if DUCKDB_TABLE_NOT_FOUND_ERROR in str(e):
|
|
995
|
+
return 0
|
|
996
|
+
raise
|
|
997
|
+
|
|
998
|
+
def _delete_idle_sessions(self, updated_before: "datetime", app_name: "str | None" = None) -> int:
|
|
999
|
+
where = "WHERE update_time < ?"
|
|
1000
|
+
params: tuple[Any, ...] = (updated_before,)
|
|
1001
|
+
if app_name is not None:
|
|
1002
|
+
where += " AND app_name = ?"
|
|
1003
|
+
params = (updated_before, app_name)
|
|
1004
|
+
delete_events_sql = f"""
|
|
1005
|
+
DELETE FROM {self._events_table}
|
|
1006
|
+
WHERE session_id IN (SELECT id FROM {self._session_table} {where})
|
|
1007
|
+
"""
|
|
1008
|
+
delete_sessions_sql = f"DELETE FROM {self._session_table} {where} RETURNING 1"
|
|
1009
|
+
|
|
1010
|
+
try:
|
|
1011
|
+
with self._config.provide_connection() as conn:
|
|
1012
|
+
conn.execute(delete_events_sql, params)
|
|
1013
|
+
conn.commit()
|
|
1014
|
+
cursor = conn.execute(delete_sessions_sql, params)
|
|
1015
|
+
count = len(cursor.fetchall())
|
|
1016
|
+
conn.commit()
|
|
1017
|
+
return count
|
|
1018
|
+
except Exception as e:
|
|
1019
|
+
if DUCKDB_TABLE_NOT_FOUND_ERROR in str(e):
|
|
1020
|
+
return 0
|
|
1021
|
+
raise
|
|
1022
|
+
|
|
1023
|
+
def _delete_idle_user_states(self, updated_before: "datetime", app_name: "str | None" = None) -> int:
|
|
1024
|
+
where = "WHERE update_time < ?"
|
|
1025
|
+
params: tuple[Any, ...] = (updated_before,)
|
|
1026
|
+
if app_name is not None:
|
|
1027
|
+
where += " AND app_name = ?"
|
|
1028
|
+
params = (updated_before, app_name)
|
|
1029
|
+
delete_sql = f"DELETE FROM {self._user_state_table} {where} RETURNING 1"
|
|
1030
|
+
|
|
1031
|
+
try:
|
|
1032
|
+
with self._config.provide_connection() as conn:
|
|
1033
|
+
cursor = conn.execute(delete_sql, params)
|
|
1034
|
+
count = len(cursor.fetchall())
|
|
1035
|
+
conn.commit()
|
|
1036
|
+
return count
|
|
1037
|
+
except Exception as e:
|
|
1038
|
+
if DUCKDB_TABLE_NOT_FOUND_ERROR in str(e):
|
|
1039
|
+
return 0
|
|
1040
|
+
raise
|
|
1041
|
+
|
|
1042
|
+
def _get_app_state(self, app_name: str) -> "dict[str, Any] | None":
|
|
1043
|
+
sql = f"SELECT state FROM {self._app_state_table} WHERE app_name = ?"
|
|
1044
|
+
try:
|
|
1045
|
+
with self._config.provide_connection() as conn:
|
|
1046
|
+
row = conn.execute(sql, (app_name,)).fetchone()
|
|
1047
|
+
if row is None:
|
|
1048
|
+
return None
|
|
1049
|
+
return cast("dict[str, Any]", from_json(row[0]) if isinstance(row[0], str) else row[0])
|
|
1050
|
+
except Exception as e:
|
|
1051
|
+
if DUCKDB_TABLE_NOT_FOUND_ERROR in str(e):
|
|
1052
|
+
return None
|
|
1053
|
+
raise
|
|
1054
|
+
|
|
1055
|
+
def _get_user_state(self, app_name: str, user_id: str) -> "dict[str, Any] | None":
|
|
1056
|
+
sql = f"SELECT state FROM {self._user_state_table} WHERE app_name = ? AND user_id = ?"
|
|
1057
|
+
try:
|
|
1058
|
+
with self._config.provide_connection() as conn:
|
|
1059
|
+
row = conn.execute(sql, (app_name, user_id)).fetchone()
|
|
1060
|
+
if row is None:
|
|
1061
|
+
return None
|
|
1062
|
+
return cast("dict[str, Any]", from_json(row[0]) if isinstance(row[0], str) else row[0])
|
|
1063
|
+
except Exception as e:
|
|
1064
|
+
if DUCKDB_TABLE_NOT_FOUND_ERROR in str(e):
|
|
1065
|
+
return None
|
|
1066
|
+
raise
|
|
1067
|
+
|
|
1068
|
+
def _upsert_app_state(self, app_name: str, state: "dict[str, Any]") -> None:
|
|
1069
|
+
now = datetime.now(UTC)
|
|
1070
|
+
sql = f"""
|
|
1071
|
+
INSERT INTO {self._app_state_table} (app_name, state, update_time)
|
|
1072
|
+
VALUES (?, ?, ?)
|
|
1073
|
+
ON CONFLICT(app_name) DO UPDATE SET
|
|
1074
|
+
state = excluded.state,
|
|
1075
|
+
update_time = excluded.update_time
|
|
1076
|
+
"""
|
|
1077
|
+
with self._config.provide_connection() as conn:
|
|
1078
|
+
conn.execute(sql, (app_name, to_json(state), now))
|
|
1079
|
+
conn.commit()
|
|
1080
|
+
|
|
1081
|
+
def _upsert_user_state(self, app_name: str, user_id: str, state: "dict[str, Any]") -> None:
|
|
1082
|
+
now = datetime.now(UTC)
|
|
1083
|
+
sql = f"""
|
|
1084
|
+
INSERT INTO {self._user_state_table} (app_name, user_id, state, update_time)
|
|
1085
|
+
VALUES (?, ?, ?, ?)
|
|
1086
|
+
ON CONFLICT(app_name, user_id) DO UPDATE SET
|
|
1087
|
+
state = excluded.state,
|
|
1088
|
+
update_time = excluded.update_time
|
|
1089
|
+
"""
|
|
1090
|
+
with self._config.provide_connection() as conn:
|
|
1091
|
+
conn.execute(sql, (app_name, user_id, to_json(state), now))
|
|
1092
|
+
conn.commit()
|
|
1093
|
+
|
|
1094
|
+
def _get_metadata(self, key: str) -> "str | None":
|
|
1095
|
+
sql = f"SELECT value FROM {self._metadata_table} WHERE key = ?"
|
|
1096
|
+
try:
|
|
1097
|
+
with self._config.provide_connection() as conn:
|
|
1098
|
+
row = conn.execute(sql, (key,)).fetchone()
|
|
1099
|
+
return row[0] if row is not None else None
|
|
1100
|
+
except Exception as e:
|
|
1101
|
+
if DUCKDB_TABLE_NOT_FOUND_ERROR in str(e):
|
|
1102
|
+
return None
|
|
1103
|
+
raise
|
|
1104
|
+
|
|
1105
|
+
def _set_metadata(self, key: str, value: str) -> None:
|
|
1106
|
+
sql = f"""
|
|
1107
|
+
INSERT INTO {self._metadata_table} (key, value)
|
|
1108
|
+
VALUES (?, ?)
|
|
1109
|
+
ON CONFLICT(key) DO UPDATE SET value = excluded.value
|
|
1110
|
+
"""
|
|
1111
|
+
with self._config.provide_connection() as conn:
|
|
1112
|
+
conn.execute(sql, (key, value))
|
|
1113
|
+
conn.commit()
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
class DuckDBADKMemoryStore(BaseSyncADKMemoryStore["DuckDBConfig"]):
|
|
1117
|
+
"""DuckDB ADK memory store using synchronous DuckDB driver with async wrappers.
|
|
1118
|
+
|
|
1119
|
+
Implements memory entry storage for Google Agent Development Kit
|
|
1120
|
+
using DuckDB's synchronous driver with a synchronous public API.
|
|
1121
|
+
Provides:
|
|
1122
|
+
- Session memory storage with native JSON type
|
|
1123
|
+
- Simple ILIKE search or BM25 full-text search via FTS extension
|
|
1124
|
+
- Native TIMESTAMP type support
|
|
1125
|
+
- Deduplication via (app_name, user_id, event_id) unique constraint
|
|
1126
|
+
- Efficient upserts using ON CONFLICT DO NOTHING
|
|
1127
|
+
- Columnar storage for analytical queries
|
|
1128
|
+
|
|
1129
|
+
Args:
|
|
1130
|
+
config: DuckDBConfig with extension_config["adk"] settings.
|
|
1131
|
+
"""
|
|
1132
|
+
|
|
1133
|
+
__slots__ = ()
|
|
1134
|
+
|
|
1135
|
+
_max_table_name_parts = 2
|
|
1136
|
+
|
|
1137
|
+
def __init__(self, config: "DuckDBConfig", *, read_config: "DuckDBConfig | None" = None) -> None:
|
|
1138
|
+
"""Initialize DuckDB ADK memory store.
|
|
1139
|
+
|
|
1140
|
+
Args:
|
|
1141
|
+
read_config: Optional compatible reader for pure reads.
|
|
1142
|
+
config: DuckDBConfig instance.
|
|
1143
|
+
"""
|
|
1144
|
+
super().__init__(config, read_config=read_config)
|
|
1145
|
+
|
|
1146
|
+
def create_tables(self) -> None:
|
|
1147
|
+
"""Create the memory table and indexes if they don't exist."""
|
|
1148
|
+
if not self._enabled:
|
|
1149
|
+
return
|
|
1150
|
+
|
|
1151
|
+
if not self.create_schema_enabled:
|
|
1152
|
+
self.reconcile_schema()
|
|
1153
|
+
return
|
|
1154
|
+
|
|
1155
|
+
self._create_tables()
|
|
1156
|
+
|
|
1157
|
+
def insert_memory_entries(self, entries: "list[StoredMemory]", owner_id: "object | None" = None) -> int:
|
|
1158
|
+
"""Bulk insert memory entries with deduplication.
|
|
1159
|
+
|
|
1160
|
+
After successful inserts, refreshes the FTS index if FTS is enabled.
|
|
1161
|
+
"""
|
|
1162
|
+
return self._insert_memory_entries(entries, owner_id)
|
|
1163
|
+
|
|
1164
|
+
def search_entries(
|
|
1165
|
+
self,
|
|
1166
|
+
query: str,
|
|
1167
|
+
app_name: str,
|
|
1168
|
+
user_id: str,
|
|
1169
|
+
limit: "int | None" = None,
|
|
1170
|
+
scope_filter: Literal["all", "user", "app"] = "all",
|
|
1171
|
+
embedding: "Sequence[float] | None" = None,
|
|
1172
|
+
) -> "list[StoredMemory]":
|
|
1173
|
+
"""Search memory entries by text query.
|
|
1174
|
+
|
|
1175
|
+
When FTS is enabled, uses ``match_bm25()`` for BM25-ranked results.
|
|
1176
|
+
Falls back to ILIKE for simple substring matching.
|
|
1177
|
+
"""
|
|
1178
|
+
if embedding is not None:
|
|
1179
|
+
msg = "DuckDB ADK memory store does not support embedding-based search."
|
|
1180
|
+
raise NotImplementedError(msg)
|
|
1181
|
+
return self._search_entries(query, app_name, user_id, limit, scope_filter, read=True)
|
|
1182
|
+
|
|
1183
|
+
def delete_entries_by_session(self, session_id: str, app_name: str, user_id: str) -> int:
|
|
1184
|
+
"""Delete memory entries for a specific session, owned by an app and user."""
|
|
1185
|
+
return self._delete_entries_by_session(session_id, app_name=app_name, user_id=user_id)
|
|
1186
|
+
|
|
1187
|
+
def delete_entries_older_than(self, days: int, app_name: "str | None" = None, scope: "str | None" = None) -> int:
|
|
1188
|
+
"""Delete memory entries older than specified days."""
|
|
1189
|
+
return self._delete_entries_older_than(days, app_name, scope)
|
|
1190
|
+
|
|
1191
|
+
def reconcile_companion_objects_sync(self, driver: Any) -> None:
|
|
1192
|
+
"""Create missing DuckDB memory companion indexes and FTS schema without committing."""
|
|
1193
|
+
if not self._enabled:
|
|
1194
|
+
return
|
|
1195
|
+
fts_present = self._fts_index_exists(driver) if self._use_fts else True
|
|
1196
|
+
for statement in self._memory_index_statements():
|
|
1197
|
+
driver.execute(statement)
|
|
1198
|
+
if self._use_fts and not fts_present:
|
|
1199
|
+
self._load_fts_extension(driver)
|
|
1200
|
+
driver.execute(self._fts_index_ddl(overwrite=False))
|
|
1201
|
+
|
|
1202
|
+
def _ensure_fts_extension(self, conn: Any) -> bool:
|
|
1203
|
+
"""Ensure the DuckDB FTS extension is available for this connection."""
|
|
1204
|
+
with contextlib.suppress(Exception):
|
|
1205
|
+
conn.execute("LOAD fts")
|
|
1206
|
+
return True
|
|
1207
|
+
|
|
1208
|
+
with contextlib.suppress(Exception):
|
|
1209
|
+
conn.execute("INSTALL fts")
|
|
1210
|
+
|
|
1211
|
+
try:
|
|
1212
|
+
conn.execute("LOAD fts")
|
|
1213
|
+
except Exception as exc:
|
|
1214
|
+
logger.debug("DuckDB FTS extension unavailable: %s", exc)
|
|
1215
|
+
return False
|
|
1216
|
+
|
|
1217
|
+
return True
|
|
1218
|
+
|
|
1219
|
+
def _create_fts_index(self, conn: Any) -> None:
|
|
1220
|
+
"""Create FTS index for the memory table."""
|
|
1221
|
+
if not self._ensure_fts_extension(conn):
|
|
1222
|
+
return
|
|
1223
|
+
|
|
1224
|
+
try:
|
|
1225
|
+
conn.execute(self._fts_index_ddl(overwrite=False))
|
|
1226
|
+
conn.commit()
|
|
1227
|
+
except Exception as exc:
|
|
1228
|
+
logger.debug("Failed to create DuckDB FTS index: %s", exc)
|
|
1229
|
+
|
|
1230
|
+
def _refresh_fts_index(self, conn: Any) -> None:
|
|
1231
|
+
"""Rebuild the FTS index to reflect recent inserts.
|
|
1232
|
+
|
|
1233
|
+
DuckDB FTS indexes do not auto-update. This must be called after
|
|
1234
|
+
insert/update/delete operations, NOT on every search.
|
|
1235
|
+
"""
|
|
1236
|
+
if not self._ensure_fts_extension(conn):
|
|
1237
|
+
return
|
|
1238
|
+
|
|
1239
|
+
try:
|
|
1240
|
+
conn.execute(self._fts_index_ddl(overwrite=True))
|
|
1241
|
+
conn.commit()
|
|
1242
|
+
except Exception as exc:
|
|
1243
|
+
logger.debug("Failed to refresh DuckDB FTS index: %s", exc)
|
|
1244
|
+
|
|
1245
|
+
def _fts_index_ddl(self, *, overwrite: bool) -> str:
|
|
1246
|
+
"""Return DuckDB FTS index PRAGMA SQL for the memory table."""
|
|
1247
|
+
return f"PRAGMA create_fts_index('{self._memory_table}', 'id', 'content_text', {self._render_fts_options(overwrite=overwrite)})"
|
|
1248
|
+
|
|
1249
|
+
def _render_fts_options(self, *, overwrite: bool) -> str:
|
|
1250
|
+
"""Render DuckDB FTS options from adapter-local ADK config."""
|
|
1251
|
+
options: dict[str, object] = dict(DUCKDB_FTS_DEFAULT_OPTIONS)
|
|
1252
|
+
adk_config = _adk_config(self._config)
|
|
1253
|
+
configured_options = adk_config.get("memory_fts_options", {})
|
|
1254
|
+
if configured_options:
|
|
1255
|
+
_validate_duckdb_fts_options(configured_options)
|
|
1256
|
+
options.update(configured_options)
|
|
1257
|
+
if overwrite:
|
|
1258
|
+
options["overwrite"] = 1
|
|
1259
|
+
|
|
1260
|
+
option_order = DUCKDB_FTS_REFRESH_OPTION_ORDER if overwrite else DUCKDB_FTS_CREATE_OPTION_ORDER
|
|
1261
|
+
return ", ".join(
|
|
1262
|
+
f"{option_name}={_format_duckdb_fts_option(options[option_name])}"
|
|
1263
|
+
for option_name in option_order
|
|
1264
|
+
if option_name in options
|
|
1265
|
+
)
|
|
1266
|
+
|
|
1267
|
+
def _fts_schema_name(self) -> str:
|
|
1268
|
+
"""Return the DuckDB FTS schema name for the configured memory table."""
|
|
1269
|
+
schema, bare_table = _split_duckdb_table_name(self._memory_table)
|
|
1270
|
+
return f"fts_{schema}_{bare_table}"
|
|
1271
|
+
|
|
1272
|
+
def _fts_index_exists(self, driver: Any) -> bool:
|
|
1273
|
+
"""Return whether the DuckDB FTS schema already exists in the catalog."""
|
|
1274
|
+
rows = driver.select(
|
|
1275
|
+
"SELECT 1 AS present FROM information_schema.schemata WHERE lower(schema_name) = lower(?)",
|
|
1276
|
+
(self._fts_schema_name(),),
|
|
1277
|
+
)
|
|
1278
|
+
return bool(rows)
|
|
1279
|
+
|
|
1280
|
+
def _load_fts_extension(self, driver: Any) -> None:
|
|
1281
|
+
"""Load the DuckDB FTS extension via transaction-safe catalog probing."""
|
|
1282
|
+
rows = driver.select("SELECT loaded, installed FROM duckdb_extensions() WHERE extension_name = 'fts'")
|
|
1283
|
+
if rows and bool(rows[0].get("loaded")):
|
|
1284
|
+
return
|
|
1285
|
+
if not rows or not bool(rows[0].get("installed")):
|
|
1286
|
+
driver.execute("INSTALL fts")
|
|
1287
|
+
driver.execute("LOAD fts")
|
|
1288
|
+
|
|
1289
|
+
def _memory_index_statements(self) -> list[str]:
|
|
1290
|
+
"""Return canonical CREATE INDEX statements for the memory table."""
|
|
1291
|
+
idx_app_scope_user_time = _duckdb_index_name(self._memory_table, "app_scope_user_time")
|
|
1292
|
+
idx_scope = _duckdb_index_name(self._memory_table, "scope")
|
|
1293
|
+
idx_session = _duckdb_index_name(self._memory_table, "session")
|
|
1294
|
+
return [
|
|
1295
|
+
f"CREATE INDEX IF NOT EXISTS {idx_app_scope_user_time} ON {self._memory_table}(app_name, scope, user_id, timestamp DESC)",
|
|
1296
|
+
f"CREATE INDEX IF NOT EXISTS {idx_scope} ON {self._memory_table}(app_name, scope)",
|
|
1297
|
+
f"CREATE INDEX IF NOT EXISTS {idx_session} ON {self._memory_table}(session_id)",
|
|
1298
|
+
]
|
|
1299
|
+
|
|
1300
|
+
def _memory_table_ddl(self) -> str:
|
|
1301
|
+
"""Get DuckDB CREATE TABLE SQL for memory entries.
|
|
1302
|
+
|
|
1303
|
+
Returns:
|
|
1304
|
+
SQL statement to create memory table with indexes.
|
|
1305
|
+
"""
|
|
1306
|
+
owner_id_line = ""
|
|
1307
|
+
if self._owner_id_column_ddl:
|
|
1308
|
+
owner_id_line = f",\n {self._owner_id_column_ddl}"
|
|
1309
|
+
|
|
1310
|
+
index_lines = "\n".join(f" {stmt};" for stmt in self._memory_index_statements())
|
|
1311
|
+
return (
|
|
1312
|
+
f"\n CREATE TABLE IF NOT EXISTS {self._memory_table} (\n"
|
|
1313
|
+
f" id VARCHAR(128) PRIMARY KEY,\n"
|
|
1314
|
+
f" session_id VARCHAR(128) NOT NULL,\n"
|
|
1315
|
+
f" app_name VARCHAR(128) NOT NULL,\n"
|
|
1316
|
+
f" user_id VARCHAR(128) NOT NULL,\n"
|
|
1317
|
+
f" scope VARCHAR(16) NOT NULL DEFAULT 'user',\n"
|
|
1318
|
+
f" event_id VARCHAR(128) NOT NULL,\n"
|
|
1319
|
+
f" author VARCHAR(256){owner_id_line},\n"
|
|
1320
|
+
f" timestamp TIMESTAMP NOT NULL,\n"
|
|
1321
|
+
f" content_json JSON NOT NULL,\n"
|
|
1322
|
+
f" content_text TEXT NOT NULL,\n"
|
|
1323
|
+
f" metadata_json JSON,\n"
|
|
1324
|
+
f" inserted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n"
|
|
1325
|
+
f" UNIQUE (app_name, user_id, event_id)\n"
|
|
1326
|
+
f" );\n"
|
|
1327
|
+
f"{index_lines}\n"
|
|
1328
|
+
f" "
|
|
1329
|
+
)
|
|
1330
|
+
|
|
1331
|
+
def _drop_memory_table_sql(self) -> "list[str]":
|
|
1332
|
+
"""Get DuckDB DROP TABLE SQL statements."""
|
|
1333
|
+
return [f"DROP TABLE IF EXISTS {self._memory_table}"]
|
|
1334
|
+
|
|
1335
|
+
def _create_tables(self) -> None:
|
|
1336
|
+
"""Synchronous implementation of create_tables."""
|
|
1337
|
+
if not self._enabled:
|
|
1338
|
+
return
|
|
1339
|
+
|
|
1340
|
+
ddl = self._memory_table_ddl()
|
|
1341
|
+
with self._config.provide_connection() as conn:
|
|
1342
|
+
conn.execute(ddl)
|
|
1343
|
+
if self._use_fts:
|
|
1344
|
+
self._create_fts_index(conn)
|
|
1345
|
+
|
|
1346
|
+
def _insert_memory_entries(self, entries: "list[StoredMemory]", owner_id: "object | None" = None) -> int:
|
|
1347
|
+
"""Synchronous implementation of insert_memory_entries."""
|
|
1348
|
+
if not self._enabled:
|
|
1349
|
+
msg = "Memory store is disabled"
|
|
1350
|
+
raise RuntimeError(msg)
|
|
1351
|
+
|
|
1352
|
+
if not entries:
|
|
1353
|
+
return 0
|
|
1354
|
+
|
|
1355
|
+
inserted_count = 0
|
|
1356
|
+
if self._owner_id_column_name:
|
|
1357
|
+
sql = f"""
|
|
1358
|
+
INSERT INTO {self._memory_table} (
|
|
1359
|
+
id, session_id, app_name, user_id, scope, event_id, author,
|
|
1360
|
+
{self._owner_id_column_name}, timestamp, content_json,
|
|
1361
|
+
content_text, metadata_json, inserted_at
|
|
1362
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1363
|
+
ON CONFLICT DO NOTHING RETURNING 1
|
|
1364
|
+
"""
|
|
1365
|
+
else:
|
|
1366
|
+
sql = f"""
|
|
1367
|
+
INSERT INTO {self._memory_table} (
|
|
1368
|
+
id, session_id, app_name, user_id, scope, event_id, author,
|
|
1369
|
+
timestamp, content_json, content_text, metadata_json, inserted_at
|
|
1370
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1371
|
+
ON CONFLICT DO NOTHING RETURNING 1
|
|
1372
|
+
"""
|
|
1373
|
+
|
|
1374
|
+
with self._config.provide_connection() as conn:
|
|
1375
|
+
conn.begin()
|
|
1376
|
+
try:
|
|
1377
|
+
for entry in entries:
|
|
1378
|
+
params: tuple[Any, ...]
|
|
1379
|
+
scope_value = entry.get("scope", "user")
|
|
1380
|
+
metadata_json = entry.get("metadata_json")
|
|
1381
|
+
if self._owner_id_column_name:
|
|
1382
|
+
params = (
|
|
1383
|
+
entry["id"],
|
|
1384
|
+
entry["session_id"],
|
|
1385
|
+
entry["app_name"],
|
|
1386
|
+
entry["user_id"],
|
|
1387
|
+
scope_value,
|
|
1388
|
+
entry["event_id"],
|
|
1389
|
+
entry.get("author"),
|
|
1390
|
+
owner_id,
|
|
1391
|
+
entry["timestamp"],
|
|
1392
|
+
to_json(entry["content_json"]),
|
|
1393
|
+
entry["content_text"],
|
|
1394
|
+
to_json(metadata_json) if metadata_json is not None else None,
|
|
1395
|
+
entry["inserted_at"],
|
|
1396
|
+
)
|
|
1397
|
+
else:
|
|
1398
|
+
params = (
|
|
1399
|
+
entry["id"],
|
|
1400
|
+
entry["session_id"],
|
|
1401
|
+
entry["app_name"],
|
|
1402
|
+
entry["user_id"],
|
|
1403
|
+
scope_value,
|
|
1404
|
+
entry["event_id"],
|
|
1405
|
+
entry.get("author"),
|
|
1406
|
+
entry["timestamp"],
|
|
1407
|
+
to_json(entry["content_json"]),
|
|
1408
|
+
entry["content_text"],
|
|
1409
|
+
to_json(metadata_json) if metadata_json is not None else None,
|
|
1410
|
+
entry["inserted_at"],
|
|
1411
|
+
)
|
|
1412
|
+
result = conn.execute(sql, params)
|
|
1413
|
+
inserted_count += len(result.fetchall())
|
|
1414
|
+
conn.commit()
|
|
1415
|
+
except Exception:
|
|
1416
|
+
with contextlib.suppress(Exception):
|
|
1417
|
+
conn.rollback()
|
|
1418
|
+
raise
|
|
1419
|
+
|
|
1420
|
+
if self._use_fts and inserted_count > 0:
|
|
1421
|
+
self._refresh_fts_index(conn)
|
|
1422
|
+
|
|
1423
|
+
return inserted_count
|
|
1424
|
+
|
|
1425
|
+
def _search_entries(
|
|
1426
|
+
self,
|
|
1427
|
+
query: str,
|
|
1428
|
+
app_name: str,
|
|
1429
|
+
user_id: str,
|
|
1430
|
+
limit: "int | None" = None,
|
|
1431
|
+
scope_filter: Literal["all", "user", "app"] = "all",
|
|
1432
|
+
*,
|
|
1433
|
+
read: bool = False,
|
|
1434
|
+
) -> "list[StoredMemory]":
|
|
1435
|
+
"""Synchronous implementation of search_entries."""
|
|
1436
|
+
if not self._enabled:
|
|
1437
|
+
msg = "Memory store is disabled"
|
|
1438
|
+
raise RuntimeError(msg)
|
|
1439
|
+
|
|
1440
|
+
if not query or not query.strip():
|
|
1441
|
+
return []
|
|
1442
|
+
|
|
1443
|
+
limit_value = limit if limit is not None else self._max_results
|
|
1444
|
+
use_fts = self._use_fts
|
|
1445
|
+
rows: list[Any] | None = None
|
|
1446
|
+
columns: list[str] = []
|
|
1447
|
+
|
|
1448
|
+
with self._provide_replica_connection(primary=not read) as conn:
|
|
1449
|
+
if use_fts and not self._ensure_fts_extension(conn):
|
|
1450
|
+
use_fts = False
|
|
1451
|
+
|
|
1452
|
+
if use_fts:
|
|
1453
|
+
fts_macro = self._fts_schema_name()
|
|
1454
|
+
where_scope, scope_params = _build_duckdb_scope_where(app_name, user_id, scope_filter, prefix="m")
|
|
1455
|
+
fts_sql = f"""
|
|
1456
|
+
SELECT m.*
|
|
1457
|
+
FROM {self._memory_table} m
|
|
1458
|
+
JOIN (
|
|
1459
|
+
SELECT id, {fts_macro}.match_bm25(id, ?, fields := 'content_text') AS score
|
|
1460
|
+
FROM {self._memory_table}
|
|
1461
|
+
WHERE app_name = ?
|
|
1462
|
+
) fts ON m.id = fts.id
|
|
1463
|
+
WHERE {where_scope} AND fts.score IS NOT NULL
|
|
1464
|
+
ORDER BY fts.score DESC
|
|
1465
|
+
LIMIT ?
|
|
1466
|
+
"""
|
|
1467
|
+
fts_params = (query, app_name, *scope_params, limit_value)
|
|
1468
|
+
try:
|
|
1469
|
+
rows = cast("list[Any]", conn.execute(fts_sql, fts_params).fetchall())
|
|
1470
|
+
columns = [col[0] for col in conn.description or []]
|
|
1471
|
+
except Exception as exc:
|
|
1472
|
+
logger.warning("FTS search failed; falling back to simple search: %s", exc)
|
|
1473
|
+
|
|
1474
|
+
if rows is None:
|
|
1475
|
+
where_scope, scope_params = _build_duckdb_scope_where(app_name, user_id, scope_filter)
|
|
1476
|
+
sql = f"""
|
|
1477
|
+
SELECT * FROM {self._memory_table}
|
|
1478
|
+
WHERE {where_scope} AND content_text ILIKE ?
|
|
1479
|
+
ORDER BY timestamp DESC
|
|
1480
|
+
LIMIT ?
|
|
1481
|
+
"""
|
|
1482
|
+
params = (*scope_params, f"%{query}%", limit_value)
|
|
1483
|
+
try:
|
|
1484
|
+
rows = cast("list[Any]", conn.execute(sql, params).fetchall())
|
|
1485
|
+
columns = [col[0] for col in conn.description or []]
|
|
1486
|
+
except Exception as exc:
|
|
1487
|
+
if DUCKDB_TABLE_NOT_FOUND_ERROR in str(exc):
|
|
1488
|
+
return []
|
|
1489
|
+
raise
|
|
1490
|
+
|
|
1491
|
+
records: list[StoredMemory] = []
|
|
1492
|
+
for row in rows:
|
|
1493
|
+
record = cast("StoredMemory", dict(zip(columns, row, strict=False)))
|
|
1494
|
+
content_value = record["content_json"]
|
|
1495
|
+
if isinstance(content_value, (str, bytes)):
|
|
1496
|
+
record["content_json"] = from_json(content_value)
|
|
1497
|
+
metadata_value = record.get("metadata_json")
|
|
1498
|
+
if isinstance(metadata_value, (str, bytes)):
|
|
1499
|
+
record["metadata_json"] = from_json(metadata_value)
|
|
1500
|
+
record["embedding"] = None
|
|
1501
|
+
records.append(record)
|
|
1502
|
+
return records
|
|
1503
|
+
|
|
1504
|
+
def _delete_entries_by_session(self, session_id: str, app_name: str, user_id: str) -> int:
|
|
1505
|
+
"""Synchronous implementation of delete_entries_by_session."""
|
|
1506
|
+
if not self._enabled:
|
|
1507
|
+
msg = "Memory store is disabled"
|
|
1508
|
+
raise RuntimeError(msg)
|
|
1509
|
+
|
|
1510
|
+
clauses = ["session_id = ?"]
|
|
1511
|
+
params: list[Any] = [session_id]
|
|
1512
|
+
clauses.append("app_name = ?")
|
|
1513
|
+
params.append(app_name)
|
|
1514
|
+
clauses.append("user_id = ?")
|
|
1515
|
+
params.append(user_id)
|
|
1516
|
+
where_sql = " AND ".join(clauses)
|
|
1517
|
+
sql = f"DELETE FROM {self._memory_table} WHERE {where_sql} RETURNING 1"
|
|
1518
|
+
with self._config.provide_connection() as conn:
|
|
1519
|
+
result = conn.execute(sql, tuple(params))
|
|
1520
|
+
deleted_count = len(result.fetchall())
|
|
1521
|
+
conn.commit()
|
|
1522
|
+
if self._use_fts and deleted_count > 0:
|
|
1523
|
+
self._refresh_fts_index(conn)
|
|
1524
|
+
return deleted_count
|
|
1525
|
+
|
|
1526
|
+
def _delete_entries_older_than(self, days: int, app_name: "str | None" = None, scope: "str | None" = None) -> int:
|
|
1527
|
+
"""Synchronous implementation of delete_entries_older_than."""
|
|
1528
|
+
if not self._enabled:
|
|
1529
|
+
msg = "Memory store is disabled"
|
|
1530
|
+
raise RuntimeError(msg)
|
|
1531
|
+
|
|
1532
|
+
clauses = ["inserted_at < (CURRENT_TIMESTAMP - (? * INTERVAL '1 day'))"]
|
|
1533
|
+
params: list[Any] = [days]
|
|
1534
|
+
if app_name is not None:
|
|
1535
|
+
clauses.append("app_name = ?")
|
|
1536
|
+
params.append(app_name)
|
|
1537
|
+
if scope is not None:
|
|
1538
|
+
clauses.append("scope = ?")
|
|
1539
|
+
params.append(scope)
|
|
1540
|
+
|
|
1541
|
+
where_sql = " AND ".join(clauses)
|
|
1542
|
+
sql = f"DELETE FROM {self._memory_table} WHERE {where_sql} RETURNING 1"
|
|
1543
|
+
with self._config.provide_connection() as conn:
|
|
1544
|
+
result = conn.execute(sql, tuple(params))
|
|
1545
|
+
deleted_count = len(result.fetchall())
|
|
1546
|
+
conn.commit()
|
|
1547
|
+
if self._use_fts and deleted_count > 0:
|
|
1548
|
+
self._refresh_fts_index(conn)
|
|
1549
|
+
return deleted_count
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
def _raise_session_not_found(session_id: str) -> None:
|
|
1553
|
+
msg = f"Session {session_id} not found during append_event_and_update_state."
|
|
1554
|
+
raise ValueError(msg)
|
|
1555
|
+
|
|
1556
|
+
|
|
1557
|
+
def _adk_config(config: Any) -> DuckDBADKConfig:
|
|
1558
|
+
"""Return DuckDB ADK extension settings from ``extension_config["adk"]``."""
|
|
1559
|
+
extension_config = getattr(config, "extension_config", {})
|
|
1560
|
+
if not isinstance(extension_config, dict):
|
|
1561
|
+
return cast("DuckDBADKConfig", {})
|
|
1562
|
+
adk_config = extension_config.get("adk", {})
|
|
1563
|
+
if not isinstance(adk_config, dict):
|
|
1564
|
+
return cast("DuckDBADKConfig", {})
|
|
1565
|
+
return cast("DuckDBADKConfig", adk_config)
|
|
1566
|
+
|
|
1567
|
+
|
|
1568
|
+
def _validate_duckdb_fts_options(options: Mapping[str, object]) -> None:
|
|
1569
|
+
"""Validate DuckDB FTS option names before rendering a PRAGMA."""
|
|
1570
|
+
unknown_options = sorted(set(options) - set(DUCKDB_FTS_ALLOWED_OPTIONS))
|
|
1571
|
+
if unknown_options:
|
|
1572
|
+
msg = f"Unsupported DuckDB ADK memory_fts_options: {', '.join(unknown_options)}"
|
|
1573
|
+
raise ValueError(msg)
|
|
1574
|
+
|
|
1575
|
+
|
|
1576
|
+
def _format_duckdb_fts_option(value: object) -> str:
|
|
1577
|
+
"""Render a DuckDB FTS option value."""
|
|
1578
|
+
if isinstance(value, bool):
|
|
1579
|
+
return "1" if value else "0"
|
|
1580
|
+
if isinstance(value, int):
|
|
1581
|
+
return str(value)
|
|
1582
|
+
if isinstance(value, str):
|
|
1583
|
+
escaped_value = value.replace("'", "''")
|
|
1584
|
+
return f"'{escaped_value}'"
|
|
1585
|
+
msg = f"DuckDB ADK memory_fts_options values must be str, int, or bool; got {type(value).__name__}"
|
|
1586
|
+
raise TypeError(msg)
|
|
1587
|
+
|
|
1588
|
+
|
|
1589
|
+
def _build_duckdb_scope_where(
|
|
1590
|
+
app_name: str, user_id: str, scope_filter: Literal["all", "user", "app"], *, prefix: str = ""
|
|
1591
|
+
) -> tuple[str, tuple[Any, ...]]:
|
|
1592
|
+
pfx = f"{prefix}." if prefix else ""
|
|
1593
|
+
if scope_filter == "all":
|
|
1594
|
+
return f"{pfx}app_name = ? AND (({pfx}scope = 'user' AND {pfx}user_id = ?) OR {pfx}scope = 'app')", (
|
|
1595
|
+
app_name,
|
|
1596
|
+
user_id,
|
|
1597
|
+
)
|
|
1598
|
+
if scope_filter == "user":
|
|
1599
|
+
return f"{pfx}app_name = ? AND {pfx}scope = 'user' AND {pfx}user_id = ?", (app_name, user_id)
|
|
1600
|
+
return f"{pfx}app_name = ? AND {pfx}scope = 'app'", (app_name,)
|
|
1601
|
+
|
|
1602
|
+
|
|
1603
|
+
def _duckdb_index_name(table_name: str, suffix: str) -> str:
|
|
1604
|
+
"""Generate a valid DuckDB index name for an optionally schema-qualified table."""
|
|
1605
|
+
parts = split_qualified_identifier(table_name.strip(), quote_chars='"')
|
|
1606
|
+
bare_name = parts[-1]
|
|
1607
|
+
if len(parts) > 1 and parts[0].lower() != "main":
|
|
1608
|
+
return f"idx_{parts[0]}_{bare_name}_{suffix}"
|
|
1609
|
+
return f"idx_{bare_name}_{suffix}"
|
|
1610
|
+
|
|
1611
|
+
|
|
1612
|
+
def _split_duckdb_table_name(table_name: str) -> tuple[str, str]:
|
|
1613
|
+
"""Split an optionally schema-qualified table name into schema and bare table name.
|
|
1614
|
+
|
|
1615
|
+
Returns:
|
|
1616
|
+
Tuple of (schema, bare_table_name). If unqualified, schema defaults to 'main'.
|
|
1617
|
+
"""
|
|
1618
|
+
parts = split_qualified_identifier(table_name.strip(), quote_chars='"')
|
|
1619
|
+
if not parts:
|
|
1620
|
+
msg = "DuckDB table name must not be empty."
|
|
1621
|
+
raise ValueError(msg)
|
|
1622
|
+
first_part = parts[0]
|
|
1623
|
+
if len(parts) > 1:
|
|
1624
|
+
return first_part, parts[1]
|
|
1625
|
+
return "main", first_part
|
|
1626
|
+
|
|
1627
|
+
|
|
1628
|
+
def _session_list_query(
|
|
1629
|
+
session_table: str,
|
|
1630
|
+
app_name: str,
|
|
1631
|
+
user_id: "str | None",
|
|
1632
|
+
column: str,
|
|
1633
|
+
direction: str,
|
|
1634
|
+
limit: "int | None",
|
|
1635
|
+
offset: int,
|
|
1636
|
+
) -> "tuple[str, tuple[Any, ...]]":
|
|
1637
|
+
"""Return the bounded session-list query and its bound values."""
|
|
1638
|
+
params: list[Any] = [app_name]
|
|
1639
|
+
where_clause = "app_name = ?"
|
|
1640
|
+
if user_id is not None:
|
|
1641
|
+
params.append(user_id)
|
|
1642
|
+
where_clause = f"{where_clause} AND user_id = ?"
|
|
1643
|
+
|
|
1644
|
+
page_clause = ""
|
|
1645
|
+
if limit is not None:
|
|
1646
|
+
params.extend((limit, offset))
|
|
1647
|
+
page_clause = "\n LIMIT ? OFFSET ?"
|
|
1648
|
+
|
|
1649
|
+
sql = f"""
|
|
1650
|
+
SELECT id, app_name, user_id, state, create_time, update_time
|
|
1651
|
+
FROM {session_table}
|
|
1652
|
+
WHERE {where_clause}
|
|
1653
|
+
ORDER BY {column} {direction}, id {direction}{page_clause}
|
|
1654
|
+
"""
|
|
1655
|
+
return sql, tuple(params)
|
|
1656
|
+
|
|
1657
|
+
|
|
1658
|
+
def _next_monotonic_timestamp(previous: "datetime | None") -> datetime:
|
|
1659
|
+
now = datetime.now(UTC)
|
|
1660
|
+
if previous is None:
|
|
1661
|
+
return now
|
|
1662
|
+
comparable = previous if previous.tzinfo is not None else previous.replace(tzinfo=UTC)
|
|
1663
|
+
if now <= comparable:
|
|
1664
|
+
return comparable + timedelta(microseconds=1)
|
|
1665
|
+
return now
|
|
1666
|
+
|
|
1667
|
+
|
|
1668
|
+
def _is_retryable_error(exc: Exception, *, allow_unique_conflict: bool) -> bool:
|
|
1669
|
+
message = str(exc).lower()
|
|
1670
|
+
if "conflict" in message or "transactioncontext" in message:
|
|
1671
|
+
return True
|
|
1672
|
+
return allow_unique_conflict and ("duplicate key" in message or "constraint" in message)
|