High performance database connection pool for Clojure
Java Clojure Ruby Shell
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
scripts
src
test
.gitignore
README.md
Rakefile
project.clj

README.md

Database Connection pool for Clojure

A jdbc connection pool written from scratch, using ThreadLocals, per Thread per connection. Works very good with http-kit server's thread pool model

Current semantic version: [http-kit/dbcp "0.1.0"].

wait, Is the API blocking (sync)? blocking = slow

Of course blocking! Blocking API is much much easier to use.

blocking = slow?

If you only have one thread, that's may be the case, you can do nothing but waiting for server if blocking. For Clojure, not the case, Clojure has multithreading, you can accept incoming request and wait for MySQL at the same time!

A SQL query can run more than 10s

It's time to double check your data and SQL statement. Non-blocking does not save you!

Feature

  • Clean and compact code: jar size is about ~11k
  • Fast, very fast.
  • The connection get atomatically closed when thread died.
  • Reconnect if closed

Usage

(:require [org.httpkit.dbcp :as db])

(db/use-database! "jdbc:mysql://localhost/test" "user" "password")

;; insert value
(db/insert-record :your_table {:column1 "value1"
                               :column2 "value2"
                               :column3 2})
=> {:generated_key 1} ;; mysql

;; update
(db/update-values :your_table ["column1 = ?" "value1"]
                  {:column1 "new-value"
                   :column3 1000})

;;query
(db/query "select * from your_table where column1 = ?" "value1")
=> ({:id 1 :column1 "new-value" :column2 "vlaue2" :column3 1000})

;; delete
(db/delete-rows :your_table ["column1 = ?" "value1"])

(db/close-database!)

Contact

Please use the GitHub issues page for feature suggestions, bug reports, or general discussions.

License

Copyright © 2012 Feng Shen. Distributed under the Apache License Version 2.0.