HoneySQL wrappers and shortcuts.
HoneySQL wrappers and shortcuts.
(delete conn table)
(delete conn table {:as opt :keys [where returning] :or {returning [:*]}})
(execute conn sql-map)
(execute conn sql-map {:as opt :keys [honey]})
Like pg.core/execute
but accepts a HoneySQL map
which gets rendered into SQL vector and split on a query
and parameters.
Arguments:
:honey
key for HoneySQL params.Result:
pg.core/execute
.Like `pg.core/execute` but accepts a HoneySQL map which gets rendered into SQL vector and split on a query and parameters. Arguments: - conn: a Connection object; - sql-map: a map like {:select [:this :that] :from [...]} - opt: PG2 options; pass the `:honey` key for HoneySQL params. Result: - same as `pg.core/execute`.
(find conn table kv)
(find conn
table
kv
{:as opt :keys [fields limit offset order-by] :or {fields [:*]}})
Select rows by a column->value filter, for example:
{:name 'Foo', :active true}
All the kv pairs get concatenated with AND.
The optional arguments are:
Select rows by a column->value filter, for example: {:name 'Foo', :active true} All the kv pairs get concatenated with AND. The optional arguments are: - fields (default is [:*]) - limit - offset - order-by
(find-first conn table kv)
(find-first conn
table
kv
{:as opt :keys [fields offset order-by] :or {fields [:*]}})
Like find
but gets the first row only. Adds the
limit 1 expression to the query. Supports the same
optional arguments.
Like `find` but gets the first row only. Adds the limit 1 expression to the query. Supports the same optional arguments.
(format sql-map)
(format sql-map opt)
Like honey.sql/format but with some Postgres-related overrides.
Namely, it produces a SQL expressions with dollar signs instead
of question marks, e.g. SELECT * FROM USERS WHERE id = $1
.
Like honey.sql/format but with some Postgres-related overrides. Namely, it produces a SQL expressions with dollar signs instead of question marks, e.g. `SELECT * FROM USERS WHERE id = $1`.
(get-by-id conn table id)
(get-by-id conn table id {:as opt :keys [pk fields] :or {pk :id fields [:*]}})
Get a single row by its primary key.
By default, the name of the primary key is :id
which can be overridden by the :pk
parameter.
The optimal :fields
vector specifies which
columns to return, [:*]
by default.
Get a single row by its primary key. By default, the name of the primary key is `:id` which can be overridden by the `:pk` parameter. The optimal `:fields` vector specifies which columns to return, `[:*]` by default.
(get-by-ids conn table ids)
(get-by-ids conn
table
ids
{:as opt :keys [pk fields order-by] :or {pk :id fields [:*]}})
Get multiple rows from a table by their PKs. It's not recommended to pass thousands of PKs at once. Split them by smaller chunks instead.
Like get-by-id
, accepts the PK name, the column names
to return, and order-by clause.
Returns a vector of rows.
Get multiple rows from a table by their PKs. It's not recommended to pass thousands of PKs at once. Split them by smaller chunks instead. Like `get-by-id`, accepts the PK name, the column names to return, and order-by clause. Returns a vector of rows.
(insert conn table kvs)
(insert conn
table
kvs
{:as opt
:keys [returning on-conflict do-update-set do-nothing]
:or {returning [:*]}})
Insert a collection of rows into a table.
The kvs
argument must be a seq of maps.
The optional arguments are:
Other PG2-related options are supported.
The result depends on the returning
clause and PG2 options.
By default, it will be a vector of inserted rows.
Insert a collection of rows into a table. The `kvs` argument must be a seq of maps. The optional arguments are: - returning: a vector of columns to return, default is [:*] - on-conflict, - do-update-set, - do-nothing: Postgres-specific ON CONFLICT ... DO ... expressions. Other PG2-related options are supported. The result depends on the `returning` clause and PG2 options. By default, it will be a vector of inserted rows.
(insert-one conn table kv)
(insert-one conn
table
kv
{:as opt
:keys [returning on-conflict do-update-set do-nothing]
:or {returning [:*]}})
Like insert
but accepts a single row.
Supports the same options. The default result is a single inserted row.
Like `insert` but accepts a single row. Supports the same options. The default result is a single inserted row.
(prepare conn sql-map)
(prepare conn sql-map {:as opt :keys [honey]})
Prepare a statement expressed wit a Honey map. For parameters, use either blank values or raw expressions, for example:
{:select [:*] :from :users :where [:= :id 0]}
or
{:select [:*] :from :users :where [:raw 'id = $1']}
Return an instance of PreparedStatement
class.
Prepare a statement expressed wit a Honey map. For parameters, use either blank values or raw expressions, for example: {:select [:*] :from :users :where [:= :id 0]} or {:select [:*] :from :users :where [:raw 'id = $1']} Return an instance of `PreparedStatement` class.
(queries conn sql-maps)
(queries conn sql-maps {:as opt :keys [honey]})
Like query
but accepts a vector of SQL maps.
Returns a vector of results.
Like `query` but accepts a vector of SQL maps. Returns a vector of results.
(query conn sql-map)
(query conn sql-map {:as opt :keys [honey]})
Like pg.core/query
but accepts a HoneySQL map
which gets rendered into a SQL string.
Arguments:
:honey
key for HoneySQL params.Result:
pg.core/query
.Like `pg.core/query` but accepts a HoneySQL map which gets rendered into a SQL string. Arguments: - conn: a Connection object; - sql-map: a map like {:select [:this :that] :from [...]} - opt: PG2 options; pass the `:honey` key for HoneySQL params. Result: - the same as `pg.core/query`.
(update conn table kv)
(update conn table kv {:as opt :keys [where returning] :or {returning [:*]}})
Update rows in a table. The kv
is a map of field->value.
Note that the value might be not a scalar but something
like [:raw 'now()']
or any other HoneySQL expression.
The optional parametes are:
where
which acts like a filter when updating the rows;returning
which determines what columns to return.Update rows in a table. The `kv` is a map of field->value. Note that the value might be not a scalar but something like `[:raw 'now()']` or any other HoneySQL expression. The optional parametes are: - `where` which acts like a filter when updating the rows; - `returning` which determines what columns to return.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close