Seth0330 commited on
Commit
ff68972
·
verified ·
1 Parent(s): 7cbabf8

Update app/core/database.py

Browse files
Files changed (1) hide show
  1. app/core/database.py +8 -0
app/core/database.py CHANGED
@@ -2,10 +2,18 @@ from sqlalchemy import create_engine
2
  from sqlalchemy.orm import sessionmaker, declarative_base
3
  from .config import settings
4
 
 
 
 
 
 
 
5
  engine = create_engine(
6
  settings.DATABASE_URL,
 
7
  pool_pre_ping=True,
8
  )
9
 
10
  SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
 
11
  Base = declarative_base()
 
2
  from sqlalchemy.orm import sessionmaker, declarative_base
3
  from .config import settings
4
 
5
+ # If DATABASE_URL starts with sqlite, we need a special argument
6
+ connect_args = {}
7
+
8
+ if settings.DATABASE_URL.startswith("sqlite"):
9
+ connect_args = {"check_same_thread": False}
10
+
11
  engine = create_engine(
12
  settings.DATABASE_URL,
13
+ connect_args=connect_args,
14
  pool_pre_ping=True,
15
  )
16
 
17
  SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
18
+
19
  Base = declarative_base()