generated from render-examples/fastapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
30 lines (21 loc) · 1022 Bytes
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from config import settings
# SQLALCHEMY_DATABASE_URL = f'{settings.DATABASE_URL}'
# SQLALCHEMY_DATABASE_URL = f'postgresql://root_joezzy:7i1GteVz51krwJdulNimlwb7FJzypuMP@dpg-cnj3om8l6cac739bqbig-a.oregon-postgres.render.com/fastapi_i719'
SQLALCHEMY_DATABASE_URL = f'postgresql://root:7Iu1AruoCZCqbVwyD9Yc1RDQRnDma1x1@dpg-cnj4qd779t8c7399o0jg-a/fastapi_m4ho'
# SQLALCHEMY_DATABASE_URL = f'postgres://{settings.DATABASE_USERNAME}:{settings.DATABASE_PASSWORD}@{settings.DATABASE_HOST}/{settings.DATABASE_NAME}'
engine = create_engine( SQLALCHEMY_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
# Dependency
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
# engine = create_engine(
# SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
# )