sql.join() for building dynamic queries
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
postgres.js gives us parameterized tagged templates and the ability to nest sql partials, and this is fantastic, but I think it is missing a piece of the puzzle:
I want to be able concat partials together (that may contain query parameters), usually with some delimiter (eg whitespace, or a comma, or maybe an sql operator)
something like:
sql.join = (a: PendingQuery[] | Helper[], p: PendingQuery): PendingQuery {...}
would be amazing if this were a first-class feature in postgres.js
this should allow things like
let dynamicFilters = [
sql`somecol = ${somevalue}`,
sql`col2 = ${v2}`
];
const dynamicColumns = [sql('somecol'), sql('col2')]
await sql`
select ${sql.join(dynamicColumns, sql`, `)} from t
where ${sql.join(dynamicFilters, sql` and `)};
`;
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named in the issue. Start by tracing how postgres.js handles tagged templates, nested SQL partials, and parameter collection; then define the join behavior from the dynamic columns and filters examples, including delimiters and parameterized parts, and add coverage for those cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, postgresql
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100