From add0ddbad16925a1386aa9debdc4ce58feb233d4 Mon Sep 17 00:00:00 2001 From: snan Date: Sat, 7 Aug 2021 21:32:59 +0200 Subject: [PATCH] Update pull_data.md --- pull_data.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pull_data.md b/pull_data.md index 2c6fcc3..9b02e11 100644 --- a/pull_data.md +++ b/pull_data.md @@ -1,6 +1,6 @@ ## Pull -Datascript and Datomic both come with a special *Pull API* for pulling entity data at a more coarse grained level. The Pull API can be seen as a sort of *simple query* that is more batch oriented. +Datascript and Datomic both come with a special *Pull API* for pulling entity data at a more coarse-grained level. The Pull API can be seen as a sort of *simple query* that is more batch oriented. The Pull API comes in two variants: - Pull One @@ -8,7 +8,7 @@ The Pull API comes in two variants: ### Select patterns -The Pull API uses patterns for selecing attributes. +The Pull API uses patterns for selecting attributes. The special pattern `'*'` fetches *all* attributes. ### Limits @@ -42,7 +42,7 @@ SQL: `["SELECT * FROM People WHERE People.id = ?", maksim-id]` ### Fetch entity by ID -`entity(db eid)` +`(d/entity db eid)` ### Pull and Query combined @@ -51,21 +51,21 @@ Let's say we want to extract all entity data of all entities. `(d/pull-many db '[*] (d/q '[:find ?e :where [?e]]))` -The `d/q` will match all entity ids in the db -Then `pull-many` pulls everything for all of them +The `d/q` will match all entity ids in the db. +Then `pull-many` pulls everything for all of them. -We can f.ex also use a pull to find attributes to be used in a `:find` clause. +As another example, we can use a pull to find attributes to be used in a `:find` clause. Here we use `pull` on the `:aliases` attribute value `?a` in the `:where` clause to pull only `:name` and `:order` values, which will be used as the attributes to `find`. ```clj ;; query (->> - (d/q '[:find [(pull ?a [:name :order]) ...] - :in $ ?e + (d/q '[:find [(pull ?a [:name :order]) ...] + :in $ ?e :where [?e :aliases ?a] db eid) (sort-by :order) (map :name)) ``` -We can then sort and map the query result independently (and/or include limit/paging logic). +We can then sort and map the query result independently (or include limiting or paging logic).