-
-
Save refset/9c4af79b359c1d51d83ba46f930fbedd to your computer and use it in GitHub Desktop.
LWW in Datalog (https://speakerdeck.com/ept/data-structures-as-queries-expressing-crdts-using-datalog?slide=15)
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
;; LWW Register | |
;; https://speakerdeck.com/ept/data-structures-as-queries-expressing-crdts-using-datalog?slide=15 | |
(def schema | |
{:assign/time {:db/valueType :Number} | |
:assign/key {:db/valueType :Number} | |
:assign/value {:db/valueType :Number}}) | |
(def rules | |
'[[(older ?t1 ?key) | |
[?op :assign/key ?key] [?op :assign/time ?t1] | |
[?op2 :assign/key ?key] [?op2 :assign/time ?t2] | |
[(< ?t1 ?t2)]] | |
[(lww ?key ?val) | |
[?op :assign/time ?t] | |
[?op :assign/key ?key] | |
[?op :assign/value ?val] | |
(not [(older ?t ?key)])]]) | |
;; possible ergonomics improvement | |
(def rules | |
'[[(older ?t1 ?key) | |
#:assign{:key ?key :time ?t1} | |
#:assign{:key ?key :time ?t2} | |
[(< ?t1 ?t2)]]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment