Skip to content

Instantly share code, notes, and snippets.

@dball
Created January 12, 2016 21:16
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 dball/f4cd5a52dddc7b812b86 to your computer and use it in GitHub Desktop.
Save dball/f4cd5a52dddc7b812b86 to your computer and use it in GitHub Desktop.
Trouble with datomic transaction fns
(deftxnfn increase-book-quality
[db eid attr quality]
(do
(assert (= :book/quality attr))
(if (q '[:find ?eid .
:in $ ?ords ?eid ?quality'
:where
[?eid :book/quality ?quality-eid]
[?quality-eid :db/ident ?quality]
[(get ?ords ?quality' -1) ?ord']
[(get ?ords ?quality -1) ?ord]
[(> ?ord' ?ord)]]
db
{:BookQuality/Poor 0
:BookQuality/Good 1
:BookQuality/Excellent 2}
eid quality)
[[:db/add eid :book/quality quality]]
[])))
(defn increase-book-quality-txns
[db eid quality]
(if (q '[:find ?eid .
:in $ ?ords ?eid ?quality'
:where
[?eid :book/quality ?quality-eid]
[?quality-eid :db/ident ?quality]
[(get ?ords ?quality' -1) ?ord']
[(get ?ords ?quality -1) ?ord]
[(> ?ord' ?ord)]]
db
{:BookQuality/Poor 0
:BookQuality/Good 1
:BookQuality/Excellent 2}
eid quality)
[[:db/add eid :book/quality quality]]
[]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment