porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.03k stars 255 forks source link

Is it possible to execute a parameterized query with separate sql and bindings? #898

Closed jacobcons closed 2 weeks ago

jacobcons commented 2 weeks ago

I basically have sql and bindings generated dynamically from a query builder

A toy example:

const sql = 'SELECT * FROM users WHERE id = $1';
const params = [1];

And so I was just wondering if it's possible to execute these dynamically built queries with your library as a parameterized query?

Loving the project overall, thank you so much.

porsager commented 2 weeks ago

You're looking for sql.unsafe ;) https://github.com/porsager/postgres?tab=readme-ov-file#unsafe-raw-string-queries