Rendering is the process of turning:
- a SQL template
- a params map
into:
- rendered SQL
- bind params
- metadata
[!TIP]- Bisql block comment sigils Bisql reserves five sigils at the start of block comments:
$,^,!,%,:
/*$ */- bind values (ex.?)/*^ */- literal values (ex.'John')/*! */- raw values (ex.created_at)/*% */- control flow (if / for)/*: */- metadata declarationsDo not use those sigils accidentally at the start of an ordinary SQL block comment. To keep room for future extensions, prefer a space or
*when you mean a normal comment:
/* *//** */
Rendering returns a map like this:
{:sql "SELECT * FROM users WHERE id = ?"
:params [42]
:meta {}}If declaration comments exist, :meta contains them.
WHERE id = /*$id*/1{:id 42}→
{:sql "WHERE id = ?"
:params [42]}default-to lets a $ bind variable fall back to the sample SQL fragment when
the parameter is missing:
VALUES (/*$id default-to */DEFAULT)With {:id 42}, this renders as a normal bind:
{:sql "VALUES (?)"
:params [42]}With no :id, the sample SQL fragment is kept:
{:sql "VALUES (DEFAULT)"
:params []}Passing nil is still explicit and renders as a bind param, not as the fallback.
default-to currently applies only to $ bind variables.
WHERE id IN /*$ids*/(1,2,3){:ids [10 20 30]}→
{:sql "WHERE id IN (?, ?, ?)"
:params [10 20 30]}WHERE
/*%if active */
active = true
/*%else => status = 'inactive' */
/*%end */The rendered SQL depends on the truthiness of active.
bisql/DEFAULT and bisql/ALL are rendered as SQL keywords for scalar $ bindings.
{:status bisql/DEFAULT
:limit bisql/ALL}Bisql also provides small helpers for LIKE bindings:
bisql/LIKE_STARTS_WITHbisql/LIKE_ENDS_WITHbisql/LIKE_CONTAINS
For example:
WHERE name LIKE /*$search*/'foo%' ESCAPE '\'{:search (bisql/LIKE_CONTAINS "foo%_bar")}→
{:sql "WHERE name LIKE ? ESCAPE '\\'"
:params ["%foo\\%\\_bar%"]}These helpers:
- add
%in the expected position - escape
% - escape
_ - escape
\
They are intended for scalar $ bindings.
Typical user-facing APIs are:
bisql.core/defrenderbisql.core/defquery