{:sql-stmt :select
:fields ...field-list...
:from ...source-list...
:where ...expr...
:group ...expr-list...
:having ...expr...
:order-by ...order-item-list...
:limit ...expr...
:offset ...expr...}
A select statement is just an ordinary map with the following allowable keys:
{:sql-stmt :select
:fields ...field-list...
:from ...source-list...
:where ...expr...
:group ...expr-list...
:having ...expr...
:order-by ...order-item-list...
:limit ...expr...
:offset ...expr...}
Most keys are optional.
A legitimate select statement requires the sql-stmt
key and either the fields
key or the from
key.
For example:
=> (to-sql {:sql-stmt :select, :fields 5})
"SELECT 5;"
=> (to-sql {:sql-stmt :select, :from :users})
"SELECT * FROM users;"
...field-list...
can be either a single field or a collection of fields.
Any single field can be an expression or a field map:
{:field ...expr... ;mandatory
:as ...name...} ;optional
...source-list...
can be a single source or a collection of them.
Any single source can be a name (keyword, string, or symbol), a select statement or a join map:
{:source ...source... ;mandatory
:op ...op...
:on ...expr...
:using ...name-list...
:as ...name...}
...source...
can be a keyword, string, select statement, or a nested ...source-list...
.
...op...
is anything suitable to pass to to-sql-keywords
, but usually just a clojure style keyword such as :inner-join
.
If supplied, :as
defines a table alias for the source.
If present, :using
can be a single field name or a collection of them.
In a join map, :on
and :using
are mutually exclusive.
...expr...
can be any valid boolean expression
...expr-list...
can be either a single expression or a collection of expressions.
Usually, each expression identifies a (possibly qualified) column to group by.
...expr...
can be any valid boolean expression
...order-item-list...
can be a single order item or a collection of them.
Any single order item can be an expression or an order item map:
{:expr ...expr-list... ;mandatory
:order ...order...} ;optional - either :asc or :desc; defaults to :asc
...expr...
can be any integral expression
...expr...
can be any integral expression
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close