dp-zp-agent/tools/rag/sqlite_schema.py

21 lines
651 B
Python

"""Shared SQLite schema inspection for text-evidence expansion."""
import sqlite3
def sqlite_table_exists(conn: sqlite3.Connection, table_name: str) -> bool:
return (
conn.execute(
"SELECT 1 FROM sqlite_master " "WHERE type IN ('table', 'view') AND name = ? LIMIT 1",
(table_name,),
).fetchone()
is not None
)
def sqlite_table_columns(conn: sqlite3.Connection, table_name: str) -> set[str]:
if not sqlite_table_exists(conn, table_name):
return set()
rows = conn.execute(f"PRAGMA table_info({table_name})").fetchall()
return {str(row[1]) for row in rows if len(row) > 1}