Problem with unsafe with arguments
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
Hi
I am trying to use sql.unsafe with arguments, but I found one issue
This works fine
const res = await sql.unsafe(`SELECT * from events WHERE id = $1`, ["51"]);
But when I wrap this inside the sql function then arguments are not passed and I get PostgresError "bind message supplies 0 parameters, but prepared statement "lzwten7e2w15" requires 1"
const res = await sql`${sql.unsafe(`SELECT * from events WHERE id = $1`, ["51"])}`;
Am I using this wrong somehow or is it some other kind of issue? I will appreciate your help this
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 sql.unsafe call and the tagged sql template shown in the report, then reproduce the bind-parameter error against PostgreSQL. Trace how arguments are handled when sql.unsafe is nested in sql; done means the wrapped query forwards its parameter and no longer reports zero supplied parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, postgresql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100