Bisql supports a small expression language inside if and elseif directives.
The goal is to keep conditional SQL readable without turning SQL templates into a general-purpose scripting language.
Bisql currently supports:
and, or=, !=, <, <=, >, >=(, )Examples:
/*%if active and status = expected_status */
status = 'pending'
/*%end */
/*%if (active and status = expected_status) or pending */
status = 'pending'
/*%end */
Operands are parameter references.
That means both sides of a comparison are resolved from the params map:
/*%if status = expected_status */
{:status "pending"
:expected_status "pending"}
Dot-path access also works:
/*%if user.id = owner.id */
{:user {:id 10}
:owner {:id 10}}
A bare identifier is treated as a truthiness check:
/*%if active */
Expressions follow this precedence order:
andorSo this:
/*%if active or status = expected_status and pending */
is interpreted as:
active or ((status = expected_status) and pending)
Use parentheses when you want a different grouping.
The initial expression language is intentionally small.
These are not supported yet:
notnil literalsFor example, this is not supported:
/*%if status = "active" */
Instead, compare parameters:
/*%if status = expected_status */
{:status "active"
:expected_status "active"}
note
Bisql is designed to keep SQL executable and predictable.
The expression language is intentionally limited so that:
Bisql currently supports this expression language only inside if and
elseif conditions.
The main reason is that more complex logic should usually be finished in Clojure before values reach the SQL template. Bisql intentionally keeps SQL templates focused on SQL structure, with only a small amount of conditional control flow.
The same reasoning applies to the language itself. It is intentionally much smaller than a general-purpose expression language so that templates stay readable, predictable, and close to executable SQL.
See also:
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |