Liking cljdoc? Tell your friends :D

clojure.java.jdbc

A Clojure interface to SQL databases via JDBC

clojure.java.jdbc provides a simple abstraction for CRUD (create, read, update, delete) operations on a SQL database, along with basic transaction support. Basic DDL operations are also supported (create table, drop table, access to table metadata).

Maps are used to represent records, making it easy to store and retrieve data. Results can be processed using any standard sequence operations.

For most operations, Java's PreparedStatement is used so your SQL and parameters can be represented as simple vectors where the first element is the SQL string, with ? for each parameter, and the remaining elements are the parameter values to be substituted. In general, operations return the number of rows affected, except for a single record insert where any generated keys are returned (as a map).

A Clojure interface to SQL databases via JDBC

clojure.java.jdbc provides a simple abstraction for CRUD (create, read,
update, delete) operations on a SQL database, along with basic transaction
support. Basic DDL operations are also supported (create table, drop table,
access to table metadata).

Maps are used to represent records, making it easy to store and retrieve
data. Results can be processed using any standard sequence operations.

For most operations, Java's PreparedStatement is used so your SQL and
parameters can be represented as simple vectors where the first element
is the SQL string, with ? for each parameter, and the remaining elements
are the parameter values to be substituted. In general, operations return
the number of rows affected, except for a single record insert where any
generated keys are returned (as a map).
raw docstring

as-identifierclj

Given a string, return it as-is. Given a keyword, return it as a string using the current naming strategy.

Given a string, return it as-is.  Given a keyword, return
it as a string using the current naming strategy.
sourceraw docstring

as-keywordclj

Given a string, return it as a keyword using the current naming strategy. Given a keyword, return it as-is.

Given a string, return it as a keyword using the current
naming strategy.  Given a keyword, return it as-is.
sourceraw docstring

as-named-identifierclj

(as-named-identifier naming-strategy x)

Given a naming strategy and a keyword, return the keyword as a string using the entity naming strategy. Given a naming strategy and a string, return the string as-is. The naming strategy should either be a function (the entity naming strategy) or a map containing :entity and/or :keyword keys which provide the entity naming strategy and/or keyword naming strategy respectively.

Given a naming strategy and a keyword, return the keyword as a string using the 
entity naming strategy.
Given a naming strategy and a string, return the string as-is.
The naming strategy should either be a function (the entity naming strategy) or 
a map containing :entity and/or :keyword keys which provide the entity naming
strategy and/or keyword naming strategy respectively.
sourceraw docstring

as-named-keywordclj

(as-named-keyword naming-strategy x)

Given a naming strategy and a string, return the string as a keyword using the keyword naming strategy. Given a naming strategy and a keyword, return the keyword as-is. The naming strategy should either be a function (the entity naming strategy) or a map containing :entity and/or :keyword keys which provide the entity naming strategy and/or keyword naming strategy respectively. Note that providing a single function will cause the default keyword naming strategy to be used!

Given a naming strategy and a string, return the string as a keyword using the 
keyword naming strategy.
Given a naming strategy and a keyword, return the keyword as-is.
The naming strategy should either be a function (the entity naming strategy) or 
a map containing :entity and/or :keyword keys which provide the entity naming
strategy and/or keyword naming strategy respectively.
Note that providing a single function will cause the default keyword naming
strategy to be used!
sourceraw docstring

as-quoted-identifierclj

(as-quoted-identifier q x)

Given a quote pattern - either a single character or a pair of characters in a vector - and a keyword, return the keyword as a string using a simple quoting naming strategy. Given a qote pattern and a string, return the string as-is. (as-quoted-identifier X :name) will return XnameX as a string. (as-quoted-identifier [A B] :name) will return AnameB as a string.

Given a quote pattern - either a single character or a pair of characters in
a vector - and a keyword, return the keyword as a string using a simple
quoting naming strategy.
Given a qote pattern and a string, return the string as-is.
  (as-quoted-identifier X :name) will return XnameX as a string.
  (as-quoted-identifier [A B] :name) will return AnameB as a string.
sourceraw docstring

as-quoted-strclj

(as-quoted-str q x)

Given a quoting pattern - either a single character or a vector pair of characters - and a string, return the quoted string: (as-quoted-str X foo) will return XfooX (as-quoted-str [A B] foo) will return AfooB

Given a quoting pattern - either a single character or a vector pair of
characters - and a string, return the quoted string:
  (as-quoted-str X foo) will return XfooX
  (as-quoted-str [A B] foo) will return AfooB
sourceraw docstring

connectionclj

Returns the current database connection (or throws if there is none)

Returns the current database connection (or throws if
there is none)
sourceraw docstring

create-tableclj

(create-table name & specs)

Creates a table on the open database connection given a table name and specs. Each spec is either a column spec: a vector containing a column name and optionally a type and other constraints, or a table-level constraint: a vector containing words that express the constraint. An optional suffix to the CREATE TABLE DDL describing table attributes may by provided as :table-spec {table-attributes-string}. All words used to describe the table may be supplied as strings or keywords.

Creates a table on the open database connection given a table name and
specs. Each spec is either a column spec: a vector containing a column
name and optionally a type and other constraints, or a table-level
constraint: a vector containing words that express the constraint. An
optional suffix to the CREATE TABLE DDL describing table attributes may
by provided as :table-spec {table-attributes-string}. All words used to
describe the table may be supplied as strings or keywords.
sourceraw docstring

create-table-ddlclj

(create-table-ddl name & specs)

Given a table name and column specs with an optional table-spec return the DDL string for creating a table based on that.

Given a table name and column specs with an optional table-spec
return the DDL string for creating a table based on that.
sourceraw docstring

delete-rowsclj

(delete-rows table where-params)

Deletes rows from a table. where-params is a vector containing a string providing the (optionally parameterized) selection criteria followed by values for any parameters.

Deletes rows from a table. where-params is a vector containing a string
providing the (optionally parameterized) selection criteria followed by
values for any parameters.
sourceraw docstring

do-commandsclj

(do-commands & commands)

Executes SQL commands on the open database connection.

Executes SQL commands on the open database connection.
sourceraw docstring

do-preparedclj

(do-prepared sql & param-groups)

Executes an (optionally parameterized) SQL prepared statement on the open database connection. Each param-group is a seq of values for all of the parameters.

Executes an (optionally parameterized) SQL prepared statement on the
open database connection. Each param-group is a seq of values for all of
the parameters.
sourceraw docstring

drop-tableclj

(drop-table name)

Drops a table on the open database connection given its name, a string or keyword

Drops a table on the open database connection given its name, a string
or keyword
sourceraw docstring

find-connectionclj

Returns the current database connection (or nil if there is none)

Returns the current database connection (or nil if there
is none)
sourceraw docstring

insert-recordclj

(insert-record table record)

Inserts a single record into a table. A record is a map from strings or keywords (identifying columns) to values. Returns a map of the generated keys.

Inserts a single record into a table. A record is a map from strings or
keywords (identifying columns) to values.
Returns a map of the generated keys.
sourceraw docstring

insert-recordsclj

(insert-records table & records)

Inserts records into a table. records are maps from strings or keywords (identifying columns) to values. Inserts the records one at a time. Returns a sequence of maps containing the generated keys for each record.

Inserts records into a table. records are maps from strings or keywords
(identifying columns) to values. Inserts the records one at a time.
Returns a sequence of maps containing the generated keys for each record.
sourceraw docstring

insert-rowsclj

(insert-rows table & rows)

Inserts complete rows into a table. Each row is a vector of values for each of the table's columns in order. If a single row is inserted, returns a map of the generated keys.

Inserts complete rows into a table. Each row is a vector of values for
each of the table's columns in order.
If a single row is inserted, returns a map of the generated keys.
sourceraw docstring

insert-valuesclj

(insert-values table column-names & value-groups)

Inserts rows into a table with values for specified columns only. column-names is a vector of strings or keywords identifying columns. Each value-group is a vector containing a values for each column in order. When inserting complete rows (all columns), consider using insert-rows instead. If a single set of values is inserted, returns a map of the generated keys.

Inserts rows into a table with values for specified columns only.
column-names is a vector of strings or keywords identifying columns. Each
value-group is a vector containing a values for each column in
order. When inserting complete rows (all columns), consider using
insert-rows instead.
If a single set of values is inserted, returns a map of the generated keys.
sourceraw docstring

is-rollback-onlyclj

(is-rollback-only)

Returns true if the outermost transaction will rollback rather than commit when complete

Returns true if the outermost transaction will rollback rather than
commit when complete
sourceraw docstring

(print-sql-exception exception)

Prints the contents of an SQLException to out

Prints the contents of an SQLException to *out*
sourceraw docstring

(print-sql-exception-chain exception)

Prints a chain of SQLExceptions to out

Prints a chain of SQLExceptions to *out*
sourceraw docstring

(print-update-counts exception)

Prints the update counts from a BatchUpdateException to out

Prints the update counts from a BatchUpdateException to *out*
sourceraw docstring

resultset-seqclj

