Smiel2 commited on
Commit
71cf735
·
verified ·
1 Parent(s): a06e66e

Upload app/core/database.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app/core/database.py +16 -6
app/core/database.py CHANGED
@@ -6,12 +6,22 @@ from sqlalchemy.orm import sessionmaker, declarative_base
6
 
7
  from app.core.config import settings
8
 
9
- # Create async SQLAlchemy engine
10
- engine = create_async_engine(
11
- str(settings.DATABASE_URL).replace("postgresql://", "postgresql+asyncpg://"),
12
- pool_pre_ping=True,
13
- echo=settings.DEBUG,
14
- )
 
 
 
 
 
 
 
 
 
 
15
 
16
  # Create async SessionLocal class
17
  AsyncSessionLocal = sessionmaker(
 
6
 
7
  from app.core.config import settings
8
 
9
+ # Get the database URL from settings
10
+ db_url = str(settings.DATABASE_URL)
11
+
12
+ # For SQLite, don't add asyncpg prefix
13
+ if db_url.startswith("sqlite"):
14
+ engine = create_async_engine(
15
+ db_url,
16
+ echo=settings.DEBUG,
17
+ )
18
+ else:
19
+ # For PostgreSQL, add asyncpg prefix
20
+ engine = create_async_engine(
21
+ db_url.replace("postgresql://", "postgresql+asyncpg://"),
22
+ pool_pre_ping=True,
23
+ echo=settings.DEBUG,
24
+ )
25
 
26
  # Create async SessionLocal class
27
  AsyncSessionLocal = sessionmaker(