lots of changes
This commit is contained in:
27
database.py
Normal file
27
database.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from sqlalchemy import create_engine
|
||||
from dqlalchemy.orm import sessionmaker, declaritive_base
|
||||
|
||||
DATABASE_URL = "sqlite:///./locations.db"
|
||||
|
||||
engine = create_engine(
|
||||
DATABASE_URL, connect_engine("check_same_thread": false}
|
||||
)
|
||||
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
def get_db():
|
||||
"""Dependency for getting database session."""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
def create_all_tables():
|
||||
"""Creates all tables defined with Base in the database."""
|
||||
# Note: import models before calling create_all_tables()
|
||||
Base.metadata_create_all(bind=engine)
|
||||
print("Database and tables created.")
|
||||
|
||||
Reference in New Issue
Block a user