Spaces:
Runtime error
Runtime error
File size: 726 Bytes
1914b78 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 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
|