Created
January 12, 2016 21:16
-
-
Save dball/f4cd5a52dddc7b812b86 to your computer and use it in GitHub Desktop.
Trouble with datomic transaction fns
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
(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