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.

Hey, is there a way to log the generated query?

I tried this but it did not printed out the queries.

export const db = new Kysely<ModelTypeMap>({
  dialect: new PostgresDialect({
    host: "localhost",
    database: "postgres",
    password: "postgres",
    user: "postgres",
    log: (message) => {
      console.info(message);
    },
  }),
});

// Output

/*
checking client timeout
connecting new client
new client connected
pulse queue
no queued requests
[
  {
    id: 2,
    slug: 'a',
    name: 'a',
    last_updated: 2021-11-29T11:51:27.581Z,
    thumbnail_url: 'aa',
    default_source: 'a',
    status: 'ENABLED'
  }
]
remove idle client
*/

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

9reactions
koskimascommented, Dec 11, 2021

@AzSiAz 0.11.3 now supports a custom logger function:

const db = new Kysely<Database>({
  dialect: new PostgresDialect(postgresConfig),
  log(event) {
    if (event.level === 'query') {
      console.log(event.query.sql)
      console.log(event.query.parameters)
    }
  }
})
3reactions
koskimascommented, Nov 30, 2021

There’s currently no built-in way to log queries in Kysely. The parameters the PostgresDialect takes are passed directly to the pg module.

You can get the compiled sql like this for any query:

const sql = db
  .selectFrom('foo')
  .where(...)
  .orderBy(...)
  .selectAll()
  .compile()

console.log(sql)

I’ll add an easier way to debug queries soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

General Query Log - MariaDB Knowledge Base
The general query log is a log of every SQL query received from a client, as well as each client connect and disconnect....
Read more >
MySQL 8.0 Reference Manual :: 5.4.3 The General Query Log
The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect...
Read more >
Sample queries - Logging - Google Cloud
This document provides you with suggested queries to make it easier to find important logs using the Logs Explorer in the Google Cloud...
Read more >
Log queries in Azure Monitor - Microsoft Learn
Azure Monitor Logs is based on Azure Data Explorer, and log queries are written by using the same Kusto Query Language (KQL).
Read more >
Query Logging - the Advantage Developer Zone
Query logging is a powerful tool for uncovering problem queries. It also increases the amount of work that Advantage must perform during queries—significantly ......
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