Query compilation pipeline is something like this:
Call something like [[toucan2.select/select]] with `modelable` and `unparsed-args`
↓
`modelable` is resolved to `model` with [[toucan2.model/with-model]]
↓
[[parse-args]] is used to parse args into a `parsed-args` map
↓
The `:queryable` key in parsed args is resolved
↓
[[build]] takes the resolved query and combines the other parsed args into it to build a compilable query. The default
backend builds a Honey SQL 2 query map
↓
some sort of reducible is returned.
<reducing the reducible>
↓
[[toucan2.compile/with-compiled-query]] compiles the built query (e.g. Honey SQL 2) into something that can be
executed natively (e.g. a `sql-args` vector)
↓
[[toucan2.connection/with-connection]] is used to get a connection from the current connectable, or the default
connectable for `model`, or the global default connectable
↓
Compiled query is executed with connection
Query compilation pipeline is something like this: ``` Call something like [[toucan2.select/select]] with `modelable` and `unparsed-args` ↓ `modelable` is resolved to `model` with [[toucan2.model/with-model]] ↓ [[parse-args]] is used to parse args into a `parsed-args` map ↓ The `:queryable` key in parsed args is resolved ↓ [[build]] takes the resolved query and combines the other parsed args into it to build a compilable query. The default backend builds a Honey SQL 2 query map ↓ some sort of reducible is returned. <reducing the reducible> ↓ [[toucan2.compile/with-compiled-query]] compiles the built query (e.g. Honey SQL 2) into something that can be executed natively (e.g. a `sql-args` vector) ↓ [[toucan2.connection/with-connection]] is used to get a connection from the current connectable, or the default connectable for `model`, or the global default connectable ↓ Compiled query is executed with connection ```
(condition->honeysql-where-clause k v)
Something sequential like :id [:> 5]
becomes [:> :id 5]
. Other stuff like :id 5
just becomes [:= :id 5]
.
Something sequential like `:id [:> 5]` becomes `[:> :id 5]`. Other stuff like `:id 5` just becomes `[:= :id 5]`.
(honeysql-table-and-alias model)
Build an Honey SQL [table]
or [table alias]
(if the model has a toucan2.model/namespace
form) for model
for
use in something like a :select
clause.
Build an Honey SQL `[table]` or `[table alias]` (if the model has a [[toucan2.model/namespace]] form) for `model` for use in something like a `:select` clause.
(parse-args query-type unparsed-args)
(parse-args query-type spec unparsed-args)
parse-args
takes a sequence of unparsed args passed to something like toucan2.select/select
and parses them into
a parsed args map. The default implementation uses [[clojure.spec.alpha]] to parse the args according to args-spec
.
These keys are commonly returned by several of the different implementations parse-args
, and other tooling is
build to leverage them:
:modelable
-- usually the first of the unparsed-args
, this is the thing that should get resolved to a model
with toucan2.model/with-model
.
:queryable
-- something that can be resolved to a query, for example a map or integer or 'named query' keyword.
The resolved query is ultimately combined with other parsed args and built into something like a Honey SQL map
with [[build]], then compiled with toucan2.compile/with-compiled-query
.
:kv-args
-- map of key-value pairs. When [[build]] builds a query, it calls apply-kv-arg
for each of the
key-value pairs. The default behavior is to append a Honey SQL :where
clause based on the pair; but you can
customize the behavior for specific keywords to do other things -- :toucan/pk
is one such example.
:columns
-- for things that return instances, :columns
is a sequence of columns to return. These are commonly
specified by wrapping the modelable in a [modelable & columns]
vector.
`parse-args` takes a sequence of unparsed args passed to something like [[toucan2.select/select]] and parses them into a parsed args map. The default implementation uses [[clojure.spec.alpha]] to parse the args according to `args-spec`. These keys are commonly returned by several of the different implementations `parse-args`, and other tooling is build to leverage them: * `:modelable` -- usually the first of the `unparsed-args`, this is the thing that should get resolved to a model with [[toucan2.model/with-model]]. * `:queryable` -- something that can be resolved to a query, for example a map or integer or 'named query' keyword. The resolved query is ultimately combined with other parsed args and built into something like a Honey SQL map with [[build]], then compiled with [[toucan2.compile/with-compiled-query]]. * `:kv-args` -- map of key-value pairs. When [[build]] builds a query, it calls [[apply-kv-arg]] for each of the key-value pairs. The default behavior is to append a Honey SQL `:where` clause based on the pair; but you can customize the behavior for specific keywords to do other things -- `:toucan/pk` is one such example. * `:columns` -- for things that return instances, `:columns` is a sequence of columns to return. These are commonly specified by wrapping the modelable in a `[modelable & columns]` vector.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close