question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Printing full SQL queries with parameters in debug mode

See original GitHub issue

I am initializing prisma with {debug: true, log: ['info', 'query'],} and this is printing SQL queries without actual parameters, just ? to mask them. Wouldn’t it be useful to print the whole thing?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

17reactions
Isahara86commented, Nov 30, 2021

@incompletude @pantharshit00 approach works for Nestjs as well

import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
  constructor() {
    super({
      log: [
        {
          emit: 'event',
          level: 'query',
        },
      ],
    });
  }

  async onModuleInit(): Promise<void> {
    await this.$connect();
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    this.$on('query', async (e) => {
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore
      console.log(`${e.query} ${e.params}`);
    });
  }

  async enableShutdownHooks(app: INestApplication): Promise<void> {
    this.$on('beforeExit', async () => {
      await app.close();
    });
  }
}
15reactions
pantharshit00commented, Jan 13, 2021

Right now you can use events to log the parameters like so:

const prisma = new PrismaClient({
  log: [
    {
      emit: "event",
      level: "query",
    },
  ],
});

prisma.$on("query", async (e) => {
    console.log(`${e.query} ${e.params}`)
});

We might even close this one considering it is safer to log masked output by default and also provide you a way to customize the output.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Printing full SQL queries with parameters in debug mode #5026
I am initializing prisma with {debug: true, log: ['info', 'query'],} and this is printing SQL queries without actual parameters, just ? to mask ......
Read more >
Print parameterized SQL - MSDN - Microsoft
I want to debug a very complicatedm sql query, ... Anyway is it possible to print it out with FULL(+Parameter values) in .NET?...
Read more >
Printing all arguments to a SQL stored procedure (for SQL ...
Here's a short SQL script I made that can be used to print all the arguments passed to a given stored procedure. It's...
Read more >
How to print a query string with parameter values when using ...
SQL - set to debug to log all SQL DML statements as they are executed; org.hibernate.type - set to trace to log all...
Read more >
how to print a constructed query with it's parameters?
hello friends,. in order to debug my code, i wish to print my query sql. ... with unicode parameters. ... it doesn't presently...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found