async function injuries({where = `TRUE`} = {}) {
return queryRows(`SELECT
COALESCE(a.count, 0) AS incidents,
COALESCE(a.number_of_persons_injured, 0) AS persons_injured,
COALESCE(a.number_of_pedestrian_injured, 0) AS pedestrian_injured,
COALESCE(a.number_of_cyclist_injured, 0) AS cyclist_injured,
COALESCE(a.number_of_motorist_injured, 0) AS motorist_injured,
c.year_month AS year_month
FROM (SELECT GENERATE_SERIES('2011-08-01'::TIMESTAMP, '2020-01-01'::TIMESTAMP, '1 month'::INTERVAL) AS year_month) c
LEFT JOIN (
SELECT
COUNT(*) AS count,
SUM(number_of_persons_injured) AS number_of_persons_injured,
SUM(number_of_pedestrian_injured) AS number_of_pedestrian_injured,
SUM(number_of_cyclist_injured) AS number_of_cyclist_injured,
SUM(number_of_motorist_injured) AS number_of_motorist_injured,
TO_TIMESTAMP(year || '-' || LPAD(month::text, 2, '0'), 'YYYY-MM') AS year_month
FROM crashes_all_prod
WHERE
number_of_persons_injured > 0
AND (${where})
GROUP BY year_month
) a ON (a.year_month = c.year_month)
ORDER BY c.year_month
`)
}