hugsql

2020-01-24T09:24:05.001600Z

Hi there πŸ™‚ is there a way to get the connection used to execute a query on hugsql.core/hugsql-result-fn ? i want to inject new data on the results after loaded, but i need to use the same db conenction (and don’t want to relay on a global connection)

curtis.summers 2020-01-24T13:05:26.007800Z

@jmayaalv Hi. The hugsql-result-fn multimethod doesn't have access to the db connection, but the hugsql-command-fn does, as it calls either execute or query on the hugsql adapter. So, you could feasibly implement a custom hugsql-command-fn and then use the :raw (default) result. However, depending on what you're doing, since your user code calling a hugsql function already has access to the database connection, you might consider just wrapping the hugsql function in your own code that handles the additions you're wanting to make.

2020-01-24T13:43:17.008400Z

thanks a lot @curtis.summers this sounds exactly like what i need πŸ™‚

seancorfield 2020-01-24T17:40:03.010400Z

@jmayaalv I'd recommend using a connection pool as the thing you pass around, rather than having the JDBC lib create entire new connections on demand. next.jdbc has built in support for c3p0 and HikariCP. clojure.java.jdbc accepts a {:connection pooled-datasource} db-spec, where the pooled-datasource is built from c3p0 or HikariCP