chore(*.sql): use sql-formatter for sql formatting
This commit is contained in:
parent
cf1ee4c97f
commit
1d7f13d1f5
63 changed files with 4432 additions and 2358 deletions
|
@ -6,16 +6,23 @@ SELECT
|
|||
ol.album_art,
|
||||
ol.artist_url,
|
||||
json_build_object(
|
||||
'title', ol.album_name,
|
||||
'image', ol.album_art,
|
||||
'url', ol.artist_url,
|
||||
'alt', CONCAT(ol.album_name, ' by ', ol.artist_name),
|
||||
'subtext', ol.artist_name
|
||||
'title',
|
||||
ol.album_name,
|
||||
'image',
|
||||
ol.album_art,
|
||||
'url',
|
||||
ol.artist_url,
|
||||
'alt',
|
||||
CONCAT(ol.album_name, ' by ', ol.artist_name),
|
||||
'subtext',
|
||||
ol.artist_name
|
||||
) AS grid,
|
||||
json_build_object(
|
||||
'open_graph_image',
|
||||
CASE
|
||||
WHEN ol.opengraph_image_album IS NOT NULL AND ol.opengraph_image_album != '' AND ol.opengraph_image_album != '/' THEN ol.opengraph_image_album
|
||||
WHEN ol.opengraph_image_album IS NOT NULL
|
||||
AND ol.opengraph_image_album != ''
|
||||
AND ol.opengraph_image_album != '/' THEN ol.opengraph_image_album
|
||||
ELSE NULL
|
||||
END
|
||||
) AS metadata
|
||||
|
|
|
@ -6,16 +6,23 @@ SELECT
|
|||
ol.artist_url,
|
||||
ARRAY_AGG(DISTINCT ol.genre_name) AS genres,
|
||||
json_build_object(
|
||||
'title', ol.artist_name,
|
||||
'image', ol.artist_art,
|
||||
'url', ol.artist_url,
|
||||
'alt', CONCAT(COUNT(*), ' plays of ', ol.artist_name),
|
||||
'subtext', CONCAT(COUNT(*), ' plays')
|
||||
'title',
|
||||
ol.artist_name,
|
||||
'image',
|
||||
ol.artist_art,
|
||||
'url',
|
||||
ol.artist_url,
|
||||
'alt',
|
||||
CONCAT(COUNT(*), ' plays of ', ol.artist_name),
|
||||
'subtext',
|
||||
CONCAT(COUNT(*), ' plays')
|
||||
) AS grid,
|
||||
json_build_object(
|
||||
'open_graph_image',
|
||||
CASE
|
||||
WHEN ol.opengraph_image_artist IS NOT NULL AND ol.opengraph_image_artist != '' AND ol.opengraph_image_artist != '/' THEN ol.opengraph_image_artist
|
||||
WHEN ol.opengraph_image_artist IS NOT NULL
|
||||
AND ol.opengraph_image_artist != ''
|
||||
AND ol.opengraph_image_artist != '/' THEN ol.opengraph_image_artist
|
||||
ELSE NULL
|
||||
END
|
||||
) AS metadata
|
||||
|
|
|
@ -3,7 +3,12 @@ SELECT
|
|||
ol.genre_name,
|
||||
ol.genre_url,
|
||||
COUNT(*) AS plays,
|
||||
json_build_object('alt', ol.genre_name, 'subtext', CONCAT(COUNT(*), ' plays')) AS grid
|
||||
json_build_object(
|
||||
'alt',
|
||||
ol.genre_name,
|
||||
'subtext',
|
||||
CONCAT(COUNT(*), ' plays')
|
||||
) AS grid
|
||||
FROM
|
||||
optimized_listens ol
|
||||
WHERE
|
||||
|
@ -13,4 +18,3 @@ GROUP BY
|
|||
ol.genre_url
|
||||
ORDER BY
|
||||
plays DESC;
|
||||
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
CREATE OR REPLACE VIEW month_tracks AS
|
||||
WITH track_stats AS (
|
||||
SELECT
|
||||
ol.track_name,
|
||||
ol.artist_name,
|
||||
ol.album_name,
|
||||
COUNT(*) AS plays,
|
||||
MAX(ol.listened_at) AS last_listened,
|
||||
ol.album_art,
|
||||
ol.artist_url,
|
||||
MAX(COUNT(*)) OVER () AS most_played
|
||||
FROM
|
||||
optimized_listens ol
|
||||
WHERE
|
||||
TO_TIMESTAMP(ol.listened_at) >= NOW() - INTERVAL '30 days'
|
||||
GROUP BY
|
||||
ol.track_name,
|
||||
ol.artist_name,
|
||||
ol.album_name,
|
||||
ol.album_art,
|
||||
ol.artist_url
|
||||
)
|
||||
WITH
|
||||
track_stats AS (
|
||||
SELECT
|
||||
ol.track_name,
|
||||
ol.artist_name,
|
||||
ol.album_name,
|
||||
COUNT(*) AS plays,
|
||||
MAX(ol.listened_at) AS last_listened,
|
||||
ol.album_art,
|
||||
ol.artist_url,
|
||||
MAX(COUNT(*)) OVER () AS most_played
|
||||
FROM
|
||||
optimized_listens ol
|
||||
WHERE
|
||||
TO_TIMESTAMP(ol.listened_at) >= NOW() - INTERVAL '30 days'
|
||||
GROUP BY
|
||||
ol.track_name,
|
||||
ol.artist_name,
|
||||
ol.album_name,
|
||||
ol.album_art,
|
||||
ol.artist_url
|
||||
)
|
||||
SELECT
|
||||
track_name,
|
||||
artist_name,
|
||||
|
@ -28,10 +29,24 @@ SELECT
|
|||
last_listened,
|
||||
album_art,
|
||||
artist_url,
|
||||
json_build_object('title', track_name, 'artist', artist_name, 'url', artist_url, 'plays', plays, 'alt', CONCAT(track_name, ' by ', artist_name), 'subtext', CONCAT(album_name, ' (', plays, ' plays)'), 'percentage', ROUND((plays::decimal / most_played) * 100, 2)) AS chart
|
||||
json_build_object(
|
||||
'title',
|
||||
track_name,
|
||||
'artist',
|
||||
artist_name,
|
||||
'url',
|
||||
artist_url,
|
||||
'plays',
|
||||
plays,
|
||||
'alt',
|
||||
CONCAT(track_name, ' by ', artist_name),
|
||||
'subtext',
|
||||
CONCAT(album_name, ' (', plays, ' plays)'),
|
||||
'percentage',
|
||||
ROUND((plays::decimal / most_played) * 100, 2)
|
||||
) AS chart
|
||||
FROM
|
||||
track_stats
|
||||
ORDER BY
|
||||
plays DESC,
|
||||
last_listened DESC;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue