feat: initial view queries
This commit is contained in:
parent
8f44ce9bdd
commit
08e2c2ff3f
23 changed files with 1282 additions and 10 deletions
89
views/feeds/all-content.psql
Normal file
89
views/feeds/all-content.psql
Normal file
|
@ -0,0 +1,89 @@
|
|||
CREATE OR REPLACE VIEW optimized_all_activity AS
|
||||
WITH feed_data AS (
|
||||
SELECT
|
||||
p.date AS content_date,
|
||||
'post' AS content_type,
|
||||
p.title,
|
||||
p.description,
|
||||
CONCAT('https://coryd.dev', p.url) AS url,
|
||||
NULL AS image,
|
||||
NULL AS rating,
|
||||
p.tags,
|
||||
json_build_object(
|
||||
'title', p.title,
|
||||
'url', CONCAT('https://coryd.dev', p.url),
|
||||
'description', p.description,
|
||||
'date', p.date
|
||||
) AS feed
|
||||
FROM optimized_posts p
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
l.date AS content_date,
|
||||
'link' AS content_type,
|
||||
CONCAT(l.title, ' via ', l.name) AS title,
|
||||
l.description,
|
||||
l.link AS url,
|
||||
NULL AS image,
|
||||
NULL AS rating,
|
||||
l.tags,
|
||||
json_build_object(
|
||||
'title', CONCAT(l.title, ' via ', l.name),
|
||||
'url', l.link,
|
||||
'description', l.description,
|
||||
'date', l.date
|
||||
) AS feed
|
||||
FROM optimized_links l
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
b.date_finished AS content_date,
|
||||
'book' AS content_type,
|
||||
b.title,
|
||||
b.description,
|
||||
CONCAT('https://coryd.dev', b.url) AS url,
|
||||
b.image,
|
||||
b.rating,
|
||||
b.tags,
|
||||
CASE
|
||||
WHEN LOWER(b.status) = 'finished' THEN json_build_object(
|
||||
'title', b.title,
|
||||
'url', CONCAT('https://coryd.dev', b.url),
|
||||
'description', b.description,
|
||||
'image', b.image,
|
||||
'rating', b.rating,
|
||||
'date', b.date_finished
|
||||
)
|
||||
ELSE NULL
|
||||
END AS feed
|
||||
FROM optimized_books b
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
m.last_watched AS content_date,
|
||||
'movie' AS content_type,
|
||||
m.title,
|
||||
m.description,
|
||||
CONCAT('https://coryd.dev', m.url) AS url,
|
||||
m.image,
|
||||
m.rating,
|
||||
m.tags,
|
||||
CASE
|
||||
WHEN m.last_watched IS NOT NULL THEN json_build_object(
|
||||
'title', m.title,
|
||||
'url', CONCAT('https://coryd.dev', m.url),
|
||||
'description', m.description,
|
||||
'image', m.image,
|
||||
'rating', m.rating,
|
||||
'date', m.last_watched
|
||||
)
|
||||
ELSE NULL
|
||||
END AS feed
|
||||
FROM optimized_movies m
|
||||
)
|
||||
|
||||
SELECT json_agg(feed_data.* ORDER BY feed_data.content_date DESC) AS feed
|
||||
FROM feed_data;
|
Reference in a new issue