Last active
December 23, 2015 12:29
-
-
Save yayitswei/6635158 to your computer and use it in GitHub Desktop.
learning how to use the history db
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
(defn balance-history [id] | |
(d/q '[:find ?tx ?tx-time ?v | |
:in $ ?e ?a | |
:where [?e ?a ?v ?tx _] | |
[?tx :db/txInstant ?tx-time]] | |
(d/history (db/db)) id :account/balance)) | |
@(d/transact conn [[:credit 17592186145525 100]]) | |
(balance-history 17592186145525) | |
; => #{[13194139534419 #inst "2013-09-20T09:04:56.730-00:00" 0] | |
; [13194139534419 #inst "2013-09-20T09:04:56.730-00:00" 100] | |
; [13194139534415 #inst "2013-09-20T09:00:49.186-00:00" 0]} | |
; why does this return three results? I want only two: the first 0 and 100. |
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
[ | |
{:db/id #db/id[:db.part/db] | |
:db/ident :account/balance | |
:db/cardinality :db.cardinality/one | |
:db/valueType :db.type/bigint | |
:db.install/_attribute :db.part/db} | |
{:db/id #db/id [:db.part/user] | |
:db/ident :credit | |
:db/fn #db/fn {:lang "clojure" | |
:params [db id amount] | |
:code [[:db/add id :account/balance (biginteger balance)]]}} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the answer was to restrict ?added (the fifth field in the query pattern) to true:
:where [?e ?a ?v ?tx true]