mirror of https://github.com/stijndcl/didier
26 lines
633 B
Python
26 lines
633 B
Python
from database import all_models, engine, Base
|
|
from typing import Dict
|
|
|
|
|
|
def create_all_tables():
|
|
"""
|
|
Create all tables in case they don't exist yet
|
|
so the user doesn't have to do this manually
|
|
when a new table is added
|
|
"""
|
|
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
|