mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-08 08:12:34 +08:00
Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019cf73e-7f44-7003-8886-58eaaf1edbf4
24 lines
666 B
Python
24 lines
666 B
Python
from typing import Any
|
|
from datetime import datetime, timezone
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
def to_dict(obj: Any, include_none: bool = False) -> dict[str, Any]:
|
|
fields = obj.__table__.columns.keys()
|
|
out: dict[str, Any] = {}
|
|
for field in fields:
|
|
val = getattr(obj, field)
|
|
if val is None and not include_none:
|
|
continue
|
|
if isinstance(val, datetime):
|
|
if val.tzinfo is None:
|
|
val = val.replace(tzinfo=timezone.utc)
|
|
out[field] = val.isoformat()
|
|
else:
|
|
out[field] = val
|
|
return out
|
|
|
|
# TODO: Define models here
|