tomekw/hikari-cp

hook on connection initialization

niquola opened this issue · 17 comments

Hello, is there any way to be hooked when new connection is opened.

I have to do some initialization SQL before all queries, ala SET plv8.init_proc =...

Hello @niquola, I believe you can use :connection-init-sql option.

Anyway, let me know if it works for you, please. Also, the PR to update the README would be great! :)

Should this key be added to datasource-options and passed to (make-datasource opts) ?

Method not found: setConnectionInitSql

Also looks like ignoring: (.addDataSourceProperty ds "connectionInitSQL" "SET plv8.start_proc = 'plv8_init'")

(.setConnectionInitSql config "SET plv8.ustart_proc = 'plv8_init';") does not work too

@niquola Weird: https://github.com/brettwooldridge/HikariCP/search?utf8=%E2%9C%93&q=setConnectionInitSql&type=Code

The solution would be to add custom setting like here:

(.setAutoCommit auto-commit)
(.setReadOnly read-only)
(.setConnectionTimeout connection-timeout)
(.setValidationTimeout validation-timeout)
(.setIdleTimeout idle-timeout)
(.setMaxLifetime max-lifetime)
(.setMinimumIdle minimum-idle)
(.setMaximumPoolSize maximum-pool-size)
(.setDataSourceClassName datasource-class-name))

Would you be so kind to prepare PR for this? :)

I will try

👍 Thanks!

Ah, @niquola please look at #13 :) - got merged, I just need to release it to Clojars

Cool,

The only problem - that i'm doing this by hand - but it does not work :(

Ie (.setConnectionInitSql config "SET plv8.ustart_proc = 'plv8_init';") is called without errors, but SQL statement does not executed.

Who should execute this statement - pool? driver?

Another question: how to set pg specific connection property 'stringtype=unspecified'?

Another question: how to set pg specific connection property 'stringtype=unspecified'?

Would it work for you to set it using the configure option? It would probably something along the lines of:

(make-datasource {:configure (fn [cfg] (.setYourProperty ...))})

@niquola is there any way we can help you? :)

Explicit support for :connection-init-sql has been added in 7fbe6ac and released in 1.6.0. I hope this helps!

jjl commented

It would be nice to have a hook for on connection too. I'm experimenting with postgres notifications and I need a reliable way to set them up. Since they might vary over the course of a program run, fixed sql isn't going to cut it :/

@jjl Sure, if HikariCP supports it it'd be great to have it. Patches are very welcome!