aboutsummaryrefslogtreecommitdiff
path: root/app/db.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/db.py')
-rw-r--r--app/db.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/app/db.py b/app/db.py
new file mode 100644
index 0000000..5846834
--- /dev/null
+++ b/app/db.py
@@ -0,0 +1,16 @@
+from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine, AsyncSession
+from sqlalchemy.orm import DeclarativeBase
+from app.config import settings
+
+
+class Base(DeclarativeBase):
+ pass
+
+
+engine = create_async_engine(settings.database_url, future=True)
+SessionLocal = async_sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)
+
+
+async def get_db() -> AsyncSession:
+ async with SessionLocal() as session:
+ yield session