AI-powered-SQL / src /pipeline /schema_extract.py
github-actions
Auto deploy from GitHub Actions
1914b78
raw
history blame contribute delete
726 Bytes
import sqlite3
from src.utils.db_helpers import convert_to_sqlite
def extract_schema(db_path):
db_path = convert_to_sqlite(db_path , "test.db" )
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute("""
SELECT name FROM sqlite_master
WHERE type='table' AND name NOT LIKE 'sqlite_%';
""")
tables = cursor.fetchall()
schema_chunks = []
for (table_name,) in tables:
cursor.execute(f"PRAGMA table_info({table_name});")
columns = cursor.fetchall()
col_names = [col[1] for col in columns]
chunk = f"Table: {table_name} ({', '.join(col_names)})"
schema_chunks.append(chunk)
conn.close()
return schema_chunks