Spaces:
Sleeping
Sleeping
Download app/models/base.py from yabeskn/briga-core-api: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/yabeskn/briga-core-api/resolve/main/app/models/base.py
- Command line
-
hf download hf://spaces/yabeskn/briga-core-api/app/models/base.py
-
curl -L -o base.py https://huggingface.co/spaces/yabeskn/briga-core-api/resolve/main/app/models/base.py
1.17 kB
| """Single shared SQLAlchemy declarative Base for all Brigawan models. | |
| All model modules should import Base from here to ensure Alembic | |
| and cross-table relationships work correctly. | |
| Also provides renderable JSONB type for SQLite dev compatibility. | |
| """ | |
| from sqlalchemy import TypeDecorator, Text | |
| from sqlalchemy.dialects.postgresql import JSONB as PGJSONB | |
| from sqlalchemy.orm import declarative_base | |
| import json | |
| class JSONB(TypeDecorator): | |
| """Cross-dialect JSONB type. | |
| Uses native JSONB on PostgreSQL, falls back to JSON text on SQLite. | |
| """ | |
| impl = Text | |
| cache_ok = True | |
| def load_dialect_impl(self, dialect): | |
| if dialect.name == "postgresql": | |
| return dialect.type_descriptor(PGJSONB()) | |
| return dialect.type_descriptor(Text()) | |
| def process_bind_param(self, value, dialect): | |
| if dialect.name == "postgresql": | |
| return value | |
| return json.dumps(value) if value is not None else None | |
| def process_result_value(self, value, dialect): | |
| if dialect.name == "postgresql": | |
| return value | |
| return json.loads(value) if value is not None else None | |
| Base = declarative_base() | |