16 lines
488 B
Python
16 lines
488 B
Python
import uuid
|
|
|
|
from sqlalchemy.orm import declarative_base
|
|
|
|
|
|
Base = declarative_base()
|
|
|
|
def as_dict(tbl: Base) -> dict:
|
|
out = { c.name: getattr(tbl, c.name) for c in tbl.__table__.columns }
|
|
|
|
# Some data types are not json serializable, so I need to do this separately
|
|
for key, value in out.items():
|
|
# UUIDs can be represented as strings, as they support creation from their string representation
|
|
if type(value) is uuid.UUID: out[key] = str(value)
|
|
|
|
return out |