squee.jdbc
connect!
(connect! db f a)
(connect! db f a b)
(connect! db f a b c)
(connect! db f a b c & args)
Helper, equivalent to
(with-connection [conn db-spec]
(f conn .. args)
and in the spirit of update-in/update/swap!, etc.
(connect! "db query select * from foo where x = ?" (params a))
default-rs-fn
(default-rs-fn opts)
do-commands
(do-commands conn & commands)
Runs a set of commands against the database.
execute!
(execute! conn sql)
(execute! conn sql params)
(execute! conn sql params opts)
Execute an SQL query against a Connection or open transaction.
params is a function that parameterizes the query, like #'params
Examples:
(query conn "select * from bar")
(query conn "select * from foo where x = ? and y = ? " (params 4 5))
Supports all opts that #'query supports
Additionally `:return-keys? true` will return database-generated keys.
execute-against-connection*
(execute-against-connection* conn create-jdbc-statement parameterize! realize!)
Low-level.
conn java.sql.Connection
create-jdbc-statement function of a Connection -> Statement or PreparedStatement
parameterize! side-effecting function of a PreparedStatement.
realize! fn of a PreparedStatement whose return value is returned.
insert-sql
(insert-sql table & cols)
many
macro
(many params)
Returns a params function that parameterizes an SQL statement *multiple* times.
Takes a collection of collections.
params
(params & xs)
Returns a params function that parameterizes an SQL statement *once*.
Takes multiple arguments
query
(query conn sql)
(query conn sql params)
(query conn sql params opts)
Execute an SQL query against a Connection or open transaction.
params is a function that parameterizes the query, like #'params
Examples:
(query conn "select * from bar")
(query conn "select * from foo where x = ? and y = ? " (params 4 5))
opts supported:
:result-type :forward-only | :scroll-insensitive | :scroll-sensitive
:concurrency :read-only | :updatable
:cursors
:fetch-size n
:max-rows n
:timeout n
:create-statement! Providing this function (of a Connection) will override the above arguments
:result-set-fn By default, this turns the ResultSet into a vector of maps.
Described in #'reducible-result-set:
:row-strategy
:name-keys
reducible-result-set
(reducible-result-set rs opts)
Low-level. Takes a result set and an option map, returns a
reducible collection (clojure.lang.IReduceInit) on the result-set.
opts supported:
:row-strategy something that extends RowGenerator. The
default RowGenerator turns rows into maps.
:name-keys a function that takes one arg, a collection keys,
and somehow transforms them. The default one
dedups, lower-cases, and keywordizes them.
transactionally
macro
(transactionally conn & body)
Takes a Connection (or open transaction) and performs its
body within a transaction. Arbitrarily nestable, but
if an inner transaction rolls back on uncaught exception,
the outermost will rollback as well.
Takes an *optional* opts map between the connection and the body,
which supports :isolation and :read-only? options.
Isolation levels:
:none :read-committed :read-uncommitted :repeatable-read :serializable
Example usage:
(transactionally conn
(execute! conn ...)
(query conn ...)
(execute! conn ...))
with-connection
macro
(with-connection binding & body)
Macro that opens a connection from the provided spec, which must be
one of the extenders of IDataSource.
(with-connection [conn some-IDataSource])
.... body)