Merge Datomic Pull syntax via union and intersection.
(require '[lab79.datomic-pullups :as dp])
Given two pull patterns, e.g.:
(def pull1 [:foo :bar])
(def pull2 [:foo :qux :cow])
We can get the union of them:
(dp/compose-pull-patterns [pull1 pull2])
;;=>
(:foo :bar :qux :cow)
We can also get the intersection:
(dp/intersect-pull-patterns pull1 pull2)
;;=>
[:foo]
It works on deeply nested patterns too:
;; union
(dp/compose-pull-patterns
[[{:user/access-groups
[{:access-group/members
[:person.id/ssn
{:person/name [:person.name/family]}]}]}]
[{:user/access-groups
[{:access-group/members
[{:person/name [:person.name/given]}]}]}]])
;; =>
(#:user{:access-groups
(#:access-group{:members
(:person.id/ssn #:person{:name (:person.name/family :person.name/given)})})})
;; intersection
(dp/intersect-pull-patterns
[{:user/access-groups
[{:access-group/members
[:person.id/ssn
{:person/name [:person.name/given :person.name/family]}]}]}]
[{:user/access-groups
[{:access-group/members
[{:person/name [:person.name/given]}]}]}])
;; =>
[#:user{:access-groups
[#:access-group{:members
[#:person{:name [:person.name/given]}]}]}]
See the tests for more examples.
It does not currently support the full range of Datomic syntax:
- does not explicitly support
*
Limitations are captured in commented-out tests.
Copyright © 2017 Lab79, Inc.
Distributed under the MIT License.