Spaces:
Sleeping
Sleeping
Create database.py
Browse files- app/database.py +16 -0
app/database.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sqlalchemy import create_engine
|
| 2 |
+
from sqlalchemy.orm import sessionmaker, declarative_base
|
| 3 |
+
from app.config import settings
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
engine = create_engine(settings.DATABASE_URL, pool_pre_ping=True, future=True)
|
| 7 |
+
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine, future=True)
|
| 8 |
+
Base = declarative_base()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def get_db():
|
| 12 |
+
db = SessionLocal()
|
| 13 |
+
try:
|
| 14 |
+
yield db
|
| 15 |
+
finally:
|
| 16 |
+
db.close()
|