-
-
Save jgdavey/57208328312ebecbc6c6 to your computer and use it in GitHub Desktop.
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
(def set-with-token | |
(d/function | |
'{:lang "clojure" | |
:params [db token-attr token-value attr value] | |
:code (let [e (d/q '[:find ?e . | |
:in $ ?ta ?tv | |
:where | |
[?e ?ta ?tv]] | |
db token-attr token-value)] | |
(if e | |
[[:db/add e attr value] | |
[:db/retract e token-attr token-value]] | |
(throw (ex-info (str "No entity with that token exists") | |
{token-attr token-value}))))})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment