Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/souenzzo/eav-pull
create queries from patterns
https://github.com/souenzzo/eav-pull
Last synced: about 2 months ago
JSON representation
create queries from patterns
- Host: GitHub
- URL: https://github.com/souenzzo/eav-pull
- Owner: souenzzo
- License: epl-1.0
- Created: 2018-10-17T01:18:36.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-10T20:40:05.000Z (almost 5 years ago)
- Last Synced: 2024-03-10T10:02:57.635Z (10 months ago)
- Language: Clojure
- Size: 9.77 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# eav-pull
Get data from db as `eav` tuples
## Usage
lein/boot: `[eav-pull "0.1.0"]`
tools-deps:
```clojure
eav-pull {:git/url "https://github.com/souenzzo/eav-pull.git"
:sha "494a906b32c1767ff3c71f0c1df387ac0df7a27f"}
``````clojure
(require '[eav-pull.core :as eav])
;; should work in datomic-client and datascript too.(require '[datomic.api :as d])
;; tradicional pull/query:
(d/q '[:find [(pull ?e [:user/name {:user/friends [:user/name]}]) ...]
:where [?e :user/id]] db)
;; => [{:user/name "Alice"
;; :user/friends [{:user/name "Bob"}
;; {:user/name "Jack"}]}
;; {:user/name "Bob"
;; :user/friends [{:user/name "Jack"}]}
;; {:user/name "Jack"}]
;; eav query:
(d/q (eav/->query '{::eav/find ?e
::eav/pattern [:user/name
{:user/friends [:user/name]}]
::eav/where [[?e :user/id]]}) db)
;; => #{[1 :user/name "Alice"]
;; [2 :user/name "Bob"]
;; [3 :user/name "Jack"]
;; [1 :user/friends 2]
;; [1 :user/friends 3]
;; [2 :user/friends 3]}
```