Fork me on GitHub
#hugsql
<
2020-01-24
>
jmayaalv09:01:05

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.summers13:01:26

@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.

jmayaalv13:01:17

thanks a lot @curtis.summers this sounds exactly like what i need 🙂

seancorfield17:01:03

@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