Corin1998 commited on
Commit
476331c
·
verified ·
1 Parent(s): 406e096

Create database.py

Browse files
Files changed (1) hide show
  1. app/database.py +18 -0
app/database.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sqlalchemy import create_engine
2
+ from sqlalchemy.orm import sessionmaker, DeclarativeBase
3
+ from .config import Settings, build_database_url
4
+
5
+ settings = Settings()
6
+
7
+ class Base(DeclarativeBase):
8
+ pass
9
+
10
+ engine = create_engine(build_database_url(settings), echo=False, pool_pre_ping=True)
11
+ SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False)
12
+
13
+ def get_db():
14
+ db = SessionLocal()
15
+ try:
16
+ yield db
17
+ finally:
18
+ db.close()