diff options
| author | l3wdfut4pwr <l3wdfut4pwr@gmail.com> | 2026-03-17 14:11:45 +0200 |
|---|---|---|
| committer | l3wdfut4pwr <l3wdfut4pwr@gmail.com> | 2026-03-17 14:11:45 +0200 |
| commit | 47fd81a5910eab3483f79d03eedf9307bc81252f (patch) | |
| tree | 3e1ebd1bddcea649eb968e65161555afd4c2898c /app/utils/db.py | |
| parent | f01cb6703710b7df4c7c022047cd35e1d5e9c70e (diff) | |
simple registration prototype
Diffstat (limited to 'app/utils/db.py')
| -rw-r--r-- | app/utils/db.py | 25 |
1 files changed, 25 insertions, 0 deletions
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 |
