Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node-postgres how to escape parameters?

I know about parameterized query, but since I have to programmatically construct the where condition, taking count of the parameters and building the parameters array is a task much more complex than simply calling an escape function when required. So:

is there a parameters escape function in node-postgres?

like image 287
Daniele Ricci Avatar asked Jul 24 '26 01:07

Daniele Ricci


1 Answers

Yes, since this PR there are client.escapeIdentifier and client.escapeLiteral (sadly still undocumented), and since PR2954 (released with v8.11.0) they are exported and documented as pg.escapeIdentifier and pg.escapeLiteral.

However, it is not recommended to use them when you can use parameterised queries, and for dynamic WHERE condition you can easily construct a query object with text and values on the fly.

like image 130
Bergi Avatar answered Jul 27 '26 10:07

Bergi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!