adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.02k stars 189 forks source link

Debug option does not print all queries #950

Closed romch007 closed 6 months ago

romch007 commented 10 months ago

I have enabled the debug option in my postgresql configuration and added Event.on('db:query', Database.prettyPrint) to events.ts.

When I run this query:

const loggedUser = auth.user!
await loggedUser.load('groups', (group) =>
  group.preload('boxes', (boxes) => {
    boxes
      .withScopes((scopes) => scopes.fetchUnresponsive())
      .preload('sockets', (sockets) =>
        sockets
          .preload('records', (records) => records.orderBy('created_at', 'desc').groupLimit(1))
          .preload('chargeSessions', (chargeSessions) =>
            chargeSessions.whereNull('charge_end').groupLimit(1)
          )
      )
      .preload('records', (records) => records.groupLimit(1))
      .orderBy('id')
  })
)

the only output I get is:

"pg" User (1.67 ms) SELECT * FROM "users" WHERE "id" = ? LIMIT ? [ 2, 1 ]

However, when I manually add the debug option to the query (group.preload(...).debug(true)), I get the full query.

Package version

8.2.3

Node.js and npm version

v20.5.0 and 9.8.0

Sample Code (to reproduce the issue)

BONUS (a sample repo to reproduce the issue)

thetutlage commented 6 months ago

Fixed in https://github.com/adonisjs/lucid/commit/b44d15ee658d6e673cc7a8c97d1b7e617ad3b504