Liking cljdoc? Tell your friends :D

honey.sql.helpers

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

All helper functions are inherently variadic.

In general, (helper :foo expr) will produce {:helper [:foo expr]}, with a few exceptions: see the docstring of the helper function for details.

Typical usage is threaded, like this:

  (-> (select :a :b :c)
      (from :table)
      (where [:= :id 42])
      (sql/format))

or conditionally like this:

  (-> (select :a :b :c)
      (from :table)
      (cond->
        id (where [:= :id id]))
      (sql/format))

Therefore all helpers can take an existing DSL expression as their first argument or, if the first argument is not a hash map, an empty DSL is assumed -- an empty hash map. The above is therefore equivalent to:

  (-> {}
      (select :a :b :c)
      (from :table)
      (where [:= :id 42])
      (sql/format))

Some of the helper functions here have :arglists metadata in an attempt to provide better hints for auto-complete in editors but those :arglists always omit the DSL argument to avoid duplicating the various argument lists. When you see an auto-complete suggestion like:

bulk-collect-into [varname] [varname n]

bear in mind that a DSL hash map can always be threaded in so the following (pseudo) arities are also available:

bulk-collect-into [dsl varname] [dsl varname n]

The actual arguments are:

bulk-collect-info [& args]

(as they are for all helper functions).

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

  All helper functions are inherently variadic.

  In general, `(helper :foo expr)` will produce `{:helper [:foo expr]}`,
  with a few exceptions: see the docstring of the helper function for details.

  Typical usage is threaded, like this:

```
  (-> (select :a :b :c)
      (from :table)
      (where [:= :id 42])
      (sql/format))
```

  or conditionally like this:

```
  (-> (select :a :b :c)
      (from :table)
      (cond->
        id (where [:= :id id]))
      (sql/format))
```

  Therefore all helpers can take an existing DSL expression
  as their first argument or, if the first argument is not
  a hash map, an empty DSL is assumed -- an empty hash map.
  The above is therefore equivalent to:

```
  (-> {}
      (select :a :b :c)
      (from :table)
      (where [:= :id 42])
      (sql/format))
```

  Some of the helper functions here have `:arglists` metadata
  in an attempt to provide better hints for auto-complete in
  editors but those `:arglists` _always omit the DSL argument_
  to avoid duplicating the various argument lists. When you
  see an auto-complete suggestion like:

    bulk-collect-into [varname] [varname n]

  bear in mind that a DSL hash map can always be threaded in
  so the following (pseudo) arities are also available:

    bulk-collect-into [dsl varname] [dsl varname n]

  The actual arguments are:

    bulk-collect-info [& args]

  (as they are for all helper functions).
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 & index-elems)

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-columnclj/s

(alter-column & col-elems)

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

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

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

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

alter-tableclj/s

(alter-table table & clauses)

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

bulk-collect-intoclj/s

(bulk-collect-into varname)
(bulk-collect-into varname n)

Accepts a variable name, optionally followed by a limit expression.

Accepts a variable name, optionally followed by a limit
expression.
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

compare-withclj/s

(compare-with & args)

Accepts a time interval such as:

(compare-with 1 :week :ago)

Produces: COMPARE WITH 1 WEEK AGO

Accepts a time interval such as:

(compare-with 1 :week :ago)

Produces: COMPARE WITH 1 WEEK AGO
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

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

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)

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)
sourceraw docstring

create-indexclj/s

(create-index & args)

Accepts an index spexification and a column specification. The column specification consists of table name and one or more columns.

(create-index :name-of-idx [:table :col]) (create-index :name-of-idx [:table :col1 :col2]) (create-index [:unique :name-of-idx] [:table :col])

PostgreSQL also supports :if-not-exists and expressions instead of columns.

(create-index [:name-of-idx :if-not-exists] [:table :%lower.col])

Accepts an index spexification and a column specification. The column
specification consists of table name and one or more columns.

(create-index :name-of-idx [:table :col])
(create-index :name-of-idx [:table :col1 :col2])
(create-index [:unique :name-of-idx] [:table :col])

