forked from rho_n/hpr_generator
Refactor MySQL database specific SQL
This commit is contained in:
parent
675f8fa9d5
commit
3cc6da57ad
@ -2,57 +2,9 @@
|
|||||||
<!--% PROCESS 'shared-avatar.tpl.html' %-->
|
<!--% PROCESS 'shared-avatar.tpl.html' %-->
|
||||||
<!--% PROCESS 'shared-utils.tpl.html' %-->
|
<!--% PROCESS 'shared-utils.tpl.html' %-->
|
||||||
<!--% PROCESS 'shared-listen-now.tpl.html' %-->
|
<!--% PROCESS 'shared-listen-now.tpl.html' %-->
|
||||||
|
<!--% PROCESS "queries-episode-${constants.database}.tpl.html" %-->
|
||||||
<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
|
<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
|
||||||
<!--% query_episodes = DBI.prepare('
|
<!--% query_episodes = DBI.prepare(query_episode_maxmin)
|
||||||
WITH episode_maxmin AS (
|
|
||||||
SELECT MAX(id) AS \'latest\', MIN(id) AS \'earliest\', ? AS \'id\'
|
|
||||||
FROM eps
|
|
||||||
WHERE eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY)
|
|
||||||
),
|
|
||||||
episode_date AS (
|
|
||||||
SELECT eps.date
|
|
||||||
FROM eps
|
|
||||||
WHERE eps.id = ?
|
|
||||||
),
|
|
||||||
episode_previous AS (
|
|
||||||
SELECT MAX(id) AS \'previous\', ? AS \'id\'
|
|
||||||
FROM eps
|
|
||||||
INNER JOIN episode_date
|
|
||||||
ON eps.date < episode_date.date
|
|
||||||
WHERE eps.id > 1
|
|
||||||
),
|
|
||||||
episode_next AS (
|
|
||||||
SELECT MIN(id) AS \'next\', ? AS \'id\'
|
|
||||||
FROM eps
|
|
||||||
INNER JOIN episode_date
|
|
||||||
ON eps.date > episode_date.date
|
|
||||||
WHERE eps.date < NOW()
|
|
||||||
),
|
|
||||||
comment_tallies AS (
|
|
||||||
SELECT
|
|
||||||
eps_id,
|
|
||||||
COUNT(eps_id) AS eps_tally
|
|
||||||
FROM comments
|
|
||||||
GROUP BY eps_id
|
|
||||||
)
|
|
||||||
SELECT eps.id, eps.date, eps.title, eps.duration,
|
|
||||||
eps.summary, eps.notes, eps.explicit, eps.license,
|
|
||||||
eps.tags, eps.version, eps.downloads, eps.valid,
|
|
||||||
episode_maxmin.latest, episode_maxmin.earliest,
|
|
||||||
episode_previous.previous, episode_next.next,
|
|
||||||
hosts.hostid, hosts.host,
|
|
||||||
miniseries.name AS \'series\', miniseries.id AS \'seriesid\',
|
|
||||||
miniseries.description AS \'series_description\',
|
|
||||||
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
|
|
||||||
INNER JOIN episode_maxmin ON eps.id = episode_maxmin.id
|
|
||||||
INNER JOIN episode_previous ON eps.id = episode_previous.id
|
|
||||||
INNER JOIN episode_next ON eps.id = episode_next.id
|
|
||||||
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
|
|
||||||
WHERE eps.id = ?
|
|
||||||
')
|
|
||||||
%-->
|
%-->
|
||||||
<!--% episode_result = query_episodes.execute(id, id, id, id, id) %-->
|
<!--% episode_result = query_episodes.execute(id, id, id, id, id) %-->
|
||||||
<!--% FOREACH episode IN episode_result %-->
|
<!--% FOREACH episode IN episode_result %-->
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
|
<!--% PROCESS "queries-ids-episode-${constants.database}.tpl.html" %-->
|
||||||
<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
|
<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
|
||||||
<!--% FOREACH episode IN DBI.query(
|
<!--% FOREACH episode IN DBI.query(query_ids_episode) %-->
|
||||||
'select eps.id from eps
|
|
||||||
where eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY) '
|
|
||||||
) %-->
|
|
||||||
,<!--% episode.id %-->
|
,<!--% episode.id %-->
|
||||||
<!--% END %-->
|
<!--% END %-->
|
||||||
|
|
||||||
|
51
templates/queries-episode-mysql.tpl.html
Normal file
51
templates/queries-episode-mysql.tpl.html
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<!--% query_episode_maxmin = '
|
||||||
|
WITH episode_maxmin AS (
|
||||||
|
SELECT MAX(id) AS \'latest\', MIN(id) AS \'earliest\', ? AS \'id\'
|
||||||
|
FROM eps
|
||||||
|
WHERE eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY)
|
||||||
|
),
|
||||||
|
episode_date AS (
|
||||||
|
SELECT eps.date
|
||||||
|
FROM eps
|
||||||
|
WHERE eps.id = ?
|
||||||
|
),
|
||||||
|
episode_previous AS (
|
||||||
|
SELECT MAX(id) AS \'previous\', ? AS \'id\'
|
||||||
|
FROM eps
|
||||||
|
INNER JOIN episode_date
|
||||||
|
ON eps.date < episode_date.date
|
||||||
|
WHERE eps.id > 1
|
||||||
|
),
|
||||||
|
episode_next AS (
|
||||||
|
SELECT MIN(id) AS \'next\', ? AS \'id\'
|
||||||
|
FROM eps
|
||||||
|
INNER JOIN episode_date
|
||||||
|
ON eps.date > episode_date.date
|
||||||
|
WHERE eps.date < NOW()
|
||||||
|
),
|
||||||
|
comment_tallies AS (
|
||||||
|
SELECT
|
||||||
|
eps_id,
|
||||||
|
COUNT(eps_id) AS eps_tally
|
||||||
|
FROM comments
|
||||||
|
GROUP BY eps_id
|
||||||
|
)
|
||||||
|
SELECT eps.id, eps.date, eps.title, eps.duration,
|
||||||
|
eps.summary, eps.notes, eps.explicit, eps.license,
|
||||||
|
eps.tags, eps.version, eps.downloads, eps.valid,
|
||||||
|
episode_maxmin.latest, episode_maxmin.earliest,
|
||||||
|
episode_previous.previous, episode_next.next,
|
||||||
|
hosts.hostid, hosts.host,
|
||||||
|
miniseries.name AS \'series\', miniseries.id AS \'seriesid\',
|
||||||
|
miniseries.description AS \'series_description\',
|
||||||
|
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
|
||||||
|
INNER JOIN episode_maxmin ON eps.id = episode_maxmin.id
|
||||||
|
INNER JOIN episode_previous ON eps.id = episode_previous.id
|
||||||
|
INNER JOIN episode_next ON eps.id = episode_next.id
|
||||||
|
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
|
||||||
|
WHERE eps.id = ?
|
||||||
|
'
|
||||||
|
%-->
|
4
templates/queries-ids-episode-mysql.tpl.html
Normal file
4
templates/queries-ids-episode-mysql.tpl.html
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<!--% query_ids_episode = 'select eps.id from eps
|
||||||
|
where eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY) '
|
||||||
|
%-->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user