feat: separate sql

This commit is contained in:
Stijnvandenbroek
2026-03-06 14:26:20 +00:00
parent 81188a4569
commit c908d96921
16 changed files with 179 additions and 219 deletions

View File

@@ -1,17 +1,16 @@
"""Application configuration from environment variables."""
import os
from pathlib import Path
SQL_DIR = Path(__file__).parent / "sql"
class Settings:
"""Application settings loaded from environment variables.
Configure via DATABASE_URL (single connection string) or individual
POSTGRES_* variables. The application expects the target database to
contain:
- A listings table (default: marts.funda_listings)
- An ELO schema with ratings, comparisons, and sample_listings tables
(default: elo.*)
POSTGRES_* variables.
"""
POSTGRES_HOST: str = os.getenv("POSTGRES_HOST", "localhost")
@@ -23,6 +22,8 @@ class Settings:
LISTINGS_SCHEMA: str = os.getenv("LISTINGS_SCHEMA", "marts")
LISTINGS_TABLE: str = os.getenv("LISTINGS_TABLE", "funda_listings")
ELO_SCHEMA: str = os.getenv("ELO_SCHEMA", "elo")
IMAGES_SCHEMA: str = os.getenv("IMAGES_SCHEMA", "raw_funda")
IMAGES_TABLE: str = os.getenv("IMAGES_TABLE", "listing_details")
K_FACTOR: float = float(os.getenv("ELO_K_FACTOR", "32"))
DEFAULT_ELO: float = float(os.getenv("ELO_DEFAULT_RATING", "1500"))
@@ -39,3 +40,15 @@ class Settings:
settings = Settings()
def load_sql(name: str) -> str:
"""Load a SQL template from the sql/ directory and inject schema/table names."""
raw = (SQL_DIR / name).read_text()
return raw.format(
listings_schema=settings.LISTINGS_SCHEMA,
listings_table=settings.LISTINGS_TABLE,
elo_schema=settings.ELO_SCHEMA,
images_schema=settings.IMAGES_SCHEMA,
images_table=settings.IMAGES_TABLE,
)