PostgreSQL also supports :if-not-exists and expressions instead of columns.

(create-index [:name-of-idx :if-not-exists] [:table :%lower.col])
sourceraw docstring

create-materialized-viewclj/s

(create-materialized-view view)

Accepts a single view name to create.

(-> (create-materialized-view :cities) (select :*) (from :city)) (with-data true)

Accepts a single view name to create.

(-> (create-materialized-view :cities)
    (select :*) (from :city))
    (with-data true)
sourceraw docstring

create-or-replace-viewclj/s

(create-or-replace-view view)

Accepts a single view name to create.

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

Accepts a single view name to create.

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

create-tableclj/s

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

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)

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)
sourceraw docstring

create-table-asclj/s

(create-table-as table)
(create-table-as table if-not-exists)

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

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

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

(create-table-as :foo)
(create-table-as :foo :if-not-exists)
sourceraw docstring

create-viewclj/s

(create-view view)

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)

Accepts one or more CROSS JOIN expressions. Each cross join expression is specified as a table name (or a pair of table and alias):

(cross-join :table) (cross-join [:table :t])

Produces: CROSS JOIN table CROSS JOIN table AS t

Accepts one or more CROSS JOIN expressions. Each
cross join expression is specified as a table
name (or a pair of table and alias):

(cross-join :table)
(cross-join [:table :t])

Produces:
CROSS JOIN table
CROSS JOIN table AS t
sourceraw docstring

deleteclj/s

(delete table-coll)

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

(delete-from table)

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

distinctclj/s

(distinct & args)

Like select-distinct but produces DISTINCT...

Like `select-distinct` but produces DISTINCT...
sourceraw docstring

do-nothingclj/s

(do-nothing)

Called with no arguments, produces DO NOTHING

Called with no arguments, produces DO NOTHING
sourceraw docstring

do-update-setclj/s

(do-update-set field-where-map)
(do-update-set column-value-map)
(do-update-set column* opt-where-clause)

Accepts one or more columns to update, or a hash map of column/value pairs (like set), optionally followed by a WHERE clause. Can also accept a single hash map with a :fields entry specifying the columns to update and a :where entry specifying the WHERE clause.

Accepts one or more columns to update, or a hash map
of column/value pairs (like `set`), optionally followed
by a `WHERE` clause. Can also accept a single hash map
with a `:fields` entry specifying the columns to update
and a `:where` entry specifying the `WHERE` clause.
sourceraw docstring

drop-columnclj/s

(drop-column col)

Takes one or more column names (use with alter-table).

Accepts an IF EXISTS flag (keyword or symbol) before any column names.

(alter-table :foo (drop-column :bar :if-exists :quux))

Takes one or more column names (use with `alter-table`).

Accepts an `IF EXISTS` flag (keyword or symbol) before
any column names.

(alter-table :foo (drop-column :bar :if-exists :quux))
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-materialized-viewclj/s

(drop-materialized-view & views)

Accepts one or more materialied view names to drop.

Accepts one or more materialied view names to drop.
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

drop-viewclj/s

(drop-view & views)

Accepts one or more view names to drop.

Accepts one or more view names to drop.
sourceraw docstring

erase-fromclj/s

(erase-from table)

For erasing (hard delete) from a single table (XTDB). Accepts a single table name to erase from.

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

For erasing (hard delete) from a single table (XTDB).
Accepts a single table name to erase from.

(-> (erase-from :films) (where [:= :id 1]))
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

excludeclj/s

(exclude & args)

Accepts one or more column names to exclude from a select list.

Accepts one or more column names to exclude from a select list.
sourceraw docstring

exprclj/s

(expr & args)

Like distinct but produces ... (i.e., just the expression that follows).

Like `distinct` but produces ... (i.e., just the expression that follows).
sourceraw docstring

facetclj/s

(facet & args)

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

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

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

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

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

Produces: FACET id, foo AS bar, MAX(quux)
sourceraw docstring

