Fork me on GitHub
#sql
<
2021-10-13
>
Jakub Holý (HolyJak)14:10:43

@seancorfield For next-jdbc and jdbc.connection/->pool , it seems that neither the docstring nor the docs mention how to set properties on the underlying Jdbc driver, right? That is understandable since it will differ for each pool but still an example in the docs would be nice. I currently do this for Hikari:

(jdbc.connection/->pool com.zaxxer.hikari.HikariConfig
                            {:dbtype "postgres" :host "localhost", :port 5432, :username "ardoq", :password "ardoq"
                             :dataSourceProperties
                             (doto (java.util.Properties.)
                               (.putAll {"socketTimeout" "30"}))})
Not sure whether there is a nicer way... (https://ask.clojure.org/index.php/11163/java-data-should-support-creating-properties-from-a-map)

seancorfield14:10:39

Thanks for creating an Ask for that - sounds like a good idea. Could you also create an issue on GH for next.jdbc so I don't forget? (I'm not at my desk yet)

👍 1
dharrigan06:10:54

I don't think you need to use properties, this is what I do:

dharrigan06:10:30

(def ^:private additional-config {:maxLifetime (* 10 60 1000)})

dharrigan06:10:51

(defn connection-pool-start
  ^HikariDataSource [config]
  (connection/->pool HikariDataSource (merge config additional-config)))

dharrigan06:10:04

(I also have, in my config, a poolName k/v pair, which is merged in to)

seancorfield06:10:02

There's a difference between additional configuration for the pool and additional configuration for the underlying datasource/driver.

dharrigan06:10:03

oh yes, right, that's correct. Early morning...

seancorfield06:10:31

No worries. I was confused at first too -- since c3p0 has no such equivalent functionality as far as I can tell...

dharrigan06:10:54

One of my missions (at work) is to replace c3p0 with HikariCP

seancorfield06:10:16

That is likely to become one of my (many) missions too I think...

seancorfield16:10:30

https://github.com/seancorfield/next-jdbc/releases/tag/v1.2.737 updates java.data to 1.0.92 and adds notes to the HikariCP documentation around this. Also improves documentation around :jdbcUrl.

Jakub Holý (HolyJak)18:10:37

@seancorfield the explicit call to j/to-java is unnecessary, this works just fine:

user=> (def p (connection/->pool com.zaxxer.hikari.HikariConfig 
 {:dbtype "postgres" :dbname "db" :username "u" :password "p" :dataSourceProperties {:socketTimeout 30}}))
user=> (-> p .getDataSourceProperties)
{"socketTimeout" "30"}

seancorfield18:10:28

Ah, adding support for Properties is probably what made that possible?

1
seancorfield18:10:51

I'll update the docs when I get a chance. Thanks.

🙏 1