mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
21 lines
759 B
Python
21 lines
759 B
Python
from sqlalchemy import create_engine
|
|
from backend.app.config import get_settings
|
|
from sqlmodel import Session
|
|
|
|
connection_string = "postgresql+{drivername}://{username}:{password}@{server}:{port}/{dbname}"
|
|
db_string = connection_string.format(
|
|
drivername="psycopg2", # You'll need to use psycopg2 driver for PostgreSQL
|
|
username=get_settings().DB_USERNAME,
|
|
password=get_settings().DB_PASSWORD,
|
|
server=get_settings().DB_HOST,
|
|
port=get_settings().DB_PORT,
|
|
dbname=get_settings().DB_NAME,
|
|
)
|
|
|
|
db_engine = create_engine(db_string, pool_size=5, max_overflow=5)
|
|
|
|
|
|
def get_db_session():
|
|
if db_engine is None:
|
|
raise RuntimeError("Database is not configured. Set DATABASE_URL in environment variables.")
|
|
return Session(db_engine)
|