fetchclj/s

(fetch limit)

Accepts a single SQL expression:

(fetch 10)

Produces: FETCH ? ONLY Parameters: 10

Accepts a single SQL expression:

(fetch 10)

Produces: FETCH ? ONLY
Parameters: 10
sourceraw docstring

filterclj/s

(filter expr1 clause1 & more)

Accepts alternating expressions and clauses and produces a FILTER expression:

(filter :%count.* (where :> i 5))

Produces: COUNT(*) FILTER (WHERE i > ?) Parameters: 5

Accepts alternating expressions and clauses and
produces a FILTER expression:

(filter :%count.* (where :> i 5))

Produces: COUNT(*) FILTER (WHERE i > ?)
Parameters: 5
sourceraw docstring

forclj/s

(for lock-strength table* qualifier*)

Accepts a lock strength, optionally followed by one or more table names, optionally followed by a qualifier.

Accepts a lock strength, optionally followed by one or
more table names, optionally followed by a qualifier.
sourceraw docstring

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)

Accepts one or more FULL JOIN expressions. Each join expression is specified as a pair of arguments, where the first one is the table name (or a pair of table and alias) and the second one is the join condition:

(full-join :table [:= :foo.id :table.foo_id]) (full-join [:table :t] [:= :foo.id :t.foo_id])

Produces: FULL JOIN table ON foo.id = table.foo_id FULL JOIN table AS t ON foo.id = t.foo_id

Accepts one or more FULL JOIN expressions. Each
join expression is specified as a pair of arguments,
where the first one is the table name (or a pair of
table and alias) and the second one is the join
condition:

(full-join :table [:= :foo.id :table.foo_id])
(full-join [:table :t] [:= :foo.id :t.foo_id])

Produces:
FULL JOIN table ON foo.id = table.foo_id
FULL JOIN table AS t ON foo.id = t.foo_id
sourceraw docstring

generic-helper-unaryclj/s

(generic-helper-unary k args)

Clauses that accept only a single item can be implemented using this helper, as:

(defn my-helper [& args] (generic-helper-unary :my-clause args))

Even though your helper is designed for clauses that accept only a single item, you should still define it as variadic, because that is the convention all helpers use here.

Clauses that accept only a single item can be implemented
using this helper, as:

(defn my-helper [& args] (generic-helper-unary :my-clause args))

Even though your helper is designed for clauses that accept
only a single item, you should still define it as variadic,
because that is the convention all helpers use here.
sourceraw docstring

generic-helper-variadicclj/s

(generic-helper-variadic k args)

Most clauses that accept a sequence of items can be implemented using this helper, as:

(defn my-helper [& args] (generic-helper-variadic :my-clause args))

Most clauses that accept a sequence of items can be implemented
using this helper, as:

(defn my-helper [& args] (generic-helper-variadic :my-clause args))
sourceraw docstring

group-byclj/s

(group-by & args)

Accepts one or more SQL expressions to group by.

(group-by :foo :bar) (group-by [:date :baz])

Produces: GROUP BY foo, bar GROUP BY DATE(baz)

Accepts one or more SQL expressions to group by.

(group-by :foo :bar)
(group-by [:date :baz])

Produces:
GROUP BY foo, bar
GROUP BY DATE(baz)
sourceraw docstring

havingclj/s

(having & exprs)

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

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

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

(having :> :count 0)

Produces: HAVING count > ? Parameters: 0

(having :or [:> :count 0] [:= :name ""])

Produces: HAVING (count > ?) OR (name = ?) Parameters: 0 ""

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

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

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

(having :> :count 0)

Produces: HAVING count > ?
Parameters: 0

(having :or [:> :count 0] [:= :name ""])

Produces: HAVING (count > ?) OR (name = ?)
Parameters: 0 ""
sourceraw docstring

inner-joinclj/s

(inner-join & args)

An alternative name to join, this accepts one or more INNER JOIN expressions. Each join expression is specified as a pair of arguments, where the first one is the table name (or a pair of table and alias) and the second one is the join condition:

