Created
March 20, 2018 15:20
-
-
Save bahulneel/c44869fd0078135918b693b145da722f to your computer and use it in GitHub Desktop.
Not Join in datascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def conn (d/create-conn {})) | |
(def data | |
[{:a 1 :b 2} | |
{:a 2 :b 3 :c true}]) | |
(d/transact! conn data) | |
(defn not-join | |
[db q vars where] | |
(let [q+ (assoc q :find vars) | |
q- (assoc q+ :where where :in ['$ [vars '...]]) | |
q-join (assoc q :in ['$ [vars '...]]) | |
vals+ (d/q q+ db) | |
vals- (d/q q- db vals+) | |
vals (clojure.set/difference vals+ vals-)] | |
(d/q q-join db vals))) | |
(comment | |
{:find [?a ?b] | |
:where | |
[[?e :a ?a] | |
[?e :b ?b] | |
(not-join [?e] | |
[?e :c true])]}) | |
(println | |
(not-join | |
(d/db conn) | |
'{:find [?a ?b] | |
:where | |
[[?e :a ?a] | |
[?e :b ?b]]} | |
'[?e] | |
'[[?e :c true]])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment