Liking cljdoc? Tell your friends :D

honey.sql.helpers

Helper functions for the built-in clauses in honey.sql.

Helper functions for the built-in clauses in honey.sql.
raw docstring

add-columnclj/s

(add-column & col-elems)

Add a single column to a table (see alter-table).

Accepts any number of SQL elements that describe a column:

(add-column :name [:varchar 32] [:not nil])

Add a single column to a table (see `alter-table`).

Accepts any number of SQL elements that describe
a column:

(add-column :name [:varchar 32] [:not nil])
sourceraw docstring

add-indexclj/s

(add-index & args)

Like add-column, this accepts any number of SQL elements that describe a new index to be added:

(add-index :unique :name-key :first-name :last-name)

Produces: UNIQUE name_key(first_name, last_name)

Like add-column, this accepts any number of SQL
elements that describe a new index to be added:

(add-index :unique :name-key :first-name :last-name)

Produces: UNIQUE name_key(first_name, last_name)
sourceraw docstring

alter-tableclj/s≠

clj
(alter-table table & clauses)
cljs
(alter-table & args)

Alter table takes a SQL entity (the name of the table to modify) and any number of optional SQL clauses to be applied in a single statement.

(alter-table :foo (add-column :id :int nil))

If only the SQL entity is provided, the result needs to be combined with another SQL clause to modify the table.

(-> (alter-table :foo) (add-column :id :int nil))

Alter table takes a SQL entity (the name of the
table to modify) and any number of optional SQL
clauses to be applied in a single statement.

(alter-table :foo (add-column :id :int nil))

If only the SQL entity is provided, the result
needs to be combined with another SQL clause to
modify the table.

(-> (alter-table :foo) (add-column :id :int nil))
sourceraw docstring

columnsclj/s

(columns & cols)

To be used with insert-into to specify the list of column names for the insert operation. Accepts any number of column names:

(-> (insert-into :foo) (columns :a :b :c) (values [[1 2 3] [2 4 6]]))

Produces: INSERT INTO foo (a, b, c) VALUES (?, ?, ?), (?, ?, ?) Parameters: 1 2 3 2 4 6

To be used with `insert-into` to specify the list of
column names for the insert operation. Accepts any number
of column names:

(-> (insert-into :foo)
    (columns :a :b :c)
    (values [[1 2 3] [2 4 6]]))

Produces:
  INSERT INTO foo (a, b, c) VALUES (?, ?, ?), (?, ?, ?)
Parameters: 1 2 3 2 4 6
sourceraw docstring

compositeclj/s

(composite & args)

Accepts any number of SQL expressions and produces a composite value from them:

(composite :a 42)

Produces: (a, ?) Parameters: 42

Accepts any number of SQL expressions and produces
a composite value from them:

(composite :a 42)

Produces: (a, ?)
Parameters: 42
sourceraw docstring

create-extensionclj/s≠

clj
(create-extension extension)
(create-extension extension if-not-exists)
cljs
(create-extension & args)

Accepts an extension name to create and optionally a flag to trigger IF NOT EXISTS in the SQL:

(create-extension :postgis) (create-extension :postgis :if-not-exists)

That second argument can be truthy value but using that keyword is recommended for clarity.

Accepts an extension name to create and optionally a
flag to trigger IF NOT EXISTS in the SQL:

(create-extension :postgis)
(create-extension :postgis :if-not-exists)

That second argument can be truthy value but using
that keyword is recommended for clarity.
sourceraw docstring

create-tableclj/s≠

clj
(create-table table)
(create-table table if-not-exists)
cljs
(create-table & args)

Accepts a table name to create and optionally a flag to trigger IF NOT EXISTS in the SQL:

(create-table :foo) (create-table :foo :if-not-exists)

That second argument can be truthy value but using that keyword is recommended for clarity.

Accepts a table name to create and optionally a
flag to trigger IF NOT EXISTS in the SQL:

