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

@@ -0,0 +1 @@
select count(*) from {elo_schema}.comparisons

View File

@@ -0,0 +1 @@
select count(*) from {listings_schema}.{listings_table}

View File

@@ -0,0 +1 @@
select count(*) from {elo_schema}.ratings

View File

@@ -0,0 +1,5 @@
select
avg(elo_rating),
max(elo_rating),
min(elo_rating)
from {elo_schema}.ratings

View File

@@ -0,0 +1,6 @@
select
floor(elo_rating / 50) * 50 as bucket,
count(*) as count
from {elo_schema}.ratings
group by bucket
order by bucket

View File

@@ -0,0 +1,14 @@
select
c.*,
a.title as listing_a_title,
b.title as listing_b_title,
w.title as winner_title
from {elo_schema}.comparisons as c
left join {listings_schema}.{listings_table} as a
on c.listing_a_id = a.global_id
left join {listings_schema}.{listings_table} as b
on c.listing_b_id = b.global_id
left join {listings_schema}.{listings_table} as w
on c.winner_id = w.global_id
order by c.created_at desc
limit :limit

View File

@@ -0,0 +1,4 @@
select
raw_json -> 'photo_urls' as photo_urls
from {images_schema}.{images_table}
where global_id = :gid

View File

@@ -0,0 +1,40 @@
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, :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 {listings_schema}.{listings_table} as l
left join {elo_schema}.ratings as r
on l.global_id = r.global_id

View File

@@ -0,0 +1,6 @@
select
listing_a_id,
listing_b_id
from {elo_schema}.comparisons
order by created_at desc
limit 20