Created
December 18, 2012 19:56
-
-
Save thegeez/4331339 to your computer and use it in GitHub Desktop.
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
;; bin/repl with datomic-free-0.8.3664 | |
(use '[datomic.api :only [q db] :as d]) | |
(def uri "datomic:mem://future") | |
(d/create-database uri) | |
(def conn (d/connect uri)) | |
;; balance attr | |
@(d/transact conn [{:db/id (d/tempid :db.part/db) | |
:db/ident :account/balance | |
:db/valueType :db.type/long | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db}]) | |
;; create entity | |
(def eid (-> @(d/transact conn [{:db/id (d/tempid :db.part/user) | |
:account/balance 100}]) | |
:tempids | |
first | |
val)) | |
;; async happy path | |
(def ta1 (d/transact-async conn [[:db.fn/cas eid :account/balance 100 200]])) | |
(prn "ta1 result: " @ta1) | |
(prn "account balance: " (:account/balance (d/entity (db conn) eid))) | |
;; => 200 | |
;; async fail path | |
(def ta2 (try (d/transact-async conn [[:db.fn/cas eid :account/balance 400 500]]) | |
(catch Exception e | |
(prn "Won't get to here: " e)))) | |
(try @ta2 | |
(catch Exception e | |
(prn "Should end up here:" e))) | |
;; sync happy path | |
(def t1 (d/transact conn [[:db.fn/cas eid :account/balance 200 300]])) | |
;; can get the response | |
(prn "t1 result: " @t1) | |
(prn "account balance: " (:account/balance (d/entity (db conn) eid))) | |
;;=> 300 | |
(def t2 (try (d/transact conn [[:db.fn/cas eid :account/balance 400 500]]) | |
(catch Exception e | |
(prn "Should not get here, but somehow do: " e)))) | |
(prn "t2 did not return a future") | |
;;;; this should have worked: | |
;;(try @t2 | |
;; (catch Exception e | |
;; (prn "Wanted to check this way."))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment