RinnieR
RinnieR

Reputation: 267

How to see Prisma query values

I've just set my local application to log Prisma's queries (log: ['query']), but I need to see what values it is using while I debug my application, which is currently not happening, my queries are being printed like this:

FROM "public"."potato" WHERE "public"."potato"."id" IN ($1) OFFSET $2

I have two questions:

  1. How do I print the values that are replaced by those placeholders?
  2. What is those placeholders being used for and what are they?

Note: Not that it matters or makes a difference, but I'm using postgres.

Upvotes: 4

Views: 9644

Answers (1)

shmuels
shmuels

Reputation: 1393

I think what you're looking for is https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/logging#event-based-logging.

Like this you can get the passed in parameters using the code mentioned in the docs

prisma.$on('query', (e) => {
  console.log('Query: ' + e.query)
  console.log('Params: ' + e.params)
  console.log('Duration: ' + e.duration + 'ms')
})

The placeholders are for parameters. See here https://stackoverflow.com/a/7505842/9530790 for why parameterized queries is beneficial.

Upvotes: 5

Related Questions