(inner-join :table [:= :foo.id :table.foo_id]) (inner-join [:table :t] [:= :foo.id :t.foo_id])

Produces: INNER JOIN table ON foo.id = table.foo_id INNER JOIN table AS t ON foo.id = t.foo_id

An alternative name to `join`, this accepts one or
more INNER JOIN expressions. Each join expression
is specified as a pair of arguments, where the
first one is the table name (or a pair of table
and alias) and the second one is the join condition:

(inner-join :table [:= :foo.id :table.foo_id])
(inner-join [:table :t] [:= :foo.id :t.foo_id])

Produces:
INNER JOIN table ON foo.id = table.foo_id
INNER JOIN table AS t ON foo.id = t.foo_id
sourceraw docstring

insert-intoclj/s

(insert-into table)
(insert-into table cols)
(insert-into table statement)
(insert-into table cols statement)

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

intoclj/s

(into table)
(into table dbname)

Accepts table name, optionally followed a database name.

Accepts table name, optionally followed a database name.
sourceraw docstring

joinclj/s

(join & args)

Accepts one or more (INNER) JOIN expressions. Each join expression is specified as a pair of arguments, where the first one is the table name (or a pair of table and alias) and the second one is the join condition:

(join :table [:= :foo.id :table.foo_id]) (join [:table :t] [:= :foo.id :t.foo_id])

Produces: INNER JOIN table ON foo.id = table.foo_id INNER JOIN table AS t ON foo.id = t.foo_id

Accepts one or more (INNER) JOIN expressions. Each
join expression is specified as a pair of arguments,
where the first one is the table name (or a pair of
table and alias) and the second one is the join
condition:

(join :table [:= :foo.id :table.foo_id])
(join [:table :t] [:= :foo.id :t.foo_id])

Produces:
INNER JOIN table ON foo.id = table.foo_id
INNER JOIN table AS t ON foo.id = t.foo_id
sourceraw docstring

join-byclj/s

(join-by & args)

Accepts a sequence of join clauses to be generated in a specific order.

(-> (select :*) (from :foo) (join-by :left [:bar [:= :foo.id :bar.id]] :join [:quux [:= :bar.qid :quux.id]]))

This produces a LEFT JOIN followed by an INNER JOIN even though the 'natural' order for left-join and join would be to generate the INNER JOIN first, followed by the LEFT JOIN.

Accepts a sequence of join clauses to be generated
in a specific order.

(-> (select :*)
    (from :foo)
    (join-by :left [:bar [:= :foo.id :bar.id]]
             :join [:quux [:= :bar.qid :quux.id]]))

This produces a LEFT JOIN followed by an INNER JOIN
even though the 'natural' order for `left-join` and
`join` would be to generate the INNER JOIN first,
followed by the LEFT JOIN.
sourceraw docstring

lateralclj/s

(lateral clause-or-expression)

Accepts a SQL clause or a SQL expression:

