Skip to content

Instantly share code, notes, and snippets.

@jgdavey
Created January 29, 2016 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgdavey/57208328312ebecbc6c6 to your computer and use it in GitHub Desktop.
Save jgdavey/57208328312ebecbc6c6 to your computer and use it in GitHub Desktop.
(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