23 lines
605 B
Python
23 lines
605 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import declarative_base, sessionmaker
|
|
import os
|
|
|
|
# Create SQLite database in the app directory (mapped volume in Docker)
|
|
DB_FILE = os.path.join(os.path.dirname(__file__), "audit_data.db")
|
|
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_FILE}"
|
|
|
|
engine = create_engine(
|
|
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
|
|
)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
Base = declarative_base()
|
|
|
|
# Dependency
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|