19 lines
554 B
Python
19 lines
554 B
Python
import os
|
|
from sqlalchemy import create_engine, text
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql+psycopg://timekeeper:timekeeper_pw@db:5432/timekeeper")
|
|
|
|
engine = create_engine(DATABASE_URL, pool_pre_ping=True, future=True)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine, future=True)
|
|
|
|
def get_session():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
def ping_db():
|
|
with engine.connect() as conn:
|
|
conn.execute(text("SELECT 1")) |