A Clojure wrapper to HikariCP - "zero-overhead" production ready JDBC connection pool.
- I'm still learning Clojure and this is my first public project in this language
- Add proper documentation
- Write tests
- Use Prismatic/schema to validate the configuration options
- Handle configuration errors
- (Probably) learn to write more idiomatic Clojure
- Support Heroku's
DATABASE_URL
withdatasource-from-url
I won't be available on-line until 08.09.2014!
Add the following dependency to your project.clj
file:
[hikari-cp "0.2.0"]
(ns hikari-cp.example
(:require [hikari-cp.core :refer :all]
[clojure.java.jdbc :as jdbc]))
(def config {:auto-commit true
:read-only false
:connection-timeout 30000
:idle-timeout 600000
:max-lifetime 1800000
:datasource-class-name "org.postgresql.ds.PGSimpleDataSource"
:minimum-idle 10
:maximum-pool-size 10
:username "username"
:password "password"
:database-name "database"
:server-name "localhost"
:port 5432
})
(def ds-config (datasource-config config))
(def datasource
(datasource-from-config ds-config))
(defn -main [& args]
(jdbc/with-db-connection [conn {:datasource datasource}]
(let [rows (jdbc/query conn "SELECT * FROM table")]
(println rows)))
(close-datasource datasource))
Copyright © 2014 Tomek Wałkuski
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.