luckyframework / luckyframework/avram

Supporting CTE

Open
#1,005 0 comments 0 reactions 0 assignees View on GitHub
feature request
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

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

```crystal
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

```crystal
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.

Contributor guide

Open the contributing guide

Research direction

Start by reading src/avram/join.cr and comparing the proposed Avram::CTE and with_cte approaches with the raw SQL examples in the issue. Determine which of the reporter's queries could be represented, then define and validate an agreed CTE API that supports those cases without requiring raw SQL.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.