aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hashserv/sqlalchemy.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/hashserv/sqlalchemy.py')
-rw-r--r--lib/hashserv/sqlalchemy.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/hashserv/sqlalchemy.py b/lib/hashserv/sqlalchemy.py
index bfd8a8446..818b51951 100644
--- a/lib/hashserv/sqlalchemy.py
+++ b/lib/hashserv/sqlalchemy.py
@@ -27,6 +27,7 @@ from sqlalchemy import (
and_,
delete,
update,
+ func,
)
import sqlalchemy.engine
from sqlalchemy.orm import declarative_base
@@ -401,3 +402,16 @@ class Database(object):
async with self.db.begin():
result = await self.db.execute(statement)
return result.rowcount != 0
+
+ async def get_usage(self):
+ usage = {}
+ async with self.db.begin() as session:
+ for name, table in Base.metadata.tables.items():
+ statement = select(func.count()).select_from(table)
+ self.logger.debug("%s", statement)
+ result = await self.db.execute(statement)
+ usage[name] = {
+ "rows": result.scalar(),
+ }
+
+ return usage