taoensso / faraday

Amazon DynamoDB client for Clojure
https://www.taoensso.com/faraday
Eclipse Public License 1.0
238 stars 84 forks source link

[#122] Transaction Support #123

Closed nxvipin closed 4 years ago

nxvipin commented 5 years ago

Issue #122

This PR introduces support for Dynamo DB transactions. This is up for initial feedback.

Sample TransactWriteItems call:

(far/transact-write-items *client-opts*
 {:client-req-token "foobar"
  :return-cc? true
  :items [{:cond-check {:table-name ttable
                        :prim-kvs {:id 300}
                        :cond-expr "attribute_exists(#id)"
                        :expr-attr-names {"#id" "id"}}}

          {:put {:table-name ttable
                 :item  i2
                 :cond-expr "attribute_not_exists(#id)"
                 :expr-attr-names {"#id" "id"}}}

          {:delete {:table-name ttable
                    :prim-kvs {:id 302}
                    :cond-expr "attribute_exists(#id)"
                    :expr-attr-names {"#id" "id"}}}

          {:update {:table-name ttable
                    :prim-kvs  {:id 300}
                    :update-expr "SET #name = :name"
                    :cond-expr "attribute_exists(#id) AND #name = :oldname"
                    :expr-attr-names {"#id" "id", "#name" "name"}
                    :expr-attr-vals  {":oldname" "foo", ":name" "foofoo"}}}]})

Sample TransactGetItems call:

(far/transact-get-items *client-opts*
 {:return-cc? true
  :items [{:table-name ttable
           :prim-kvs {:id 1}}
          {:table-name ttable
           :prim-kvs {:id 2}}]})
kipz commented 4 years ago

Closing this in favour of https://github.com/Taoensso/faraday/pull/145 which is basically this PR rebased on latest master.