Carregar ficheiros para "/"
This commit is contained in:
23
database.py
Normal file
23
database.py
Normal file
@ -0,0 +1,23 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user