Some utility functions that make common operations easier by
providing some syntactic sugar over execute!/execute-one!.
This is intended to provide a minimal level of parity with
clojure.java.jdbc (insert!, insert-multi!, query, find-by-keys,
get-by-id, update!, and delete!).
For anything more complex, use a library like HoneySQL https://github.com/jkk/honeysql to generate SQL + parameters.
The following options are supported:
:table-fn -- specify a function used to convert table names (strings)
to SQL entity names -- see the next.jdbc.quoted namespace for the
most common quoting strategy functions,:column-fn -- specify a function used to convert column names (strings)
to SQL entity names -- see the next.jdbc.quoted namespace for the
most common quoting strategy functions.In addition, find-by-keys supports :order-by to add an ORDER BY
clause to the generated SQL.
Some utility functions that make common operations easier by
providing some syntactic sugar over `execute!`/`execute-one!`.
This is intended to provide a minimal level of parity with
`clojure.java.jdbc` (`insert!`, `insert-multi!`, `query`, `find-by-keys`,
`get-by-id`, `update!`, and `delete!`).
For anything more complex, use a library like HoneySQL
https://github.com/jkk/honeysql to generate SQL + parameters.
The following options are supported:
* `:table-fn` -- specify a function used to convert table names (strings)
to SQL entity names -- see the `next.jdbc.quoted` namespace for the
most common quoting strategy functions,
* `:column-fn` -- specify a function used to convert column names (strings)
to SQL entity names -- see the `next.jdbc.quoted` namespace for the
most common quoting strategy functions.
In addition, `find-by-keys` supports `:order-by` to add an `ORDER BY`
clause to the generated SQL.(delete! connectable table where-params)(delete! connectable table where-params opts)Syntactic sugar over execute-one! to make certain common deletes easier.
Given a connectable object, a table name, and either a hash map of columns and values to search on or a vector of a SQL where clause and parameters, perform a delete on the table.
Syntactic sugar over `execute-one!` to make certain common deletes easier. Given a connectable object, a table name, and either a hash map of columns and values to search on or a vector of a SQL where clause and parameters, perform a delete on the table.
(find-by-keys connectable table key-map)(find-by-keys connectable table key-map opts)Syntactic sugar over execute! to make certain common queries easier.
Given a connectable object, a table name, and either a hash map of columns and values to search on or a vector of a SQL where clause and parameters, returns a vector of hash maps of rows that match.
If the :order-by option is present, add an ORDER BY clause. :order-by
should be a vector of column names or pairs of column name / direction,
which can be :asc or :desc.
Syntactic sugar over `execute!` to make certain common queries easier. Given a connectable object, a table name, and either a hash map of columns and values to search on or a vector of a SQL where clause and parameters, returns a vector of hash maps of rows that match. If the `:order-by` option is present, add an `ORDER BY` clause. `:order-by` should be a vector of column names or pairs of column name / direction, which can be `:asc` or `:desc`.
(get-by-id connectable table pk)(get-by-id connectable table pk opts)(get-by-id connectable table pk pk-name opts)Syntactic sugar over execute-one! to make certain common queries easier.
Given a connectable object, a table name, and a primary key value, returns a hash map of the first row that matches.
By default, the primary key is assumed to be id but that can be overridden
in the five-argument call.
Syntactic sugar over `execute-one!` to make certain common queries easier. Given a connectable object, a table name, and a primary key value, returns a hash map of the first row that matches. By default, the primary key is assumed to be `id` but that can be overridden in the five-argument call.
(insert! connectable table key-map)(insert! connectable table key-map opts)Syntactic sugar over execute-one! to make inserting hash maps easier.
Given a connectable object, a table name, and a data hash map, inserts the data as a single row in the database and attempts to return a map of generated keys.
Syntactic sugar over `execute-one!` to make inserting hash maps easier. Given a connectable object, a table name, and a data hash map, inserts the data as a single row in the database and attempts to return a map of generated keys.
(insert-multi! connectable table cols rows)(insert-multi! connectable table cols rows opts)Syntactic sugar over execute! to make inserting columns/rows easier.
Given a connectable object, a table name, a sequence of column names, and a vector of rows of data (vectors of column values), inserts the data as multiple rows in the database and attempts to return a vector of maps of generated keys.
Note: this expands to a single SQL statement with placeholders for every value being inserted -- for large sets of rows, this may exceed the limits on SQL string size and/or number of parameters for your JDBC driver or your database!
Syntactic sugar over `execute!` to make inserting columns/rows easier. Given a connectable object, a table name, a sequence of column names, and a vector of rows of data (vectors of column values), inserts the data as multiple rows in the database and attempts to return a vector of maps of generated keys. Note: this expands to a single SQL statement with placeholders for every value being inserted -- for large sets of rows, this may exceed the limits on SQL string size and/or number of parameters for your JDBC driver or your database!
(query connectable sql-params)(query connectable sql-params opts)Syntactic sugar over execute! to provide a query alias.
Given a connectable object, and a vector of SQL and its parameters, returns a vector of hash maps of rows that match.
Syntactic sugar over `execute!` to provide a query alias. Given a connectable object, and a vector of SQL and its parameters, returns a vector of hash maps of rows that match.
(update! connectable table key-map where-params)(update! connectable table key-map where-params opts)Syntactic sugar over execute-one! to make certain common updates easier.
Given a connectable object, a table name, a hash map of columns and values to set, and either a hash map of columns and values to search on or a vector of a SQL where clause and parameters, perform an update on the table.
Syntactic sugar over `execute-one!` to make certain common updates easier. Given a connectable object, a table name, a hash map of columns and values to set, and either a hash map of columns and values to search on or a vector of a SQL where clause and parameters, perform an update on the table.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |