Skip to content

Instantly share code, notes, and snippets.

@bahulneel
Created March 20, 2018 15:20
Show Gist options
  • Save bahulneel/c44869fd0078135918b693b145da722f to your computer and use it in GitHub Desktop.
Save bahulneel/c44869fd0078135918b693b145da722f to your computer and use it in GitHub Desktop.
Not Join in datascript
(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