feat: initial view queries
This commit is contained in:
parent
8f44ce9bdd
commit
08e2c2ff3f
23 changed files with 1282 additions and 10 deletions
103
views/feeds/syndication.psql
Normal file
103
views/feeds/syndication.psql
Normal file
|
@ -0,0 +1,103 @@
|
|||
CREATE OR REPLACE VIEW optimized_syndication AS
|
||||
WITH syndication_data AS (
|
||||
SELECT
|
||||
p.date AS content_date,
|
||||
'post' AS content_type,
|
||||
p.title,
|
||||
p.description,
|
||||
CONCAT('https://coryd.dev', p.url) AS url,
|
||||
p.tags,
|
||||
json_build_object(
|
||||
'title', CONCAT('📝 ', p.title, ' ', (
|
||||
SELECT array_to_string(
|
||||
array_agg('#' || initcap(replace(t.name, ' ', ''))), ' '
|
||||
)
|
||||
FROM unnest(p.tags) AS t(name)
|
||||
)),
|
||||
'description', p.description,
|
||||
'url', CONCAT('https://coryd.dev', p.url),
|
||||
'date', p.date
|
||||
) AS syndication
|
||||
FROM optimized_posts p
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
l.date AS content_date,
|
||||
'link' AS content_type,
|
||||
l.title,
|
||||
l.description,
|
||||
l.link AS url,
|
||||
l.tags,
|
||||
json_build_object(
|
||||
'title', CONCAT('🔗 ', l.title,
|
||||
CASE
|
||||
WHEN l.mastodon IS NOT NULL THEN
|
||||
' via @' || split_part(l.mastodon, '@', 2) || '@' || split_part(split_part(l.mastodon, 'https://', 2), '/', 1)
|
||||
ELSE ''
|
||||
END, ' ', (
|
||||
SELECT array_to_string(
|
||||
array_agg('#' || initcap(replace(t.name, ' ', ''))), ' '
|
||||
)
|
||||
FROM unnest(l.tags) AS t(name)
|
||||
)
|
||||
),
|
||||
'description', l.description,
|
||||
'url', l.link,
|
||||
'date', l.date
|
||||
) AS syndication
|
||||
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.tags,
|
||||
CASE
|
||||
WHEN LOWER(b.status) = 'finished' THEN json_build_object(
|
||||
'title', CONCAT('📖 ', b.title, ' ', (
|
||||
SELECT array_to_string(
|
||||
array_agg('#' || initcap(replace(t.name, ' ', ''))), ' '
|
||||
)
|
||||
FROM unnest(b.tags) AS t(name)
|
||||
)),
|
||||
'description', b.description,
|
||||
'url', CONCAT('https://coryd.dev', b.url),
|
||||
'date', b.date_finished
|
||||
)
|
||||
ELSE NULL
|
||||
END AS syndication
|
||||
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.tags,
|
||||
CASE
|
||||
WHEN m.last_watched IS NOT NULL THEN json_build_object(
|
||||
'title', CONCAT('🎥 ', m.title, ' ', (
|
||||
SELECT array_to_string(
|
||||
array_agg('#' || initcap(replace(t.name, ' ', ''))), ' '
|
||||
)
|
||||
FROM unnest(m.tags) AS t(name)
|
||||
)),
|
||||
'description', m.description,
|
||||
'url', CONCAT('https://coryd.dev', m.url),
|
||||
'date', m.last_watched
|
||||
)
|
||||
ELSE NULL
|
||||
END AS syndication
|
||||
FROM optimized_movies m
|
||||
)
|
||||
|
||||
SELECT json_agg(syndication_data.* ORDER BY syndication_data.content_date DESC) AS syndication
|
||||
FROM syndication_data;
|
Reference in a new issue