[clojure.jdbc/clojure.jdbc-hikari "0.3.3"]
Fast, simple, reliable. HikariCP is a "zero-overhead" production ready JDBC connection pool implementation for clojure.jdbc.
More info on: https://github.com/brettwooldridge/HikariCP
Leiningen
[clojure.jdbc/clojure.jdbc-hikari "0.3.3"]
Gradle
compile "clojure.jdbc:clojure.jdbc-hikari:0.3.3"
Maven
<dependency>
<groupId>clojure.jdbc</groupId>
<artifactId>clojure.jdbc-hikari</artifactId>
<version>0.3.3</version>
</dependency>
only targets to java8. If you want use the java6-7 version of hikari-cp, you should setup all the dependencies manually. |
In order to use a connection pool, you should convert your plain dbspec into a datasource-dbspec using the helper function provided in each extension.
;; Import the desired implementation
(require '[jdbc.pool.dbcp :as pool])
;; Convert the standard dbspec to an other dbspec with `:datasource` key
(def dbspec (pool/make-datasource-spec {:database-name "test"
:adapter :postgresql}))
HikariCP comes with "good" defaults that should work in majority standard environments, but obviously, it exposes set of options for customize it:
Option | Description |
---|---|
| This property controls the default auto-commit behavior of connections returned from the pool. It is a boolean value. (default |
| This property controls whether Connections obtained from the pool are in read-only mode by default. (default `false) |
| This property controls the maximum number of milliseconds that a client will wait for a connection from the pool. If this time is exceeded without a connection becoming available, a SQLException will be thrown. 100ms is the minimum value. (default |
| This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit idle in the pool. (default |
| This property controls the maximum lifetime of a connection in the pool. A value of 0 indicates no maximum lifetime (infinite lifetime). (default |
| This property controls the minimum number of idle connections that HikariCP tries to maintain in the pool. (default |
| This property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections. Basically this value will determine the maximum number of actual connections to the database backend. (default |
| This property sets the database adapter. Please check Adapters and corresponding datasource class names for the full list of supported adapters and their datasource class names. (this parameter is mandatory) |
| This property sets the default authentication username used when obtaining Connections from the underlying driver. (default |
| This property sets the default authentication password used when obtaining Connections from the underlying driver. (default |
HikariCP, unlike other datasource implementations, requires to setup explicitly that adapter should be used. This is a list of supported adapters:
Adapter | Datasource class name |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(def dbspec
(-> {:adapter :h2
:url "jdbc:h2:/tmp/test"}
(pool/make-datasource-spec)))
;; Convert the standard dbspec to an other dbspec with `:datasource` key
(def dbspec
(-> {:database-name "test"
:username "foo"
:password "secret"
:server-name "localhost"
:port-number 5432
:adapter :postgresql}
(pool/make-datasource-spec)))
Since clojure.jdbc 0.4.0-beta1, packages like this is not the recommended way to setup the connection pool. It provides the basic setup. If you want more controll and access to all options, consider using the dbcp directly as documented in http://niwibe.github.io/clojure.jdbc/latest/#connection-pool
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close