activity-core/src/activity_core/db.py

20 lines
571 B
Python
Raw Normal View History

"""SQLAlchemy async engine and declarative base for activity-core."""
import os
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
from sqlalchemy.orm import DeclarativeBase
class Base(DeclarativeBase):
pass
def make_engine(url: str | None = None) -> AsyncEngine:
"""Return an async engine. Falls back to ACTCORE_DB_URL, then the dev default."""
resolved = url or os.environ.get(
"ACTCORE_DB_URL",
"postgresql+asyncpg://actcore:actcore@localhost:5433/actcore",
)
return create_async_engine(resolved, echo=False)