feat: separate sql
This commit is contained in:
1
backend/app/sql/count_comparisons.sql
Normal file
1
backend/app/sql/count_comparisons.sql
Normal file
@@ -0,0 +1 @@
|
||||
select count(*) from {elo_schema}.comparisons
|
||||
1
backend/app/sql/count_listings.sql
Normal file
1
backend/app/sql/count_listings.sql
Normal file
@@ -0,0 +1 @@
|
||||
select count(*) from {listings_schema}.{listings_table}
|
||||
1
backend/app/sql/count_rated.sql
Normal file
1
backend/app/sql/count_rated.sql
Normal file
@@ -0,0 +1 @@
|
||||
select count(*) from {elo_schema}.ratings
|
||||
5
backend/app/sql/elo_aggregates.sql
Normal file
5
backend/app/sql/elo_aggregates.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
select
|
||||
avg(elo_rating),
|
||||
max(elo_rating),
|
||||
min(elo_rating)
|
||||
from {elo_schema}.ratings
|
||||
6
backend/app/sql/elo_distribution.sql
Normal file
6
backend/app/sql/elo_distribution.sql
Normal 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
|
||||
14
backend/app/sql/history.sql
Normal file
14
backend/app/sql/history.sql
Normal 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
|
||||
4
backend/app/sql/listing_images.sql
Normal file
4
backend/app/sql/listing_images.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
select
|
||||
raw_json -> 'photo_urls' as photo_urls
|
||||
from {images_schema}.{images_table}
|
||||
where global_id = :gid
|
||||
40
backend/app/sql/listing_select.sql
Normal file
40
backend/app/sql/listing_select.sql
Normal 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
|
||||
6
backend/app/sql/recent_pairs.sql
Normal file
6
backend/app/sql/recent_pairs.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
select
|
||||
listing_a_id,
|
||||
listing_b_id
|
||||
from {elo_schema}.comparisons
|
||||
order by created_at desc
|
||||
limit 20
|
||||
Reference in New Issue
Block a user