Fork me on GitHub
#luminus
<
2022-12-15
>
eggsyntax19:12:43

Hi folks! Quick conman question -- I'm using conman & hugsql in my app, and they work beautifully. It would be really nice, when calling a DB query bound with bind-connection to be able to see the actual SQL query sent to the DB (eg for debugging). Anyone aware of a way to do that? Have been looking at the conman docs & I feel like it must be there but I'm somehow missing it.

javahippie20:12:25

Would you like to get the exact statement via a function in the REPL, or would logging be enough?

eggsyntax18:12:19

Logging would be plenty! (Sorry, missed the notification of your response yesterday)

javahippie22:12:26

I’m pretty convinced we had that activated in one of our apps. I have to check (and maybe search in the Git history). Hope I can come back to you soon

eggsyntax17:12:11

Thanks, I really appreciate it!

javahippie10:01:19

So, it took longer than I expected, sorry for that. I am not able to find the code anymore, but I’m pretty sure that we hooked into the JDBC driver for logging.

javahippie10:01:48

How easy it is unfortunately depends on the type of driver

eggsyntax16:01:25

No worries, thanks for checking! That at least gives me a useful lead 🙏

eggsyntax20:08:12

Finally got around to digging into this again. For future reference & in case useful to others -- you can do this at the next.jdbc level (assuming you're using next.jdbc; other adapters may have equivalents). eg here I'm wrapping the conman/connect! call to cause all params to be logged:

(next.jdbc/with-logging
             (conman/connect! {:jdbc-url jdbc-url})
             (fn [op params] (prn "SQL operation " op "::" params)))
You can also pass a second function to log results. https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.2.761/api/next.jdbc?q=logging#with-logging

👍 1