hpr_generator/templates/queries-index-sqlite.tpl.html

75 lines
1.9 KiB
HTML

<!--% query_next_available_episode = '
WITH next_id AS (
SELECT id, id + 1 AS id_next, date as last_date
FROM eps
WHERE eps.date > date(\'now\')
),
free_slot AS (
SELECT
last_date AS prev_date,
CASE
WHEN strftime(\'%w\',last_date) = \'5\'
THEN \'+3 days\'
ELSE \'+1 days\'
END AS date_offset,
next_id.id_next AS empty_slot
FROM next_id
LEFT JOIN eps ON next_id.id_next = eps.id
WHERE eps.id IS NULL
ORDER BY next_id.id
LIMIT 1
)
SELECT
empty_slot AS next_id,
DATE (prev_date, date_offset) AS next_date,
printf(\'%i\',abs(julianday(DATE (prev_date, date_offset)) - julianday(\'now\') + 1)) AS delta_days
FROM free_slot
'
%-->
<!--% query_latest_episodes = '
WITH comment_tallies AS (
SELECT
eps_id,
COUNT(eps_id) AS eps_tally
FROM comments
GROUP BY eps_id
)
SELECT
eps.id,
eps.explicit,
eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags,
eps.notes,
hosts.local_image,
hosts.hostid,
hosts.host, hosts.email,
miniseries.name AS series, miniseries.id AS seriesid,
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
WHERE eps.date <= date(\'now\')
ORDER BY eps.id + 0 DESC
LIMIT 10
'
%-->
<!--% query_last_5_weeks_episodes = '
SELECT
eps.id,
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
eps.date, eps.license, eps.title, eps.summary,
eps.duration, eps.notes, eps.tags,
hosts.hostid,
hosts.host, hosts.email, hosts.local_image,
miniseries.name AS series, miniseries.id AS seriesid
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
WHERE eps.date <= date(\'now\')
ORDER BY eps.id + 0 DESC
LIMIT 30 OFFSET 10
'
%-->