-
-
Save refset/25d8ae03c69993831c9c23cf7e12a537 to your computer and use it in GitHub Desktop.
query-orphan-entities.clj
This file contains 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
(defn orphan? [db e atts] | |
(not-any? seq (for [a atts] | |
(xt/q db {:find '[e*] | |
:in '[e] | |
:limit 1 | |
:where [['e* a 'e]]} | |
e)))) | |
(let [node (xt/start-node {})] | |
(xt/await-tx node (xt/submit-tx node [[::xt/put {:xt/id :foo2 :ref :foo}] | |
[::xt/put {:xt/id :foo :ref :foo2}] | |
[::xt/put {:xt/id :qux}]])) | |
(with-open [db (xt/open-db node)] | |
(xt/q db '{:find [e] | |
:in [atts] | |
:where [[e :xt/id] | |
[(dev/orphan? $ e atts)]]} | |
(-> (xt/attribute-stats node) | |
keys | |
set | |
(disj :xt/id))))) | |
;; => #{[:qux]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment