-
Hi, I need to execute some dynamically generated SQL commands, like:
where However, I am getting:
Considering that in theory tagged templates are just syntactic sugar, I am also trying call it with:
but it gives the same error. Is there any way to bypass/disable this check? or call it in a way that does not crash? many thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@arcuri82 You should use Tagged template literals are not simply syntactic sugar, they allow the consuming function to both cache by a static reference to the tagged template literal, and handle the parameters supplied before moving on. This is the specific thing that makes Postgres.js able to call itself safe from SQL injection, and also the reason for the raw string query function being named |
Beta Was this translation helpful? Give feedback.
-
many thanks for the explanation |
Beta Was this translation helpful? Give feedback.
@arcuri82 You should use
sql.unsafe()
for that 😉Tagged template literals are not simply syntactic sugar, they allow the consuming function to both cache by a static reference to the tagged template literal, and handle the parameters supplied before moving on. This is the specific thing that makes Postgres.js able to call itself safe from SQL injection, and also the reason for the raw string query function being named
unsafe
😋