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:
clause-order
-- returns the current clause priority ordering;
intended as aid when registering new clauses.format-dsl
-- intended to format SQL statements; returns a vector
containing a SQL string followed by parameter values.format-entity
-- intended to format SQL entities; returns a string
representing the SQL entity.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.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.set-dialect!
-- set the default dialect to be used for formatting,
and optionally set a global :quoted
option.sql-kw
-- turns a Clojure keyword (or symbol) into SQL code (makes
it uppercase and replaces - with space).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: * `clause-order` -- returns the current clause priority ordering; intended as aid when registering new clauses. * `format-dsl` -- intended to format SQL statements; returns a vector containing a SQL string followed by parameter values. * `format-entity` -- intended to format SQL entities; returns a string representing the SQL entity. * `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. * `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. * `set-dialect!` -- set the default dialect to be used for formatting, and optionally set a global `:quoted` option. * `sql-kw` -- turns a Clojure keyword (or symbol) into SQL code (makes it uppercase and replaces - with space).
(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.
(contains-clause? clause)
Returns true if the current DSL expression being formatted contains the specified clause (as a keyword or symbol).
Returns true if the current DSL expression being formatted contains the specified clause (as a keyword or symbol).
(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.
format
accepts options as either a single hash map argument or
as named arguments (alternating keys and values). If you are using
Clojure 1.11 (or later) you can mix'n'match, providing some options
as named arguments followed by other options in a hash map.
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` accepts options as either a single hash map argument or as named arguments (alternating keys and values). If you are using Clojure 1.11 (or later) you can mix'n'match, providing some options as named arguments followed by other options in a hash map.
(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 e & [{: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.
(map= data)
Given a hash map, return a condition structure that can be used in a WHERE clause to test for equality:
{:select :* :from :table :where (sql/map= {:id 1})}
will produce: SELECT * FROM table WHERE id = ? (and a parameter of 1)
Given a hash map, return a condition structure that can be used in a WHERE clause to test for equality: {:select :* :from :table :where (sql/map= {:id 1})} will produce: SELECT * FROM table WHERE id = ? (and a parameter of 1)
(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 & {:keys [quoted]})
Set the default dialect for formatting.
Can be: :ansi
(the default), :mysql
, :oracle
, or :sqlserver
.
Can optionally accept :quoted true
(or :quoted false
) to set the
default global quoting strategy.
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`. Can optionally accept `:quoted true` (or `:quoted false`) to set the default global quoting strategy. 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 keyword whose name begins with a single quote is left exactly as-is
(with the :
and '
removed), otherwise 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 keyword whose name begins with a single quote is left exactly as-is (with the `:` and `'` removed), otherwise 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.
If org.clojure/core.cache is available, resolves to a function that calls core.cache.wrapped/lookup-or-miss, otherwise to a function that throws an exception.
In ClojureScript, a resolves to a function that throws an exception because core.cache relies on JVM machinery and is Clojure-only.
If org.clojure/core.cache is available, resolves to a function that calls core.cache.wrapped/lookup-or-miss, otherwise to a function that throws an exception. In ClojureScript, a resolves to a function that throws an exception because core.cache relies on JVM machinery and is Clojure-only.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close