porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.47k stars 273 forks source link

Disable auto console.log Notice Responses #646

Closed LouisLecouturier closed 1 year ago

LouisLecouturier commented 1 year ago

Is there any way to disable logs for notice reponses ?

When I run a Truncate query I get this in the console :

 console.log
      {
        severity_local: 'NOTICE',
        severity: 'NOTICE',
        code: '00000',
        message: 'truncate cascades to table "shops_staff"',
        file: 'tablecmds.c',
        line: '1826',
        routine: 'ExecuteTruncateGuts'
      }

      at NoticeResponse (../../node_modules/.pnpm/postgres@3.3.5/node_modules/postgres/cjs/src/connection.js:875:17)

As it's doing this in a script that clears all the tables of my db, it's pretty annoying because my true log messages are drawn inside of these...

porsager commented 1 year ago

Search for notice in the readme or more specifically onnotice

LouisLecouturier commented 1 year ago

Oh yeah my bad !

Here's what I did to solve it

const queryClient = postgres(connectionString, {
      onnotice: () => {}, // put an empty arrow function,
    });

Thanks for your help !