(lateral (-> (select '*) (from 'foo))) (lateral '(calc_value bar))

Produces: LATERAL (SELECT * FROM foo) LATERAL CALC_VALUE(bar)

Accepts a SQL clause or a SQL expression:

(lateral (-> (select '*) (from 'foo)))
(lateral '(calc_value bar))

Produces:
LATERAL (SELECT * FROM foo)
LATERAL CALC_VALUE(bar)
sourceraw docstring

left-joinclj/s

(left-join & args)

Accepts one or more LEFT JOIN expressions. Each join expression is specified as a pair of arguments, where the first one is the table name (or a pair of table and alias) and the second one is the join condition:

(left-join :table [:= :foo.id :table.foo_id]) (left-join [:table :t] [:= :foo.id :t.foo_id])

Produces: LEFT JOIN table ON foo.id = table.foo_id LEFT JOIN table AS t ON foo.id = t.foo_id

Accepts one or more LEFT JOIN expressions. Each
join expression is specified as a pair of arguments,
where the first one is the table name (or a pair of
table and alias) and the second one is the join
condition:

(left-join :table [:= :foo.id :table.foo_id])
(left-join [:table :t] [:= :foo.id :t.foo_id])

Produces:
LEFT JOIN table ON foo.id = table.foo_id
LEFT JOIN table AS t ON foo.id = t.foo_id
sourceraw docstring

limitclj/s

(limit limit)

Specific to some databases (notabley MySQL), accepts a single SQL expression:

(limit 40)

Produces: LIMIT ? Parameters: 40

The two-argument syntax is not supported: use offset instead:

LIMIT 20,10 is equivalent to LIMIT 10 OFFSET 20

(-> (limit 10) (offset 20))

Specific to some databases (notabley MySQL),
accepts a single SQL expression:

(limit 40)

Produces: LIMIT ?
Parameters: 40

The two-argument syntax is not supported: use `offset`
instead:

`LIMIT 20,10` is equivalent to `LIMIT 10 OFFSET 20`

(-> (limit 10) (offset 20))
sourceraw docstring

lockclj/s

(lock lock-mode)

Intended for MySQL, this accepts a lock mode.

It will accept the same type of syntax as for even though MySQL's lock clause is less powerful.

Intended for MySQL, this accepts a lock mode.

It will accept the same type of syntax as `for` even
though MySQL's `lock` clause is less powerful.
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])

MySQL-specific, deprecated. Use alter-column and specify the MySQL dialect to get MODIFY COLUMN.

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

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

MySQL-specific, deprecated. Use `alter-column` and
specify the MySQL dialect to get `MODIFY COLUMN`.
sourceraw docstring

offsetclj/s

(offset offset)

Accepts a single SQL expression:

(offset 10)

Produces: OFFSET ? Parameters: 10

Accepts a single SQL expression:

(offset 10)

Produces: OFFSET ?
Parameters: 10
sourceraw docstring

on-conflictclj/s

(on-conflict column* where-clause)

Accepts zero or more SQL entities (keywords or symbols), optionally followed by a single SQL clause ({:where <condition>}). Ex.: (on-conflict :mom :dad {:where [:= :race "human"]}

Accepts zero or more SQL entities (keywords or symbols),
optionally followed by a single SQL clause (`{:where <condition>}`).
Ex.: `(on-conflict :mom :dad {:where [:= :race "human"]}`
sourceraw docstring

on-constraintclj/s

(on-constraint constraint)

Accepts a single constraint name.

Accepts a single constraint name.
sourceraw docstring

on-duplicate-key-updateclj/s

(on-duplicate-key-update column-value-map)

MySQL's upsert facility. Accepts a hash map of column/value pairs to be updated (like set does).

MySQL's upsert facility. Accepts a hash map of
column/value pairs to be updated (like `set` does).
sourceraw docstring

order-byclj/s

(order-by & args)

Accepts one or more expressions to order by.

An ordering expression may be a simple column name which is assumed to be ordered ASC, or a pair of an expression and a direction (:asc or :desc):

(order-by :foo) (order-by [:bar :desc]) (order-by [[:date :baz] :asc])

Produces: ORDER BY foo ASC ORDER BY bar DESC ORDER BY DATE(baz) ASC

Accepts one or more expressions to order by.

An ordering expression may be a simple column name
which is assumed to be ordered `ASC`, or a pair of
an expression and a direction (`:asc` or `:desc`):

(order-by :foo)
(order-by [:bar :desc])
(order-by [[:date :baz] :asc])

Produces:
ORDER BY foo ASC
ORDER BY bar DESC
ORDER BY DATE(baz) ASC
sourceraw docstring

outer-joinclj/s

(outer-join & args)

Accepts one or more OUTER JOIN expressions. Each join expression is specified as a pair of arguments, where the first one is the table name (or a pair of table and alias) and the second one is the join condition:

(outer-join :table [:= :foo.id :table.foo_id]) (outer-join [:table :t] [:= :foo.id :t.foo_id])

Produces: OUTER JOIN table ON foo.id = table.foo_id OUTER JOIN table AS t ON foo.id = t.foo_id

Accepts one or more OUTER JOIN expressions. Each
join expression is specified as a pair of arguments,
where the first one is the table name (or a pair of
table and alias) and the second one is the join
condition:

(outer-join :table [:= :foo.id :table.foo_id])
(outer-join [:table :t] [:= :foo.id :t.foo_id])

Produces:
OUTER JOIN table ON foo.id = table.foo_id
OUTER JOIN table AS t ON foo.id = t.foo_id
sourceraw docstring

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)

Accepts one or more columns or SQL expressions to partition by as part of a WINDOW expression.

Accepts one or more columns or SQL expressions to
partition by as part of a `WINDOW` expression.
sourceraw docstring

patch-intoclj/s

(patch-into table)
(patch-into table cols)
(patch-into table statement)
(patch-into table cols statement)

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.

The arguments are identical to insert-into. The PATCH INTO statement is only supported by XTDB.

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.

The arguments are identical to insert-into.
The PATCH INTO statement is only supported by
XTDB.
sourceraw docstring

recordsclj/s

(records & args)

Produces RECORDS {...}, {...}, ... Like values so it accepts a collection of maps.

Produces RECORDS {...}, {...}, ...
Like `values` so it accepts a collection of maps.
sourceraw docstring

refresh-materialized-viewclj/s

(refresh-materialized-view view)

Accepts a materialied view name to refresh.

Accepts a materialied view name to refresh.
sourceraw docstring

renameclj/s

(rename & args)

Accepts one or more column names with aliases to rename in a select list.

Accepts one or more column names with aliases to rename in a select list.
sourceraw docstring

rename-columnclj/s

(rename-column old-col new-col)

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 new-table)

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

replace-intoclj/s

(replace-into table)
(replace-into table cols)
(replace-into table statement)
(replace-into table cols statement)

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.

The arguments are identical to insert-into. The REPLACE INTO statement is only supported by MySQL and SQLite.

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.

The arguments are identical to insert-into.
The REPLACE INTO statement is only supported by
MySQL and SQLite.
sourceraw docstring

returningclj/s

(returning & cols)

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

(returning :*) and (returning :a :b)

Produce: RETURNING * and RETURNING a, b respectively.

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

(returning :*) and (returning :a :b)

Produce: RETURNING * and RETURNING a, b respectively.
sourceraw docstring

right-joinclj/s

(right-join & args)

Accepts one or more RIGHT JOIN expressions. Each join expression is specified as a pair of arguments, where the first one is the table name (or a pair of table and alias) and the second one is the join condition:

(right-join :table [:= :foo.id :table.foo_id]) (right-join [:table :t] [:= :foo.id :t.foo_id])

Produces: RIGHT JOIN table ON foo.id = table.foo_id RIGHT JOIN table AS t ON foo.id = t.foo_id

Accepts one or more RIGHT JOIN expressions. Each
join expression is specified as a pair of arguments,
where the first one is the table name (or a pair of
table and alias) and the second one is the join
condition:

(right-join :table [:= :foo.id :table.foo_id])
(right-join [:table :t] [:= :foo.id :t.foo_id])

Produces:
RIGHT JOIN table ON foo.id = table.foo_id
RIGHT JOIN table AS t ON foo.id = t.foo_id
sourceraw docstring

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

(select-distinct-on distinct-cols & exprs)

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

select-distinct-topclj/s

(select-distinct-top & args)

Like select-top but produces SELECT DISTINCT TOP...

Like `select-top` but produces SELECT DISTINCT TOP...
sourceraw docstring

select-topclj/s

(select-top & args)

Accepts a TOP expression, followed by any number of column names, or column/alias pairs, or SQL expressions (optionally aliased), as for select. The TOP expression can be a simple numeric expression, or a sequence with a numeric expression followed by keywords (or symbols) for PERCENT and/or WITH TIES.

