From 47fd81a5910eab3483f79d03eedf9307bc81252f Mon Sep 17 00:00:00 2001 From: l3wdfut4pwr Date: Tue, 17 Mar 2026 14:11:45 +0200 Subject: simple registration prototype --- app/utils/db.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/utils/db.py (limited to 'app/utils/db.py') diff --git a/app/utils/db.py b/app/utils/db.py new file mode 100644 index 0000000..603ff68 --- /dev/null +++ b/app/utils/db.py @@ -0,0 +1,25 @@ +# app/utils/db.py +import os + +from dotenv import load_dotenv +from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine +from sqlalchemy.orm import DeclarativeBase, sessionmaker + +load_dotenv() + +DATABASE_URL = os.getenv("DATABASE_URL") +if not DATABASE_URL: + raise ValueError("DATABASE_URL не найден в .env!") + +engine = create_async_engine(DATABASE_URL, echo=True, future=True) + +async_session = sessionmaker(bind=engine, class_=AsyncSession, expire_on_commit=False) + + +async def get_async_session() -> AsyncSession: + async with async_session() as session: + yield session + + +class Base(DeclarativeBase): + pass -- cgit v1.3-3-g829e