mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
18 lines
400 B
Python
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
|