mirror of
https://github.com/wowlikon/LibraryAPI.git
synced 2025-12-11 21:30:46 +00:00
19 lines
483 B
Python
19 lines
483 B
Python
from sqlmodel import create_engine, SQLModel, Session
|
|
from dotenv import load_dotenv
|
|
import os
|
|
|
|
# Get database configuration
|
|
load_dotenv()
|
|
DATABASE_URL = os.getenv("DATABASE_URL")
|
|
if not DATABASE_URL:
|
|
raise ValueError("DATABASE_URL environment variable is not set")
|
|
|
|
# Create database engine
|
|
engine = create_engine(DATABASE_URL, echo=True)
|
|
SQLModel.metadata.create_all(engine)
|
|
|
|
# Get database session
|
|
def get_session():
|
|
with Session(engine) as session:
|
|
yield session
|