Lustra::SQL::Query::CTE
Allow usage of Common Table Expressions (CTE) in the query building
Instance methods
cte
List the current CTE of the query. The key is the name of the CTE, while the value is the fragment (string or Sub-select)
with_cte(name, request : CTEAuthorized)
Add a CTE to the query.
Lustra::SQL.select.with_cte("full_year",
"SELECT DATE(date)"
"FROM generate_series(NOW() - INTERVAL '1 year', NOW(), '1 day'::interval) date")
.select("*").from("full_year")
# WITH full_year AS ( SELECT DATE(date) ... ) SELECT * FROM full_year;
with_cte(tuple : NamedTuple)
Add a CTE to the query. Use NamedTuple convention:
Lustra::SQL.select.with_cte(cte: "xxx")
# WITH cte AS xxx SELECT...