Commit existing codebase
This commit is contained in:
commit
49bc902bb9
24 changed files with 1208 additions and 0 deletions
21
app/db.py
Normal file
21
app/db.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from app.config import config
|
||||
|
||||
DATABASE_URL = f"postgresql://{config['CGNO_ID_DB_USERNAME']}:{config['CGNO_ID_DB_PASSWORD']}@{config['CGNO_ID_DB_HOST']}/{config['CGNO_ID_DB_NAME']}"
|
||||
|
||||
engine = create_engine(DATABASE_URL)
|
||||
|
||||
session_factory = sessionmaker(bind=engine)
|
||||
|
||||
EntityBase = declarative_base()
|
||||
|
||||
|
||||
def get_db():
|
||||
db = session_factory()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue