luckyframework / luckyframework/avram

Allow creating QueryBuilder with "from" as result of subselect

Open
#682 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Overview

Right now the "from" is set by the passed in table name in the initializer https://github.com/luckyframework/avram/blob/72ac1d684fb4624defe65495e4854818f1041306/src/avram/query_builder.cr#L18-L19

That's not the only way to specify a from in sql, though.

I would like to update the QueryBuilder to keep track of a from instead of table and remove the setting of table in the initialize.

I believe all that would need to change for existing usage to work is to call .from instead of passing the table name into the initialize in the Queryable here https://github.com/luckyframework/avram/blob/72ac1d684fb4624defe65495e4854818f1041306/src/avram/queryable.cr#L48

I would like to add an overloaded from that takes in a QueryBuilder and an alias which would translate to the SQL from (query_builder statement) as ALIAS

Why?

I would like to see Avram have robust layers. You don't need a full model and queryable for this particular sql query? Fine, just use the QueryBuilder for a bit of a nicer experience. And that would be without sacrificing any usability of the higher level constructs.

Ultimately, I would like to be able to experiment with different higher level patterns and need this lower layer to be more flexible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/avram/query_builder.cr around lines 18-19 and src/avram/queryable.cr around line 48 to trace how the current table name is passed and stored. Review the existing QueryBuilder API and its tests, if present, before changing the initializer or adding the overloaded from behavior. Done means existing Queryable usage still works and a QueryBuilder can use another QueryBuilder as a subselect with an alias.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal, sql
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.