Skip to content

Instantly share code, notes, and snippets.

@refset
Last active January 31, 2022 17:10
Show Gist options
  • Save refset/25d8ae03c69993831c9c23cf7e12a537 to your computer and use it in GitHub Desktop.
Save refset/25d8ae03c69993831c9c23cf7e12a537 to your computer and use it in GitHub Desktop.
query-orphan-entities.clj
(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