-
Let's say I have a query that looks like
I have some variables replacing those above. How do I log the sql query that is built with this? (Not the result) e.g. SELECT id, name, FROM table WHERE name ilike 'awesome' ORDER BY age ASC |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Same problem. I have broken somewhere parameters that are inserted, but it is impossible to check without executing the query itself. And if it gives an error, it does not contain information about the SQL expression |
Beta Was this translation helpful? Give feedback.
-
I believe you can set debug to true in the config and inspect the query if it throws an error (not sure if there is a way to do this before the query is run): postgres({ debug: true })
// later
try {
await sql`faulty query ${dynamic and stuff}`
} catch(error) {
console.log(error.query)
} you can read more under the documentation, titled "Error handling". |
Beta Was this translation helpful? Give feedback.
I believe you can set debug to true in the config and inspect the query if it throws an error (not sure if there is a way to do this before the query is run):
you can read more under the documentation, titled "Error handling".