(create-table :foo)
(create-table :foo :if-not-exists)

That second argument can be truthy value but using
that keyword is recommended for clarity.
sourceraw docstring

create-viewclj/s

(create-view & args)

Accepts a single view name to create.

(-> (create-view :cities) (select :*) (from :city))

Accepts a single view name to create.

(-> (create-view :cities)
    (select :*) (from :city))
sourceraw docstring

cross-joinclj/s

(cross-join & args)
source

deleteclj/s≠

clj
(delete table-coll)
cljs
(delete & args)

For deleting from multiple tables. Accepts a collection of table names to delete from.

(-> (delete [:films :directors]) (where [:= :id 1]))

For deleting from multiple tables.
Accepts a collection of table names to delete from.

(-> (delete [:films :directors]) (where [:= :id 1]))
sourceraw docstring

delete-fromclj/s≠

clj
(delete-from table)
cljs
(delete-from & args)

For deleting from a single table. Accepts a single table name to delete from.

(-> (delete-from :films) (where [:= :id 1]))

For deleting from a single table.
Accepts a single table name to delete from.

(-> (delete-from :films) (where [:= :id 1]))
sourceraw docstring

do-nothingclj/s≠

clj
(do-nothing)
cljs
(do-nothing & args)

Called with no arguments, produces DO NOTHING

Called with no arguments, produces DO NOTHING
sourceraw docstring

do-update-setclj/s

(do-update-set & args)
source

drop-columnclj/s≠

clj
(drop-column col)
cljs
(drop-column & args)

Takes a single column name (use with alter-table).

(alter-table :foo (drop-column :bar))

Takes a single column name (use with `alter-table`).

(alter-table :foo (drop-column :bar))
sourceraw docstring

drop-extensionclj/s

(drop-extension & extensions)

Accepts one or more extension names to drop.

Accepts one or more extension names to drop.
sourceraw docstring

drop-indexclj/s

(drop-index & args)

Like drop-table, accepts a single index name:

(drop-index :name-key)

Like drop-table, accepts a single index name:

(drop-index :name-key)
sourceraw docstring

drop-tableclj/s

(drop-table & tables)

Accepts one or more table names to drop.

(drop-table :foo)

Accepts one or more table names to drop.

(drop-table :foo)
sourceraw docstring

exceptclj/s

(except & clauses)

Accepts any number of SQL clauses (queries) on which to perform a set except.

Accepts any number of SQL clauses (queries) on
which to perform a set except.
sourceraw docstring

except-allclj/s

(except-all & clauses)

Accepts any number of SQL clauses (queries) on which to perform a set except all.

Accepts any number of SQL clauses (queries) on
which to perform a set except all.
sourceraw docstring

forclj/s

(for & args)
source

fromclj/s

(from & tables)

Accepts one or more table names, or table/alias pairs.

(-> (select :*) (from [:foo :bar]))

Produces: SELECT * FROM foo AS bar

Accepts one or more table names, or table/alias pairs.

(-> (select :*)
    (from [:foo :bar]))

Produces: SELECT * FROM foo AS bar
sourceraw docstring

full-joinclj/s

(full-join & args)
source

group-byclj/s

(group-by & args)
source

havingclj/s

(having & exprs)

Like where, accepts one or more SQL expressions (conditions) and combines them with AND:

(having [:> :count 0] [:<> :name nil])

Produces: HAVING (count > ?) AND (name IS NOT NULL) Parameters: 0

Like `where`, accepts one or more SQL expressions
(conditions) and combines them with AND:

(having [:> :count 0] [:<> :name nil])

Produces: HAVING (count > ?) AND (name IS NOT NULL)
Parameters: 0
sourceraw docstring

inner-joinclj/s

(inner-join & args)
source

insert-intoclj/s≠

clj
(insert-into table)
(insert-into table cols)
(insert-into table statement)
(insert-into table cols statement)
cljs
(insert-into & args)

