Back
->pool (clj)
(source)function
(->pool clazz db-spec)
Given a (connection pooled datasource) class and a database spec, return a
connection pool object built from that class and the database spec.
Assumes the `clazz` has a `.setJdbcUrl` method (which HikariCP and c3p0 do).
If you already have a JDBC URL and want to use this method, pass `:jdbcUrl`
in the database spec (instead of `:dbtype`, `:dbname`, etc).
Properties for the connection pool object can be passed as mixed case
keywords that correspond to setter methods (just as `:jdbcUrl` maps to
`.setJdbcUrl`). `clojure.java.data/to-java` is used to construct the
object and call the setters.
If you need to pass in connection URL parameters, it can be easier to use
`next.jdbc.connection/jdbc-url` to construct URL, e.g.,
(->pool HikariDataSource
{:jdbcUrl (jdbc-url {:dbtype .. :dbname .. :useSSL false})
:username .. :password ..})
Here we pass `:useSSL false` to `jdbc-url` so that it ends up in the
connection string, but pass `:username` and `:password` for the pool itself.
Note that the result is not type-hinted (because there's no common base
class or interface that can be assumed). In particular, connection pooled
datasource objects may need to be closed but they don't necessarily implement
`java.io.Closeable` (HikariCP does, c3p0 does not).