first commit
This commit is contained in:
4
app/db/__init__.py
Normal file
4
app/db/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from app.db.base import Base
|
||||
from app.db.session import get_session_factory, init_engine
|
||||
|
||||
__all__ = ("Base", "get_session_factory", "init_engine")
|
||||
5
app/db/base.py
Normal file
5
app/db/base.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
23
app/db/session.py
Normal file
23
app/db/session.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from sqlalchemy.ext.asyncio import (
|
||||
AsyncEngine,
|
||||
AsyncSession,
|
||||
async_sessionmaker,
|
||||
create_async_engine,
|
||||
)
|
||||
|
||||
|
||||
def init_engine(database_url: str) -> AsyncEngine:
|
||||
return create_async_engine(
|
||||
database_url,
|
||||
echo=False,
|
||||
pool_pre_ping=True,
|
||||
)
|
||||
|
||||
|
||||
def get_session_factory(engine: AsyncEngine) -> async_sessionmaker[AsyncSession]:
|
||||
return async_sessionmaker(
|
||||
engine,
|
||||
class_=AsyncSession,
|
||||
expire_on_commit=False,
|
||||
autoflush=False,
|
||||
)
|
||||
Reference in New Issue
Block a user