File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55DATABASE_URL = os .getenv ("DATABASE_URL" , "sqlite:///./certificates.db" )
66
7- # Adjust connection arguments for SQLite only
8- connect_args = {"check_same_thread" : False } if DATABASE_URL .startswith ("sqlite" ) else None
7+ # SQLite needs check_same_thread=False.
8+ # PostgreSQL does not need extra connect_args.
9+ connect_args = {}
10+
11+ if DATABASE_URL .startswith ("sqlite" ):
12+ connect_args = {"check_same_thread" : False }
13+
14+ engine = create_engine (
15+ DATABASE_URL ,
16+ connect_args = connect_args ,
17+ )
18+
19+ SessionLocal = sessionmaker (
20+ autocommit = False ,
21+ autoflush = False ,
22+ bind = engine ,
23+ )
924
10- engine = create_engine (DATABASE_URL , connect_args = connect_args )
11- SessionLocal = sessionmaker (autocommit = False , autoflush = False , bind = engine )
1225Base = declarative_base ()
1326
27+
1428def get_db ():
1529 db = SessionLocal ()
1630 try :
1731 yield db
1832 finally :
19- db .close ()
33+ db .close ()
You can’t perform that action at this time.
0 commit comments