Facilities to build trees of records based on a supplied
EQL field expression. This is exists because even though
LEFT JOIN queries build ad-hoc trees of data, a flat
(potentially unsorted!) list of records is what SQL will
give. The build
function builds back the tree.
Facilities to build trees of records based on a supplied EQL field expression. This is exists because even though LEFT JOIN queries build ad-hoc trees of data, a flat (potentially unsorted!) list of records is what SQL will give. The `build` function builds back the tree.
(build schema {:keys [fields]} records)
The join query perfomed by seql.query/execute
returns a flat list of entries,
potentially unsorted (this is database implementation specific)
recompose a tree of entities as specified in fields.
For instance let's assume the following list of records coming from a database query:
[{:account/id 0 :user/id 0}
{:account/id 0 :user/id 1}
{:account/id 2 :user/id 3}]
Calling build
with a field definition of [:account/id {:account/users [:user/id]}]
will group the records together into:
[{:account/id 0 :account/users [{:user/id 0} {:user/id 1}]}
{:account/id 2 :account/users [{:user/id 3}]}]
Under the hood, the implementation keeps recursing between two functions:
walk-tree
which groups records togetheradd-relation-fn
which builds a closure to add nested fields belonging to a relationThe join query perfomed by `seql.query/execute` returns a flat list of entries, potentially unsorted (this is database implementation specific) recompose a tree of entities as specified in fields. For instance let's assume the following list of records coming from a database query: [{:account/id 0 :user/id 0} {:account/id 0 :user/id 1} {:account/id 2 :user/id 3}] Calling `build` with a field definition of `[:account/id {:account/users [:user/id]}]` will group the records together into: [{:account/id 0 :account/users [{:user/id 0} {:user/id 1}]} {:account/id 2 :account/users [{:user/id 3}]}] Under the hood, the implementation keeps recursing between two functions: - `walk-tree` which groups records together - `add-relation-fn` which builds a closure to add nested fields belonging to a relation
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close