Skip to content

How to log the SQL query that is built before running it? #932

Answered by natmfat
Blankeos asked this question in Q&A
Discussion options

You must be logged in to vote

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".

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Blankeos
Comment options

Answer selected by Blankeos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants