Model/backend/app/db/utils.py
2023-08-10 18:26:41 +01:00

18 lines
400 B
Python

import enum
def row2dict(row):
"""
Generic function to convert a SQLAlchemy row to a dictionary.
May not be the best practice implementing like this but works for the moment
"""
d = {}
for column in row.__table__.columns:
val = getattr(row, column.name)
if isinstance(val, enum.Enum):
val = val.value
d[column.name] = val
return d