26 lines
581 B
Python
26 lines
581 B
Python
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from sqlalchemy.ext.asyncio import (
|
|
AsyncEngine,
|
|
AsyncSession,
|
|
async_sessionmaker,
|
|
create_async_engine,
|
|
)
|
|
|
|
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///./app.db")
|
|
|
|
_engine: AsyncEngine = create_async_engine(DATABASE_URL, echo=False, future=True)
|
|
_sessionmaker: async_sessionmaker[AsyncSession] = async_sessionmaker(
|
|
bind=_engine, expire_on_commit=False
|
|
)
|
|
|
|
|
|
def get_engine() -> AsyncEngine:
|
|
return _engine
|
|
|
|
|
|
def get_sessionmaker() -> async_sessionmaker[AsyncSession]:
|
|
return _sessionmaker
|