first commit
This commit is contained in:
0
app/database/__init__.py
Normal file
0
app/database/__init__.py
Normal file
15
app/database/base.py
Normal file
15
app/database/base.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from sqlalchemy import MetaData
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
|
||||
|
||||
NAMING_CONVENTION = {
|
||||
"ix": "ix_%(column_0_label)s",
|
||||
"uq": "uq_%(table_name)s_%(column_0_name)s",
|
||||
"ck": "ck_%(table_name)s_%(constraint_name)s",
|
||||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
||||
"pk": "pk_%(table_name)s",
|
||||
}
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
metadata = MetaData(naming_convention=NAMING_CONVENTION)
|
||||
19
app/database/models.py
Normal file
19
app/database/models.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from app.auth.models import EmailVerificationToken, PasswordResetToken
|
||||
from app.chats.models import Chat, ChatMember
|
||||
from app.email.models import EmailLog
|
||||
from app.media.models import Attachment
|
||||
from app.messages.models import Message
|
||||
from app.notifications.models import NotificationLog
|
||||
from app.users.models import User
|
||||
|
||||
__all__ = [
|
||||
"Attachment",
|
||||
"Chat",
|
||||
"ChatMember",
|
||||
"EmailLog",
|
||||
"EmailVerificationToken",
|
||||
"Message",
|
||||
"NotificationLog",
|
||||
"PasswordResetToken",
|
||||
"User",
|
||||
]
|
||||
25
app/database/session.py
Normal file
25
app/database/session.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from collections.abc import AsyncIterator
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||
|
||||
from app.config.settings import settings
|
||||
|
||||
|
||||
engine = create_async_engine(
|
||||
settings.postgres_dsn,
|
||||
echo=settings.debug,
|
||||
pool_pre_ping=True,
|
||||
)
|
||||
|
||||
AsyncSessionLocal = async_sessionmaker(
|
||||
bind=engine,
|
||||
class_=AsyncSession,
|
||||
autoflush=False,
|
||||
autocommit=False,
|
||||
expire_on_commit=False,
|
||||
)
|
||||
|
||||
|
||||
async def get_db() -> AsyncIterator[AsyncSession]:
|
||||
async with AsyncSessionLocal() as session:
|
||||
yield session
|
||||
Reference in New Issue
Block a user