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
+21 -9
View File
@@ -434,16 +434,28 @@ class DuckDBLoader:
def stats(self) -> dict:
"""Get current database statistics."""
self.init_schema()
l2_count = self.conn.execute(
"SELECT COUNT(*) FROM l2_snapshots"
).fetchone()[0]
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"
).fetchall()
date_result = self.conn.execute(
"SELECT MIN(exchange_ts_ms), MAX(exchange_ts_ms) FROM l2_snapshots"
).fetchone()
return {
"l2_snapshots": self.conn.execute("SELECT COUNT(*) FROM l2_snapshots").fetchone()[0],
"trades": self.conn.execute("SELECT COUNT(*) FROM trades").fetchone()[0],
"funding": self.conn.execute("SELECT COUNT(*) FROM funding").fetchone()[0],
"coins": [r[0] for r in self.conn.execute(
"SELECT DISTINCT coin FROM l2_snapshots"
).fetchall()],
"date_range": self.conn.execute(
"SELECT MIN(exchange_ts_ms), MAX(exchange_ts_ms) FROM l2_snapshots"
).fetchone(),
"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):