feat: separate sql
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user