https://github.com/lab-79/datomic-pullups
Union and intersection for Datomic Pull syntax
https://github.com/lab-79/datomic-pullups
clojure datomic set-theory
Last synced: 4 days ago
JSON representation
Union and intersection for Datomic Pull syntax
- Host: GitHub
- URL: https://github.com/lab-79/datomic-pullups
- Owner: lab-79
- License: mit
- Created: 2017-02-21T15:22:26.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-27T06:06:21.000Z (almost 9 years ago)
- Last Synced: 2026-07-12T22:31:16.128Z (4 days ago)
- Topics: clojure, datomic, set-theory
- Language: Clojure
- Size: 21.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# datomic-pullups
Merge Datomic Pull syntax via union and intersection.
[](https://clojars.org/lab79/datomic-pullups)
[](https://travis-ci.org/lab-79/datomic-pullups)
[](https://codecov.io/gh/lab-79/datomic-pullups)
[](CHANGELOG.md)
## Usage
```clojure
(require '[lab79.datomic-pullups :as dp])
```
Given two pull patterns, e.g.:
```clojure
(def pull1 [:foo :bar])
(def pull2 [:foo :qux :cow])
```
We can get the union of them:
```clojure
(dp/compose-pull-patterns [pull1 pull2])
;;=>
(:foo :bar :qux :cow)
```
We can also get the intersection:
```clojure
(dp/intersect-pull-patterns pull1 pull2)
;;=>
[:foo]
```
It works on deeply nested patterns too:
```clojure
;; 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](test/lab79/datomic_pullups_test.clj) for more examples.
## Limitations
It does not currently support the full range of Datomic syntax:
- does not explicitly support `*`
Limitations are captured in commented-out tests.
## License
Copyright © 2017 Lab79, Inc.
Distributed under the [MIT License](LICENSE).