Supporting CTE
Opened this issue · 0 comments
jwoertink commented
I use a lot of these thing, and always have to drop to raw SQL because of it. It would be great if Avram had it built right in
Here's my initial proposal
schedule_query = <<-SQL
SELECT ...
SQL
UserQuery.new.with_cte(:schedules, as: schedule_query)
Or maybe go the route of Avram::Join
with something like Avram::CTE
https://github.com/luckyframework/avram/blob/main/src/avram/join.cr
cte = Avram::CTE.new(:schedules) do |io|
io << "SELECT ... FROM ...."
end
UserQuery.new.with_cte(cte)
I'll have to research a bit more of how many of my raw queries could be converted through this method. I know not all of them, but this could possibly clear up quite a bit.