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?


Yes, since this PR there are client.escapeIdentifier and client.escapeLiteral (sadly still undocumented). 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.

Answered By – Bergi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More