File size: 951 Bytes
e8efc4f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # src/database.py
from sqlmodel import SQLModel, create_engine, Session
from typing import Generator
import os
# --- INSTRUCTIONS ---
# 1. Get credentials from environment variables (Os.getenv)
# 2. Construct the DATABASE_URL string: postgresql://user:pass@host:port/db
# 3. Create the SQLModel engine
# 4. Implement the init_db and get_session functions
# TODO: Define constants for DB params (POSTGRES_USER, etc.)
# TODO: Define DATABASE_URL
# TODO: Create 'engine' using create_engine(DATABASE_URL)
def init_db():
"""
Idempotent DB initialization.
Should create all tables defined in SQLModel metadata.
"""
# TODO: Call SQLModel.metadata.create_all(engine)
pass
def get_session() -> Generator[Session, None, None]:
"""
Dependency for yielding a database session.
Useful for FastAPI dependencies or context usage.
"""
# TODO: Open a session with the engine, yield it, and ensure it closes
pass
|