kacapower commited on
Commit
f212b2a
·
verified ·
1 Parent(s): f665c79

Create app/database.py

Browse files
Files changed (1) hide show
  1. app/database.py +21 -0
app/database.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from sqlalchemy import create_engine
3
+ from sqlalchemy.orm import declarative_base, sessionmaker
4
+
5
+ # Pointing to the temporary Docker directory
6
+ DB_DIR = "/code/data"
7
+ SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/lexical.db"
8
+
9
+ engine = create_engine(
10
+ SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
11
+ )
12
+
13
+ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
14
+ Base = declarative_base()
15
+
16
+ def get_db():
17
+ db = SessionLocal()
18
+ try:
19
+ yield db
20
+ finally:
21
+ db.close()