Download src/core/database/__init__.py from anaselamr/yaz: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/database/__init__.py
- Command line
-
hf download hf://spaces/anaselamr/yaz/src/core/database/__init__.py
-
curl -L -o __init__.py https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/database/__init__.py
1.69 kB
| """ | |
| Platform Database Module | |
| Core database infrastructure for YAZ Care Platform | |
| Exports: | |
| - ID Generation: PlatformID, new_uuid7 | |
| - Models: User (as CoreUser), Tenant, UserRole | |
| - Mixins: TenantMixin, TimestampMixin, SoftDeleteMixin | |
| - Sessions: get_db_session, get_async_session | |
| """ | |
| # Import session factories from manager | |
| from .manager import get_db_session | |
| from .mixins import SoftDeleteMixin, TenantMixin, TimestampMixin, UserTrackingMixin | |
| from .platform_id import PlatformID, new_uuid7 | |
| # Alias for compatibility | |
| get_async_session = get_db_session | |
| # CoreUser / Tenant are lazy-loaded so pytest --import-mode=importlib never trips | |
| # on "shared.models" not being on sys.path at collection time. The first genuine | |
| # access (e.g. `from core.database import CoreUser`) triggers the real import. | |
| _LAZY: dict[str, tuple[str, str]] = { | |
| "CoreUser": ("shared.models.user", "User"), | |
| "Tenant": ("shared.models.tenant", "Tenant"), | |
| } | |
| def __getattr__(name: str): | |
| if name in _LAZY: | |
| module_path, attr = _LAZY[name] | |
| import importlib as _il | |
| mod = _il.import_module(module_path) | |
| val = getattr(mod, attr) | |
| globals()[name] = val # cache so subsequent lookups skip __getattr__ | |
| return val | |
| raise AttributeError(f"module {__name__!r} has no attribute {name!r}") | |
| # Import UserRole enum from feature_flags | |
| from core.feature_flags.enums import UserRole | |
| __all__ = [ | |
| # ID Generation | |
| "PlatformID", | |
| "new_uuid7", | |
| # Mixins | |
| "TenantMixin", | |
| "TimestampMixin", | |
| "SoftDeleteMixin", | |
| "UserTrackingMixin", | |
| # Sessions | |
| "get_db_session", | |
| "get_async_session", | |
| # Models | |
| "CoreUser", | |
| "Tenant", | |
| "UserRole", | |
| ] | |