Issue with dynamically building condition clause
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
I try to build a dynamic query with dynamic filters within a transaction but does not work. It returns 0 results.
Here is my code
let dynamicFilters = [
transactionSql`id=${id}`,
transactionSql`name=${name}`,
];
await transactionSql`
SELECT * FROM table WHERE ${ dynamicFilters.join(' AND ') }
`
I also tried below but does not work either
await transactionSql`
SELECT * FROM table WHERE ${ transactionSql`${ dynamicFilters.join(' AND ') }` }
`
If I replace the expression with the actual sql string it will work
await transactionSql`
SELECT * FROM table WHERE id=${id} AND name=${name} }
`
Any idea why?
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
Start with the transactionSql tagged-template examples in the issue and trace how dynamicFilters is composed and interpolated. No source files or tests are identified in the report, so first locate the tagged-template entry point and existing tests for interpolated SQL fragments; done means the composition behavior is explained and covered by a reproducible test or documented usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, postgresql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100