Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable dynamic column aliases #995

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

DictyosteliumDiscoideum

Fixes #894.

Updates the parser to enable column aliases (i.e., "AS" statements) when columns are given in a dynamic array).

The syntax uses a nested array with two elements:

let columns = [];

if (view.field === "id") {
  columns.push("companies.id");
}

// ... other fields condition

if (view.field === "createdBy") {
  columns.push(["creator.email", "creatorEmail"]);
}
// columns = ["companies.id", ["creator.email", "creatorEmail"]]
sql`
  select
    ${sql(columns)}
  from
    companies
  join
    users as creator
  on
    companies."createdBy" = creator.id`

Which will produce:

SELECT "companies.id","creator.email" AS "creatorEmail"
FROM companies JOIN users as creator ON 
companies."createdBy" = creator.id

@DictyosteliumDiscoideum
Copy link
Author

I fixed the typo that caused the checks to fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AS in Dynamic Fields Selection Not Working
1 participant