Fork me on GitHub
#sql
<
2019-12-20
>
hoynk13:12:06

How do I set a timeout for queries in clojure.java.jdbc (or next/jdbc)?

seancorfield17:12:24

In next.jdbc, since you're dealing with native Java objects (`Connection`, Statement, etc), you can just use Java interop to set the appropriate timeout.

seancorfield17:12:46

There's a :timeout option that applies to prepared statements and regular statements, equivalent to the .setQueryTimeout method on Statement. That does mean you need to prepare the statement first, if you want to .setQueryTimeout on the PreparedStatement object. You can also call .setNetworkTimeout on a Connection object (but that requires you pass an executor as well).

hoynk18:12:20

That solves half of my problem, we are changing from clojure.java.jdbc to next/jdbc 🙂

seancorfield18:12:14

@boccato Cool. I'm working on some enhancements to clojure.java.data right now that will allow me to make it easier for next.jdbc users to set properties on Connection, PreparedStatement, and other objects after construction via options.

seancorfield23:12:35

next.jdbc has some new features on master in case anyone wants to try them out -- next.jdbc.prepare/statement to create a regular java.sql.Statement more easily, which supports all the expected options, and two new options: :connection and :statement which take a hash map of :camelCase property names that should be "set" on any Connection and Statement/`PreparedStatement` objects created:

clj -Sdeps '{:deps {seancorfield/next.jdbc 
                    {:git/url "" 
                     :sha "d2b898d0441ed217d8ae0bf40407d1b2e3f61060"}}}'
This makes it possible to set any options rather than just the ones that are supported directly in next.jdbc (although these generic options will be set via Java reflection since they use java.data under the hood).

seancorfield23:12:46

The "middleware" feature I was talking about a while back is on the back-burner for now. Or perhaps "in the hammock". It may or may not return at some future date (it's still in the test folder tree, if you're curious).