sql

All things SQL and JDBC...
nick 2020-08-10T19:15:26.432900Z

Is there a way to log all SQL requests performed by next.jdbc(and/or hugsql/honeysql)? I really enjoyed that feature in other languages/similar tools, really handy for debugging and spotting actions that generate too many SQL requests.

dharrigan 2020-08-10T19:46:16.434Z

You could, if perhaps you're using postgresql, set the log level directly on the driver

dharrigan 2020-08-10T19:47:31.434900Z

Or, you could simply decorate the function that invokes the next.jdbc function ,i.e., execute-one, with a simple "log/tracef" call

dharrigan 2020-08-10T19:47:35.435100Z

(I do the latter)

seancorfield 2020-08-10T20:09:08.436100Z

@nfedyashev The primary reason that there isn't a way to do that is that everyone's logging needs are different so there's really no "one size fits all" thing the library could do for you.

seancorfield 2020-08-10T20:10:56.437900Z

I had started experimenting with some sort of interceptor approach for next.jdbc that would let you hook into execute! both before and after an operation but it was very hard to provide a clean API that didn't also add overhead for everyone, even if they're not using it.

nick 2020-08-10T20:12:12.439400Z

yep, I'm using postgresql. I may need to google how to do that, not sure yet.

seancorfield 2020-08-10T20:12:14.439600Z

I think, now I have with-options available, I might be able to use a similar approach to do logging -- but it would have the same caveats that with-options has: you need to manually propagate it across transactions and certain other calls (because next.jdbc uses native Java objects for improved performance).

nick 2020-08-10T20:13:25.439900Z

got it. Thank you @seancorfield

seancorfield 2020-08-10T20:17:33.440300Z

You can see some of that experiment in an old version of the tests https://github.com/seancorfield/next-jdbc/blob/eda9c93a1c9077f127e2cf6434b5174635ea073c/test/next/jdbc/middleware_test.clj#L22

👍 1
seancorfield 2020-08-10T20:18:23.440900Z

The next.jdbc.middleware namespace no longer exists (and nor does that test).

seancorfield 2020-08-10T20:18:50.441400Z

But it was ugly/complex to use in that state. I've learned from that 🙂

dharrigan 2020-08-10T20:48:18.441500Z

<https://github.com/pgjdbc/pgjdbc>

dharrigan 2020-08-10T20:48:27.441700Z

loggerLevel and loggerFile

nick 2020-08-10T21:32:39.442Z

Thank you David! 🙏