Using iteration with dynamic query builder
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
I couldn't find a way to make dynamic query builder to work with iteration - map/reduce does not seem to work nicely. TBH, I didn't spend too much time trying.
Here's an example of how I made it to work:
const
const rows = sql`select 1 from text where TRUE and
${search.text?.length ? sql`and (
${search.text[0] ? sql` (btt.search_text @@ phraseto_tsquery('english', ${search.text[0]}))` : sql``}
${search.text[1] ? sql`OR (btt.search_text @@ phraseto_tsquery('english', ${search.text[1]}))` : sql``}
${search.text[2] ? sql`OR (btt.search_text @@ phraseto_tsquery('english', ${search.text[2]}))` : sql``}
${search.text[3] ? sql`OR (btt.search_text @@ phraseto_tsquery('english', ${search.text[3]}))` : sql``}
${search.text[4] ? sql`OR (btt.search_text @@ phraseto_tsquery('english', ${search.text[4]}))` : sql``}
)` : sql``}
ORDER BY 1
`;
obviously this is horrible.
Any suggestions?
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
The issue names no files or tests; start by reproducing the JavaScript example against PostgreSQL and examining how dynamic query fragments behave when built through iteration, map, or reduce. Define the intended iteration API and add coverage demonstrating that the reported search conditions can be assembled without manually indexing each element.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, postgresql
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100