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,29 +1,9 @@
"""Shared query helpers for listing data."""
from app.config import settings
from app.config import load_sql, settings
from app.schemas import ListingResponse
LISTING_SELECT = f"""
SELECT
l.global_id, l.tiny_id, l.url, l.title, l.city, l.postcode,
l.province, l.neighbourhood, l.municipality,
l.latitude, l.longitude,
l.object_type, l.house_type, l.offering_type,
l.construction_type, l.construction_year,
l.energy_label, l.living_area, l.plot_area,
l.bedrooms, l.rooms,
l.has_garden, l.has_balcony, l.has_solar_panels,
l.has_heat_pump, l.has_roof_terrace,
l.is_energy_efficient, l.is_monument,
l.current_price, l.status, l.price_per_sqm,
l.publication_date,
COALESCE(r.elo_rating, {settings.DEFAULT_ELO}) AS elo_rating,
COALESCE(r.comparison_count, 0) AS comparison_count,
COALESCE(r.wins, 0) AS wins,
COALESCE(r.losses, 0) AS losses
FROM {settings.LISTINGS_SCHEMA}.{settings.LISTINGS_TABLE} l
LEFT JOIN {settings.ELO_SCHEMA}.ratings r ON l.global_id = r.global_id
"""
LISTING_SELECT = load_sql("listing_select.sql")
def row_to_listing(row) -> ListingResponse: