Primary API for HoneySQL 2.x.
This includes the format
function -- the primary entry point -- as well
as several public formatters that are intended to help users extend the
supported syntax.
In addition, functions to extend HoneySQL are also provided here:
sql-kw
-- turns a Clojure keyword into SQL code (makes it uppercase
and replaces - with space).format-dsl
-- intended to format SQL statements; returns a vector
containing a SQL string followed by parameter values.format-expr
-- intended to format SQL expressions; returns a vector
containing a SQL string followed by parameter values.format-expr-list
-- intended to format a list of SQL expressions;
returns a pair comprising: a sequence of SQL expressions (to be
join with a delimiter) and a sequence of parameter values.set-dialect!
-- set the default dialect to be used for formatting.register-clause!
-- register a new statement/clause formatter.register-fn!
-- register a new function call (or special syntax)
formatter.register-op!
-- register a new operator formatter.Primary API for HoneySQL 2.x. This includes the `format` function -- the primary entry point -- as well as several public formatters that are intended to help users extend the supported syntax. In addition, functions to extend HoneySQL are also provided here: * `sql-kw` -- turns a Clojure keyword into SQL code (makes it uppercase and replaces - with space). * `format-dsl` -- intended to format SQL statements; returns a vector containing a SQL string followed by parameter values. * `format-expr` -- intended to format SQL expressions; returns a vector containing a SQL string followed by parameter values. * `format-expr-list` -- intended to format a list of SQL expressions; returns a pair comprising: a sequence of SQL expressions (to be join with a delimiter) and a sequence of parameter values. * `set-dialect!` -- set the default dialect to be used for formatting. * `register-clause!` -- register a new statement/clause formatter. * `register-fn!` -- register a new function call (or special syntax) formatter. * `register-op!` -- register a new operator formatter.
(clause-order)
Return the current order that known clauses will be applied when
formatting a data structure into SQL. This may be useful when you are
figuring out the before
argument of register-clause!
as well as
for debugging new clauses you have registered.
Return the current order that known clauses will be applied when formatting a data structure into SQL. This may be useful when you are figuring out the `before` argument of `register-clause!` as well as for debugging new clauses you have registered.
(format data)
(format data opts)
(format data k v & {:as opts})
Turn the data DSL into a vector containing a SQL string followed by any parameter values that were encountered in the DSL structure.
This is the primary API for HoneySQL and handles dialects, quoting, and named parameters.
Turn the data DSL into a vector containing a SQL string followed by any parameter values that were encountered in the DSL structure. This is the primary API for HoneySQL and handles dialects, quoting, and named parameters.
(format-dsl statement-map & [{:keys [aliased nested pretty]}])
Given a hash map representing a SQL statement and a hash map of options, return a vector containing a string -- the formatted SQL statement -- followed by any parameter values that SQL needs.
This is intended to be used when writing your own formatters to extend the DSL supported by HoneySQL.
Given a hash map representing a SQL statement and a hash map of options, return a vector containing a string -- the formatted SQL statement -- followed by any parameter values that SQL needs. This is intended to be used when writing your own formatters to extend the DSL supported by HoneySQL.
(format-entity x & [{:keys [aliased drop-ns]}])
Given a simple SQL entity (a keyword or symbol -- or string), return the equivalent SQL fragment (as a string -- no parameters).
Handles quoting, splitting at / or ., replacing - with _ etc.
Given a simple SQL entity (a keyword or symbol -- or string), return the equivalent SQL fragment (as a string -- no parameters). Handles quoting, splitting at / or ., replacing - with _ etc.
(format-expr expr & [{:keys [nested] :as opts}])
Given a data structure that represents a SQL expression and a hash map of options, return a vector containing a string -- the formatted SQL statement -- followed by any parameter values that SQL needs.
This is intended to be used when writing your own formatters to extend the DSL supported by HoneySQL.
Given a data structure that represents a SQL expression and a hash map of options, return a vector containing a string -- the formatted SQL statement -- followed by any parameter values that SQL needs. This is intended to be used when writing your own formatters to extend the DSL supported by HoneySQL.
(format-expr-list exprs & [opts])
Given a sequence of expressions represented as data, return a pair where the first element is a sequence of SQL fragments and the second element is a sequence of parameters. The caller should join the SQL fragments with whatever appropriate delimiter is needed and then return a vector whose first element is the complete SQL string and whose subsequent elements are the parameters:
(let [[sqls params] (format-expr-list data opts)] (into [(str/join delim sqls)] params))
This is intended to be used when writing your own formatters to extend the DSL supported by HoneySQL.
Given a sequence of expressions represented as data, return a pair where the first element is a sequence of SQL fragments and the second element is a sequence of parameters. The caller should join the SQL fragments with whatever appropriate delimiter is needed and then return a vector whose first element is the complete SQL string and whose subsequent elements are the parameters: (let [[sqls params] (format-expr-list data opts)] (into [(str/join delim sqls)] params)) This is intended to be used when writing your own formatters to extend the DSL supported by HoneySQL.
(register-clause! clause formatter before)
Register a new clause formatter. If before
is nil
, the clause is
added to the end of the list of known clauses, otherwise it is inserted
immediately prior to that clause.
New clauses are registered in the base order and the current order so
that any dialect selections are able to include them while still working
predictably from the base order. Caveat: that means if you register a new
clause before
a clause that is ordered differently in different
dialects, your new clause may also end up in a different place. The
only clause so far where that would matter is :set
which differs in
MySQL.
Use clause-order
to see the full ordering of existing clauses.
Register a new clause formatter. If `before` is `nil`, the clause is added to the end of the list of known clauses, otherwise it is inserted immediately prior to that clause. New clauses are registered in the base order and the current order so that any dialect selections are able to include them while still working predictably from the base order. Caveat: that means if you register a new clause `before` a clause that is ordered differently in different dialects, your new clause may also end up in a different place. The only clause so far where that would matter is `:set` which differs in MySQL. Use `clause-order` to see the full ordering of existing clauses.
(register-fn! function formatter)
Register a new function (as special syntax). The formatter
is either
a keyword, meaning that this new function should use the same syntax as
an existing function, or a function of two arguments that generates a
SQL string and parameters (as a vector). The two arguments are the name
of the function (as a keyword) and a sequence of the arguments from the
DSL.
Register a new function (as special syntax). The `formatter` is either a keyword, meaning that this new function should use the same syntax as an existing function, or a function of two arguments that generates a SQL string and parameters (as a vector). The two arguments are the name of the function (as a keyword) and a sequence of the arguments from the DSL.
(register-op! op & {:keys [variadic ignore-nil]})
Register a new infix operator. Operators can be defined to be variadic (the
default is that they are binary) and may choose to ignore nil
arguments
(this can make it easier to programmatically construct the DSL).
Register a new infix operator. Operators can be defined to be variadic (the default is that they are binary) and may choose to ignore `nil` arguments (this can make it easier to programmatically construct the DSL).
(set-dialect! dialect)
Set the default dialect for formatting.
Can be: :ansi
(the default), :mysql
, :oracle
, or :sqlserver
.
Dialects are always applied to the base order to create the current order.
Set the default dialect for formatting. Can be: `:ansi` (the default), `:mysql`, `:oracle`, or `:sqlserver`. Dialects are always applied to the base order to create the current order.
(sql-kw k)
Given a keyword, return a SQL representation of it as a string.
A :kebab-case
keyword becomes a KEBAB CASE
(uppercase) string
with hyphens replaced by spaces, e.g., :insert-into
=> INSERT INTO
.
Any namespace qualifier is ignored.
Given a keyword, return a SQL representation of it as a string. A `:kebab-case` keyword becomes a `KEBAB CASE` (uppercase) string with hyphens replaced by spaces, e.g., `:insert-into` => `INSERT INTO`. Any namespace qualifier is ignored.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close