init
This commit is contained in:
25
app/infrastructure/db/sqlalchemy/session.py
Normal file
25
app/infrastructure/db/sqlalchemy/session.py
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
Reference in New Issue
Block a user