finai / apps /api /_inspect_db.py
Sandy-sys's picture
Deploy FinAI
db7ef8e verified
Raw History Blame Contribute Delete
494 Bytes
import duckdb
c = duckdb.connect(r"C:\Users\sayan\Downloads\FinAi\data\mbf.duckdb", read_only=True)
rows = c.execute(
"SELECT table_name, table_type FROM information_schema.tables "
"WHERE table_schema='main' ORDER BY 1"
).fetchall()
print(f"TABLES ({len(rows)}):")
for r in rows:
try:
n = c.execute(f'SELECT COUNT(*) FROM "{r[0]}"').fetchone()[0]
except Exception as e: # noqa: BLE001
n = f"ERR {e}"
print(f" {r[0]:<35} {r[1]:<10} rows={n}")