Bisql does not ask you to call a generic runtime API for every query. Instead, it can generate normal Clojure vars and functions from SQL resources.
defquerydefquery defines executable query functions on top of an adapter.
Typical use:
(ns sql
(:require [bisql.core :as bisql]))
(bisql/defquery)
Generated functions take:
For example:
(sql.postgresql.public.users.core/get-by-id ds {:id 42})
This corresponds to a SQL resource like:
sql/postgresql/public/users/core.get-by-id.sql
For example:
SELECT *
FROM users
WHERE id = /*$id*/1
Note:
<ns-suffix>.<function-name>.sql<ns-suffix> is omitted, core is used as the default namespace suffixsql/postgresql/public/users/get-by-id.sql also resolves to the same functiondefquery is the main macro most users will use in application code.
defrenderdefrender loads SQL templates and defines pure renderer functions.
Typical use:
(ns sql
(:require [bisql.core :as bisql]))
(bisql/defrender)
This creates functions that return:
For example:
(sql.postgresql.public.users.core/get-by-id {:id 42})
This corresponds to the same SQL resource:
sql/postgresql/public/users/core.get-by-id.sql
returns a map like:
{:sql "SELECT * FROM users WHERE id = ?"
:params [42]
:meta {}}
defrender is useful for debugging and development workflows where you want to inspect rendered SQL without executing it.
This keeps the call site simple:
It also keeps SQL visible. The source of truth is still the SQL file itself.
Generated CRUD SQL and handwritten SQL follow the same model.
Once a SQL file exists under sql/..., Bisql can generate matching Clojure functions for it.
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 |