Spaces:
Sleeping
Sleeping
Upload app/core/database.py with huggingface_hub
Browse files- 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 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 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(
|