from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from models import Base import os # Get the absolute path to the database file DATABASE_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "automotive_docs.db") DATABASE_URL = f"sqlite:///{DATABASE_FILE}" def init_db(): # Create new engine engine = create_engine(DATABASE_URL) # Create tables if they don't exist if not os.path.exists(DATABASE_FILE): Base.metadata.create_all(engine) return engine def get_session(): engine = create_engine(DATABASE_URL) Session = sessionmaker(bind=engine) return Session()