A refreshed JDBC wrapper, made for Clojure 1.7
tl;dr:
- Ergonomics: consistent argument shapes
- Modernized implementation with cheap reducible result-sets
- Less seq and stack frame allocation compared to clojure.java.jdbc
- Smaller methods, modularized. (e.g. RowGenerator protocol)
Arguments all have the same shape [conn sql params opts]
, and the first two are required.
- conn: a connection or transaction
- sql: a SQL string
- params: a function that manipulates the sql statement, usually filling in templated values.
There are two such built-ins,
params
andmany
. See below - opts: a map of options
(query conn "select * from bar")
(query conn "select * from bar where x = ?" (params 4))
(let [sql "insert into foo (x,y) values (?,?)"]
(execute! conn sql (params 42 40) {:return-keys? true}))
(let [sql "insert into foo (x,y) values (?,?)"]
(execute! conn sql (many [[20 30] [40 50]])))
(transactionally conn
(execute conn ...)
(query conn...)
(execute conn...))
You can set the isolation level like so:
(transactionally conn {:isolation-level :serializable}
...body)
Statement params come in two flavors, one or many, dependending on how many times the entire sql statement is used
(params ...)
(many [ [...] [...] [...] ...]) ;; this can be an lazy or an eduction too
While clojure.java.jdbc uses lazy-seqs and a naive strategy to extract data from a ResultSet,
results from query
in this library implement clojure.lang.IReduceInit, and are very efficient
to realize.
...
Copyright © Ghadi Shayban
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.