Accepts a TOP expression, followed by any number of
column names, or column/alias pairs, or SQL expressions
(optionally aliased), as for `select`. The TOP expression
can be a simple numeric expression, or a sequence with
a numeric expression followed by keywords (or symbols)
for PERCENT and/or WITH TIES.
sourceraw docstring

setclj/s

(set col-set-map)

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

settingclj/s

(setting & args)

Accepts one or more time settings for a query.

Accepts one or more time settings for a query.
sourceraw docstring

sinceclj/s

(since & args)

Accepts a time interval such as:

(since 2 :days :ago)

Produces: SINCE 2 DAYS AGO

Accepts a time interval such as:

(since 2 :days :ago)

Produces: SINCE 2 DAYS AGO
sourceraw docstring

tableclj/s

(table name)

Accepts a single table name and produces TABLE name

This is equivalent to: SELECT * FROM name

Accepts a single table name and produces TABLE name

This is equivalent to: SELECT * FROM name
sourceraw docstring

timeseriesclj/s

(timeseries & args)

Accepts a time interval such as:

(timeseries 1 :day)

or:

(timeseries :auto)

Produces: TIMESERIES 1 DAY Or: TIMESERIES AUTO

Accepts a time interval such as:

(timeseries 1 :day)

or:

(timeseries :auto)

Produces: TIMESERIES 1 DAY
Or:       TIMESERIES AUTO
sourceraw docstring

truncateclj/s

(truncate table)

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

untilclj/s

(until & args)

Accepts a time interval such as:

(until 1 :month :ago)

Produces: UNTIL 1 MONTH AGO

Accepts a time interval such as:

(until 1 :month :ago)

Produces: UNTIL 1 MONTH AGO
sourceraw docstring

updateclj/s

(update table)

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)

Accepts similar arguments to select as part of a SQL USING clause.

Accepts similar arguments to `select` as part of
a SQL `USING` clause.
sourceraw docstring

valuesclj/s

(values row-value-coll)

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 (by default):

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

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

For a single expression, the brackets can be omitted:

(where := :status 0) ; same as (where [:= :status 0])

With multiple expressions, the conjunction may be specified as a leading symbol:

(where :or [:= :status 0] [:= :task "stop"])

Produces: WHERE (status = 0) OR (task = ?) Parameters: 0 "stop"

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

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

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

For a single expression, the brackets can be omitted:

(where := :status 0) ; same as (where [:= :status 0])

With multiple expressions, the conjunction may be
specified as a leading symbol:

(where :or [:= :status 0] [:= :task "stop"])

Produces: WHERE (status = 0) OR (task = ?)
Parameters: 0 "stop"
sourceraw docstring

windowclj/s

(window & args)

Accepts a window name followed by a partition by clause.

Accepts a window name followed by a partition by clause.
sourceraw docstring

withclj/s

(with & args)

Accepts one or more CTE definitions.

See the documentation for the :with clause.

Accepts one or more CTE definitions.

See the documentation for the `:with` clause.
sourceraw docstring

with-columnsclj/s

(with-columns col-spec-coll)
(with-columns & col-specs)

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-dataclj/s

(with-data data?)

Accepts a Boolean determining WITH DATA vs WITH NO DATA.

Accepts a Boolean determining WITH DATA vs WITH NO DATA.
sourceraw docstring

with-recursiveclj/s

(with-recursive & args)

Accepts one or more CTE definitions.

See the documentation for the :with clause.

Accepts one or more CTE definitions.

See the documentation for the `:with` clause.
sourceraw docstring

within-groupclj/s

(within-group expr1 clause1 & more)

Accepts alternating expressions and clauses and produces a WITHIN GROUP expression:

(within-group :%count.* (where :> i 5))

Produces: COUNT(*) WITHIN GROUP (WHERE i > ?) Parameters: 5

Accepts alternating expressions and clauses and
produces a WITHIN GROUP expression:

(within-group :%count.* (where :> i 5))

Produces: COUNT(*) WITHIN GROUP (WHERE i > ?)
Parameters: 5
sourceraw docstring

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

× close