Creates and returns a lazy sequence of structmaps corresponding to the rows in the java.sql.ResultSet rs. Based on clojure.core/resultset-seq but it respects the current naming strategy.

Creates and returns a lazy sequence of structmaps
corresponding to the rows in the java.sql.ResultSet
rs. Based on clojure.core/resultset-seq but it respects
the current naming strategy.
sourceraw docstring

set-rollback-onlyclj

(set-rollback-only)

Marks the outermost transaction such that it will rollback rather than commit when complete

Marks the outermost transaction such that it will rollback rather than
commit when complete
sourceraw docstring

transactioncljmacro

(transaction & body)

Evaluates body as a transaction on the open database connection. Any nested transactions are absorbed into the outermost transaction. By default, all database updates are committed together as a group after evaluating the outermost body, or rolled back on any uncaught exception. If set-rollback-only is called within scope of the outermost transaction, the entire transaction will be rolled back rather than committed when complete.

Evaluates body as a transaction on the open database connection. Any
nested transactions are absorbed into the outermost transaction. By
default, all database updates are committed together as a group after
evaluating the outermost body, or rolled back on any uncaught
exception. If set-rollback-only is called within scope of the outermost
transaction, the entire transaction will be rolled back rather than
committed when complete.
sourceraw docstring

update-or-insert-valuesclj

(update-or-insert-values table where-params record)

Updates values on selected rows in a table, or inserts a new row when no existing row matches the selection criteria. where-params is a vector containing a string providing the (optionally parameterized) selection criteria followed by values for any parameters. record is a map from strings or keywords (identifying columns) to updated values.

Updates values on selected rows in a table, or inserts a new row when no
existing row matches the selection criteria. where-params is a vector
containing a string providing the (optionally parameterized) selection
criteria followed by values for any parameters. record is a map from
strings or keywords (identifying columns) to updated values.
sourceraw docstring

update-valuesclj

(update-values table where-params record)

Updates values on selected rows in a table. where-params is a vector containing a string providing the (optionally parameterized) selection criteria followed by values for any parameters. record is a map from strings or keywords (identifying columns) to updated values.

Updates values on selected rows in a table. where-params is a vector
containing a string providing the (optionally parameterized) selection
criteria followed by values for any parameters. record is a map from
strings or keywords (identifying columns) to updated values.
sourceraw docstring

with-connectioncljmacro

(with-connection db-spec & body)

Evaluates body in the context of a new connection to a database then closes the connection. db-spec is a map containing values for one of the following parameter sets:

Factory: :factory (required) a function of one argument, a map of params (others) (optional) passed to the factory function in a map

DriverManager: :classname (required) a String, the jdbc driver class name :subprotocol (required) a String, the jdbc subprotocol :subname (required) a String, the jdbc subname (others) (optional) passed to the driver as properties.

DataSource: :datasource (required) a javax.sql.DataSource :username (optional) a String :password (optional) a String, required if :username is supplied

JNDI: :name (required) a String or javax.naming.Name :environment (optional) a java.util.Map

Evaluates body in the context of a new connection to a database then
closes the connection. db-spec is a map containing values for one of the
following parameter sets:

Factory:
  :factory     (required) a function of one argument, a map of params
  (others)     (optional) passed to the factory function in a map

DriverManager:
  :classname   (required) a String, the jdbc driver class name
  :subprotocol (required) a String, the jdbc subprotocol
  :subname     (required) a String, the jdbc subname
  (others)     (optional) passed to the driver as properties.

DataSource:
  :datasource  (required) a javax.sql.DataSource
  :username    (optional) a String
  :password    (optional) a String, required if :username is supplied

JNDI:
  :name        (required) a String or javax.naming.Name
  :environment (optional) a java.util.Map
sourceraw docstring

with-naming-strategycljmacro

(with-naming-strategy naming-strategy & body)

Evaluates body in the context of a naming strategy.

Evaluates body in the context of a naming strategy.
sourceraw docstring

with-query-resultscljmacro

(with-query-results results sql-params & body)

Executes a query, then evaluates body with results bound to a seq of the results. sql-params is a vector containing a string providing the (optionally parameterized) SQL query followed by values for any parameters.

Executes a query, then evaluates body with results bound to a seq of the
results. sql-params is a vector containing a string providing
the (optionally parameterized) SQL query followed by values for any
parameters.
sourceraw docstring

with-quoted-identifierscljmacro

(with-quoted-identifiers q & body)

Evaluates body in the context of a simple quoting naming strategy.

Evaluates body in the context of a simple quoting naming strategy.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close