Command stats

This commit is contained in:
Stijn De Clercq 2021-09-07 17:16:40 +02:00
parent ce9ecc8c61
commit 41f75d7bbd
4 changed files with 47 additions and 45 deletions

View file

@ -1,4 +1,5 @@
from database import all_models, engine
from database import all_models, engine, Base
from typing import Dict
def create_all_tables():
@ -9,3 +10,16 @@ def create_all_tables():
"""
for model in all_models:
model.__table__.create(engine, checkfirst=True)
def row_to_dict(row: Base) -> Dict:
"""
Create a dictionary from a database entry
vars() or dict() can NOT be used as these add extra SQLAlchemy-related properties!
"""
d = {}
for column in row.__table__.columns:
d[column.name] = getattr(row, column.name)
return d