Accepts a table name or a table/alias pair. That can optionally be followed by a collection of column names. That can optionally be followed by a (select) statement clause.

(insert-into :table) (insert-into [:table :t]) (insert-into :table [:id :name :cost]) (insert-into :table (-> (select :) (from :other))) (insert-into [:table :t] [:id :name :cost] (-> (select :) (from :other)))

Accepts a table name or a table/alias pair. That
can optionally be followed by a collection of
column names. That can optionally be followed by
a (select) statement clause.

(insert-into :table)
(insert-into [:table :t])
(insert-into :table [:id :name :cost])
(insert-into :table (-> (select :*) (from :other)))
(insert-into [:table :t]
             [:id :name :cost]
             (-> (select :*) (from :other)))
sourceraw docstring

intersectclj/s

(intersect & clauses)

Accepts any number of SQL clauses (queries) on which to perform a set intersection.

Accepts any number of SQL clauses (queries) on
which to perform a set intersection.
sourceraw docstring

joinclj/s

(join & args)
source

left-joinclj/s

(left-join & args)
source

limitclj/s≠

clj
(limit limit)
cljs
(limit & args)

Specific to MySQL, accepts a single SQL expression:

(limit 40)

Produces: LIMIT ? Parameters: 40

Specific to MySQL, accepts a single SQL expression:

(limit 40)

Produces: LIMIT ?
Parameters: 40
sourceraw docstring

modify-columnclj/s

(modify-column & col-elems)

Like add-column, accepts any number of SQL elements that describe the new column definition:

(modify-column :name [:varchar 64] [:not nil])

Like add-column, accepts any number of SQL elements
that describe the new column definition:

(modify-column :name [:varchar 64] [:not nil])
sourceraw docstring

nestclj/s

(nest & args)
source

offsetclj/s≠

clj
(offset offset)
cljs
(offset & args)

Specific to MySQL, accepts a single SQL expression:

(offset 10)

Produces: OFFSET ? Parameters: 10

Specific to MySQL, accepts a single SQL expression:

(offset 10)

Produces: OFFSET ?
Parameters: 10
sourceraw docstring

on-conflictclj/s

(on-conflict & args)
source

on-constraintclj/s≠

clj
(on-constraint constraint)
cljs
(on-constraint & args)

Accepts a single constraint name.

Accepts a single constraint name.
sourceraw docstring

order-byclj/s

(order-by & args)
source

outer-joinclj/s

(outer-join & args)
source

overclj/s

(over & args)

Accepts any number of OVER clauses, each of which is a pair of an aggregate function and a window function or a triple of an aggregate function, a window function, and an alias:

(select :id (over [[:avg :salary] (partition-by :department)]))

Produces: SELECT id, AVG(salary) OVER ()PARTITION BY department)

Accepts any number of OVER clauses, each of which
is a pair of an aggregate function and a window function
or a triple of an aggregate function, a window function,
and an alias:

(select :id (over [[:avg :salary] (partition-by :department)]))

Produces: SELECT id, AVG(salary) OVER ()PARTITION BY department)
sourceraw docstring

partition-byclj/s

(partition-by & args)
source

rename-columnclj/s≠

clj
(rename-column old-col new-col)
cljs
(rename-column & args)

Accepts two column names: the original name and the new name to which it should be renamed:

(rename-column :name :full-name)

Accepts two column names: the original name and the
new name to which it should be renamed:

(rename-column :name :full-name)
sourceraw docstring

rename-tableclj/s

(rename-table & args)

Accepts a single table name and, despite its name, actually means RENAME TO:

(alter-table :foo (rename-table :bar))

Produces: ALTER TABLE foo RENAME TO bar

Accepts a single table name and, despite its name,
actually means RENAME TO:

(alter-table :foo (rename-table :bar))

Produces: ALTER TABLE foo RENAME TO bar
sourceraw docstring

