Constant backend::model::entity::timeline::CALCULATE_TIMELINE_QUERY

source ยท
const CALCULATE_TIMELINE_QUERY: &str = "WITH t1 AS (\n    SELECT\n        p.add_date,\n        count(*)::integer AS additions\n    FROM\n        plantings AS p\n    INNER JOIN\n        layers AS l\n        ON p.layer_id = l.id\n    WHERE\n        l.map_id = $1\n        AND p.add_date BETWEEN $2 AND $3\n    GROUP BY\n        p.add_date\n),\n\nt2 AS (\n    SELECT\n        p.remove_date,\n        count(*)::integer AS removals\n    FROM\n        plantings AS p\n    INNER JOIN\n        layers AS l\n        ON p.layer_id = l.id\n    WHERE\n        l.map_id = $1\n        AND p.remove_date BETWEEN $2 AND $3\n    GROUP BY\n        p.remove_date\n)\n\nSELECT\n    coalesce(t1.add_date, t2.remove_date) AS \"date\",\n    coalesce(t1.additions, 0) AS additions,\n    coalesce(t2.removals, 0) AS removals\nFROM\n    t1\nFULL OUTER JOIN\n    t2\n    ON t1.add_date = t2.remove_date;\n";
Expand description

Query that calculates the timeline