ddstats/sql/maps/search_maps.sql

22 lines
1.8 KiB
MySQL
Raw Permalink Normal View History

2023-04-16 20:55:28 +02:00
SELECT record_maps.map, category, points, stars, mappers, release, width, height, tiles
FROM record_maps JOIN record_mapinfo_array ON record_maps.map = record_mapinfo_array.map
WHERE ($1::TEXT IS NULL OR record_maps.map ILIKE $1)
2023-04-17 09:36:55 +02:00
AND (ARRAY_LENGTH(ARRAY[]::TEXT[], 1) > 0 IS TRUE OR $2::TEXT[] <@ mappers::TEXT[])
2023-04-16 20:55:28 +02:00
AND ($3::TEXT IS NULL OR category = $3)
AND ($4::SMALLINT[] IS NULL OR stars = ANY($4))
AND ($5::TIMESTAMP IS NULL OR release >= $5)
AND ($6::TIMESTAMP IS NULL OR release <= $6)
2023-04-17 09:36:55 +02:00
AND (ARRAY_LENGTH(ARRAY[]::TEXT[], 1) > 0 IS TRUE OR $7::TEXT[] <@ tiles::TEXT[])
ORDER BY -- what in the flying fuck
2023-04-23 10:40:12 +02:00
(CASE WHEN lower($8) = 'map' AND lower($9) = 'asc' THEN record_maps.map END) ASC,
(CASE WHEN lower($8) = 'map' AND lower($9) = 'desc' THEN record_maps.map END) DESC,
(CASE WHEN lower($8) = 'category' AND lower($9) = 'asc' THEN category END) ASC,
(CASE WHEN lower($8) = 'category' AND lower($9) = 'desc' THEN category END) DESC,
(CASE WHEN lower($8) = 'points' AND lower($9) = 'asc' THEN points::INTEGER END) ASC,
(CASE WHEN lower($8) = 'points' AND lower($9) = 'desc' THEN points::INTEGER END) DESC,
(CASE WHEN lower($8) = 'stars' AND lower($9) = 'asc' THEN stars::INTEGER END) ASC,
(CASE WHEN lower($8) = 'stars' AND lower($9) = 'desc' THEN stars::INTEGER END) DESC,
(CASE WHEN lower($8) = 'width' AND lower($9) = 'asc' THEN width::INTEGER END) ASC,
(CASE WHEN lower($8) = 'width' AND lower($9) = 'desc' THEN width::INTEGER END) DESC,
(CASE WHEN lower($8) = 'height' AND lower($9) = 'asc' THEN height::INTEGER END) ASC,
(CASE WHEN lower($8) = 'height' AND lower($9) = 'desc' THEN height::INTEGER END) DESC