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

Query reporting doesn't happen in 20.1.0 #994

Closed cheald closed 4 months ago

cheald commented 4 months ago

Package version

20.1.0

Describe the bug

I'm new to Adonis, and am building an application with Adonis 6.2.2 and Lucid 20.1.0.

I've been trying to get query logging set up per the documentation:

// start/events.ts
emitter.on("db:query", (query) => {
  logger.info(query);
});

However, I can't get events to emit. I dug into the source and found that QueryReporter short-circuits when it decides there's nothing registered to the db:query event. Commenting out this check causes logging to happen as expected.

Naively, I think this is probably an issue with the emitter not reporting hasListeners correctly, but I'm new enough to Adonis that I don't know that I can help track it down much further. It is possible that I'm registering the event incorrectly, but if that's the case, then the documentation could use an update, too.

Reproduction repo

No response

thetutlage commented 4 months ago

Have you have enabled debugging inside the config/database.ts file?

RomainLanz commented 4 months ago

Closing since no answer from issue reporter.

cheald commented 4 months ago

I apologize, I missed the initial response to this thread.

Adding debug: true to my Postgres config appears to have the desired effect. Thank you!

Is that documented somewhere? I didn't see it on either the database or events handling pages.

thetutlage commented 4 months ago

Yup, its mentioned in the Lucid Debugging docs. https://lucid.adonisjs.com/docs/debugging