Fred808 commited on
Commit
0f8ccfb
·
verified ·
1 Parent(s): 3840f7b

Update app/db/database.py

Browse files
Files changed (1) hide show
  1. app/db/database.py +32 -30
app/db/database.py CHANGED
@@ -1,30 +1,32 @@
1
- from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
2
- from sqlalchemy.orm import sessionmaker, declarative_base
3
- from sqlalchemy import create_engine
4
- from ..core.config import settings
5
-
6
- # Create async engine for FastAPI
7
- async_engine = create_async_engine(
8
- settings.DATABASE_URL,
9
- echo=True,
10
- future=True,
11
- pool_pre_ping=True
12
- )
13
-
14
- # Create async session factory
15
- AsyncSessionLocal = async_sessionmaker(
16
- bind=async_engine,
17
- class_=AsyncSession,
18
- expire_on_commit=False
19
- )
20
-
21
- # Create declarative base for models
22
- Base = declarative_base()
23
-
24
- # Database dependency
25
- async def get_db():
26
- async with AsyncSessionLocal() as session:
27
- try:
28
- yield session
29
- finally:
30
- await session.close()
 
 
 
1
+ from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
2
+ from sqlalchemy.orm import declarative_base
3
+ from ..core.config import settings
4
+
5
+ # Create async engine for FastAPI
6
+ async_engine = create_async_engine(
7
+ settings.DATABASE_URL,
8
+ echo=True,
9
+ future=True,
10
+ pool_pre_ping=True
11
+ )
12
+
13
+ # Create async session factory
14
+ AsyncSessionLocal = async_sessionmaker(
15
+ bind=async_engine,
16
+ class_=AsyncSession,
17
+ expire_on_commit=False
18
+ )
19
+
20
+ # Create declarative base for models
21
+ Base = declarative_base()
22
+
23
+ # Database dependency for FastAPI routes
24
+ async def get_db():
25
+ async with AsyncSessionLocal() as session:
26
+ try:
27
+ yield session
28
+ finally:
29
+ await session.close()
30
+
31
+ # Add alias for external imports
32
+ db = AsyncSessionLocal