returningclj/s

(returning & cols)

Accepts any number of column names to return from an insert operation:

(returning :*)

Produces: RETURNING *

Accepts any number of column names to return from an
insert operation:

(returning :*)

Produces: RETURNING *
sourceraw docstring

right-joinclj/s

(right-join & args)
source

selectclj/s

(select & exprs)

Accepts any number of column names, or column/alias pairs, or SQL expressions (optionally aliased):

(select :id [:foo :bar] [[:max :quux]])

Produces: SELECT id, foo AS bar, MAX(quux)

The special column name :* produces * for 'all columns'. You can also specify :t.* for 'all columns' from the table (or alias) t.

Accepts any number of column names, or column/alias
pairs, or SQL expressions (optionally aliased):

(select :id [:foo :bar] [[:max :quux]])

Produces: SELECT id, foo AS bar, MAX(quux)

The special column name :* produces * for 'all columns'.
You can also specify :t.* for 'all columns' from the
table (or alias) t.
sourceraw docstring

select-distinctclj/s

(select-distinct & args)

Like select but produces SELECT DISTINCT.

Like `select` but produces SELECT DISTINCT.
sourceraw docstring

select-distinct-onclj/s≠

clj
(select-distinct-on distinct-cols & exprs)
cljs
(select-distinct-on & args)

Accepts a sequence of one or more columns for the distinct clause, followed by any number of column names, or column/alias pairs, or SQL expressions (optionally aliased), as for select:

(select-distinct-on [:a :b] :c [:d :dd])

Produces: SELECT DISTINCT ON(a, b) c, d AS dd

Accepts a sequence of one or more columns for the
distinct clause, followed by any number of column
names, or column/alias pairs, or SQL expressions
(optionally aliased), as for `select`:

(select-distinct-on [:a :b] :c [:d :dd])

Produces: SELECT DISTINCT ON(a, b) c, d AS dd
sourceraw docstring

setclj/s≠

clj
(set col-set-map)
cljs
(set & args)

Accepts a hash map specifying column names and the values to be assigned to them, as part of update:

(-> (update :foo) (set {:a 1 :b nil}))

Produces: UPDATE foo SET a = ?, b = NULL

Accepts a hash map specifying column names and the
values to be assigned to them, as part of `update`:

(-> (update :foo)
    (set {:a 1 :b nil}))

Produces: UPDATE foo SET a = ?, b = NULL
sourceraw docstring

truncateclj/s≠

clj
(truncate table)
cljs
(truncate & args)

Accepts a single table name to truncate.

Accepts a single table name to truncate.
sourceraw docstring

unionclj/s

(union & clauses)

Accepts any number of SQL clauses (queries) on which to perform a set union.

Accepts any number of SQL clauses (queries) on
which to perform a set union.
sourceraw docstring

union-allclj/s

(union-all & clauses)

Accepts any number of SQL clauses (queries) on which to perform a set union all.

Accepts any number of SQL clauses (queries) on
which to perform a set union all.
sourceraw docstring

updateclj/s≠

clj
(update table)
cljs
(update & args)

Accepts either a table name or a table/alias pair.

(-> (update :table) (set {:id 1 :cost 32.1}))

Accepts either a table name or a table/alias pair.

(-> (update :table) (set {:id 1 :cost 32.1}))
sourceraw docstring

upsertclj/s

(upsert clause)
(upsert data clause)

Provided purely to ease migration from nilenso/honeysql-postgres this accepts a single clause, constructed from on-conflict, do-nothing or do-update-set, and where. Any of those are optional.

This helper unpacks that clause and turns it into what HoneySQL 2.x expects, with any where clause being an argument to the do-update-set helper, along with the :fields.

nilenso/honeysql-postgres:

(-> ... (upsert (-> (on-conflict :col) do-nothing))) (-> ... (upsert (-> (on-conflict :col) (do-update-set :x) (where [:<> :x nil]))))

HoneySQL 2.x:

(-> ... (on-conflict :col) do-nothing) (-> ... (on-conflict :col) (do-update-set {:fields [:x] :where [:<> :x nil]}))

Alternative structure for that second one:

(-> ... (on-conflict :col) (do-update-set :x {:where [:<> :x nil]}))

Provided purely to ease migration from nilenso/honeysql-postgres
this accepts a single clause, constructed from on-conflict,
do-nothing or do-update-set, and where. Any of those are optional.

This helper unpacks that clause and turns it into what HoneySQL
2.x expects, with any where clause being an argument to the
do-update-set helper, along with the `:fields`.

nilenso/honeysql-postgres:

(-> ...
    (upsert (-> (on-conflict :col)
                do-nothing)))
(-> ...
    (upsert (-> (on-conflict :col)
                (do-update-set :x)
                (where [:<> :x nil]))))

HoneySQL 2.x:

(-> ...
    (on-conflict :col)
    do-nothing)
(-> ...
    (on-conflict :col)
    (do-update-set {:fields [:x]
                    :where [:<> :x nil]}))

Alternative structure for that second one:

(-> ...
    (on-conflict :col)
    (do-update-set :x {:where [:<> :x nil]}))
sourceraw docstring

usingclj/s

(using & args)
source

valuesclj/s≠

clj
(values row-value-coll)
cljs
(values & args)

Accepts a single argument: a collection of row values. Each row value can be either a sequence of column values or a hash map of column name/column value pairs.

Used with insert-into.

(-> (insert-into :foo) (values [{:id 1, :name "John"} {:id 2, :name "Fred"}]))

Produces: INSERT INTO foo (id, name) VALUES (?, ?), (?, ?) Parameters: 1 "John" 2 "Fred"

Accepts a single argument: a collection of row values.
Each row value can be either a sequence of column values
or a hash map of column name/column value pairs.

Used with `insert-into`.

(-> (insert-into :foo)
    (values [{:id 1, :name "John"}
             {:id 2, :name "Fred"}]))

Produces: INSERT INTO foo (id, name) VALUES (?, ?), (?, ?)
Parameters: 1 "John" 2 "Fred"
sourceraw docstring

whereclj/s

(where & exprs)

Accepts one or more SQL expressions (conditions) and combines them with AND:

(where [:= :status 0] [:<> :task "backup"])

Produces: WHERE (status = ?) AND (task <> ?) Parameters: 0 "backup"

Accepts one or more SQL expressions (conditions) and
combines them with AND:

(where [:= :status 0] [:<> :task "backup"])

Produces: WHERE (status = ?) AND (task <> ?)
Parameters: 0 "backup"
sourceraw docstring

windowclj/s

(window & args)
source

withclj/s

(with & args)
source

with-columnsclj/s≠

clj
(with-columns col-spec-coll)
(with-columns & col-specs)
cljs
(with-columns & args)

Accepts any number of column descriptions. Each column description is a sequence of SQL elements that specify the name and the attributes.

(with-columns [:id :int [:not nil]] [:name [:varchar 32] [:default ""]])

Produces: id INT NOT NULL, name VARCHAR(32) DEFAULT ''

Can also accept a single argument which is a collection of column descriptions (mostly for compatibility with nilenso/honeysql-postgres which used to be needed for DDL).

Accepts any number of column descriptions. Each
column description is a sequence of SQL elements
that specify the name and the attributes.

(with-columns [:id :int [:not nil]]
              [:name [:varchar 32] [:default ""]])

Produces:
  id INT NOT NULL,
  name VARCHAR(32) DEFAULT ''

Can also accept a single argument which is a
collection of column descriptions (mostly for
compatibility with nilenso/honeysql-postgres
which used to be needed for DDL).
sourceraw docstring

with-recursiveclj/s

(with-recursive & args)
source

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

× close