next.jdbc

(source)
The public API of the next generation java.jdbc library. The basic building blocks are the `java.sql`/`javax.sql` classes: * `DataSource` -- something to get connections from, * `Connection` -- an active connection to the database, * `PreparedStatement` -- SQL and parameters combined, from a connection, and the following functions and a macro: * `get-datasource` -- given a hash map describing a database or a JDBC connection string, construct a `javax.sql.DataSource` and return it, * `get-connection` -- given a connectable, obtain a new `java.sql.Connection` from it and return that, * `plan` -- given a connectable and SQL + parameters or a statement, return a reducible that, when reduced (with an initial value) will execute the SQL and consume the `ResultSet` produced, * `execute!` -- given a connectable and SQL + parameters or a statement, execute the SQL, consume the `ResultSet` produced, and return a vector of hash maps representing the rows (@1); this can be datafied to allow navigation of foreign keys into other tables (either by convention or via a schema definition), * `execute-one!` -- given a connectable and SQL + parameters or a statement, execute the SQL, consume the first row of the `ResultSet` produced, and return a hash map representing that row; this can be datafied to allow navigation of foreign keys into other tables (either by convention or via a schema definition), * `execute-batch!` -- given a `PreparedStatement` and groups of parameters, execute the statement in batch mode (via `.executeBatch`); given a connectable, a SQL string, and groups of parameters, create a new `PreparedStatement` from the SQL and execute it in batch mode. * `prepare` -- given a `Connection` and SQL + parameters, construct a new `PreparedStatement`; in general this should be used with `with-open`, * `transact` -- the functional implementation of `with-transaction`, * `with-transaction` -- execute a series of SQL operations within a transaction. @1 result sets are built, by default, as vectors of hash maps, containing qualified keywords as column names, but the row builder and result set builder machinery is open and alternatives are provided to produce unqualified keywords as column names, and to produce a vector the column names followed by vectors of column values for each row, and lower-case variants of each. The following options are supported wherever a `Connection` is created: * `:auto-commit` -- either `true` or `false`, * `:read-only` -- either `true` or `false`, * `:connection` -- a hash map of camelCase properties to set, via reflection, on the `Connection` object after it is created. The following options are supported wherever a `Statement` or `PreparedStatement` is created: * `:concurrency` -- `:read-only`, `:updatable`, * `:cursors` -- `:close`, `:hold` * `:fetch-size` -- the fetch size value, * `:max-rows` -- the maximum number of rows to return, * `:result-type` -- `:forward-only`, `:scroll-insensitive`, `:scroll-sensitive`, * `:timeout` -- the query timeout, * `:statement` -- a hash map of camelCase properties to set, via reflection, on the `Statement` or `PreparedStatement` object after it is created. In addition, wherever a `PreparedStatement` is created, you may specify: * `:return-keys` -- either `true` or a vector of key names to return.
Public Variable Short Description
active-tx? (clj) Returns true if `next.jdbc` has a currently active transaction in the current thread, else false.
execute! (clj) General SQL execution function.
execute-batch! (clj) Given a `PreparedStatement` and a vector containing parameter groups, i.e., a vector of vector of parameters, use `.addBatch` to add each group of parameters to the prepared statement (via `set-parameters`) and then call `.executeBatch`.
execute-one! (clj) General SQL execution function that returns just the first row of a result.
get-connection (clj) Given some sort of specification of a database, return a new `Connection`.
get-datasource (clj) Given some sort of specification of a database, return a `DataSource`.
on-connection (clj) Given a connectable object, gets a connection and binds it to `sym`, then executes the `body` in that context.
on-connection+options (clj) Given a connectable object, assumed to be wrapped with options, gets a connection, rewraps it with those options, and binds it to `sym`, then executes the `body` in that context.
plan (clj) General SQL execution function (for working with result sets).
prepare (clj) Given a connection to a database, and a vector containing SQL and any parameters it needs, return a new `PreparedStatement`.
snake-kebab-opts (clj) A hash map of options that will convert Clojure identifiers to snake_case SQL entities (`:table-fn`, `:column-fn`), and will convert SQL entities to qualified kebab-case Clojure identifiers (`:builder-fn`).
transact (clj) Given a transactable object and a function (taking a `Connection`), execute the function over the connection in a transactional manner.
unqualified-snake-kebab-opts (clj) A hash map of options that will convert Clojure identifiers to snake_case SQL entities (`:table-fn`, `:column-fn`), and will convert SQL entities to unqualified kebab-case Clojure identifiers (`:builder-fn`).
with-logging (clj) Given a connectable/transactable object and a sql/params logging function and an optional result logging function that should be used on all operations on that object, return a new wrapper object that can be used in its place.
with-options (clj) Given a connectable/transactable object and a set of (default) options that should be used on all operations on that object, return a new wrapper object that can be used in its place.
with-transaction (clj) Given a transactable object, gets a connection and binds it to `sym`, then executes the `body` in that context, committing any changes if the body completes successfully, otherwise rolling back any changes made.
with-transaction+options (clj) Given a transactable object, assumed to be wrapped with options, gets a connection, rewraps it with those options, and binds it to `sym`, then executes the `body` in that context, committing any changes if the body completes successfully, otherwise rolling back any changes made.