fix: duckdb_load stats requires init_schema before querying tables

This commit is contained in:
ramseshk
2026-08-11 12:41:16 +08:00
parent 20ee340cef
commit 189691e8f2
+20 -8
View File
@@ -434,16 +434,28 @@ class DuckDBLoader:
def stats(self) -> dict: def stats(self) -> dict:
"""Get current database statistics.""" """Get current database statistics."""
return { self.init_schema()
"l2_snapshots": self.conn.execute("SELECT COUNT(*) FROM l2_snapshots").fetchone()[0], l2_count = self.conn.execute(
"trades": self.conn.execute("SELECT COUNT(*) FROM trades").fetchone()[0], "SELECT COUNT(*) FROM l2_snapshots"
"funding": self.conn.execute("SELECT COUNT(*) FROM funding").fetchone()[0], ).fetchone()[0]
"coins": [r[0] for r in self.conn.execute( trade_count = self.conn.execute(
"SELECT COUNT(*) FROM trades"
).fetchone()[0]
funding_count = self.conn.execute(
"SELECT COUNT(*) FROM funding"
).fetchone()[0]
coins_result = self.conn.execute(
"SELECT DISTINCT coin FROM l2_snapshots" "SELECT DISTINCT coin FROM l2_snapshots"
).fetchall()], ).fetchall()
"date_range": self.conn.execute( date_result = self.conn.execute(
"SELECT MIN(exchange_ts_ms), MAX(exchange_ts_ms) FROM l2_snapshots" "SELECT MIN(exchange_ts_ms), MAX(exchange_ts_ms) FROM l2_snapshots"
).fetchone(), ).fetchone()
return {
"l2_snapshots": l2_count,
"trades": trade_count,
"funding": funding_count,
"coins": [r[0] for r in coins_result],
"date_range": date_result,
} }
def close(self): def close(self):