fix: duckdb_load stats requires init_schema before querying tables
This commit is contained in:
+21
-9
@@ -434,16 +434,28 @@ class DuckDBLoader:
|
|||||||
|
|
||||||
def stats(self) -> dict:
|
def stats(self) -> dict:
|
||||||
"""Get current database statistics."""
|
"""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 {
|
return {
|
||||||
"l2_snapshots": self.conn.execute("SELECT COUNT(*) FROM l2_snapshots").fetchone()[0],
|
"l2_snapshots": l2_count,
|
||||||
"trades": self.conn.execute("SELECT COUNT(*) FROM trades").fetchone()[0],
|
"trades": trade_count,
|
||||||
"funding": self.conn.execute("SELECT COUNT(*) FROM funding").fetchone()[0],
|
"funding": funding_count,
|
||||||
"coins": [r[0] for r in self.conn.execute(
|
"coins": [r[0] for r in coins_result],
|
||||||
"SELECT DISTINCT coin FROM l2_snapshots"
|
"date_range": date_result,
|
||||||
).fetchall()],
|
|
||||||
"date_range": self.conn.execute(
|
|
||||||
"SELECT MIN(exchange_ts_ms), MAX(exchange_ts_ms) FROM l2_snapshots"
|
|
||||||
).fetchone(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user