Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

return the consumed capacity Units

  • Loading branch information...
commit db213c64075eb1796de0bd853040dee20f20bb26 1 parent 4605869
Fabio Kung authored

Showing 2 changed files with 16 additions and 7 deletions. Show diff stats Hide diff stats

  1. +15 6 dynamodb.go
  2. +1 1  json.go
21 dynamodb.go
@@ -44,14 +44,14 @@ func NewTable(name string, region *Region, awsAccessKeyId string,
44 44 return &Table{name, region, k, s, debugMode}
45 45 }
46 46
47   -func (t *Table) UpdateItem(key interface{}, item map[string]interface{}) error {
  47 +func (t *Table) UpdateItem(key interface{}, item map[string]interface{}) (uint64, error) {
48 48 k, err := NewField(key)
49 49 if err != nil {
50   - return err
  50 + return 0, err
51 51 }
52 52 attrs, err := valuesToAttributeMap(item)
53 53 if err != nil {
54   - return err
  54 + return 0, err
55 55 }
56 56
57 57 r := new(UpdateItemRequest)
@@ -60,12 +60,21 @@ func (t *Table) UpdateItem(key interface{}, item map[string]interface{}) error {
60 60 r.AttributeUpdates = attrs
61 61 r.ReturnValues = "UPDATED_OLD"
62 62
63   - _, err = t.doDynamoRequest("UpdateItem", r)
  63 + rawResp, err := t.doDynamoRequest("UpdateItem", r)
64 64 if err != nil {
65   - return err
  65 + return 0, err
66 66 }
67 67
68   - return nil
  68 + type UpdateItemResponse struct {
  69 + ConsumedCapacityUnits uint64
  70 + }
  71 +
  72 + resp := new(UpdateItemResponse)
  73 + err = json.Unmarshal(rawResp, &resp)
  74 + if err != nil {
  75 + return 0, err
  76 + }
  77 + return resp.ConsumedCapacityUnits, nil
69 78 }
70 79
71 80 func (t *Table) Query(key interface{}, consistent bool) ([]map[string]interface{}, error) {
2  json.go
@@ -104,7 +104,7 @@ type UpdateItemRequest struct {
104 104 }
105 105
106 106 type Attribute struct {
107   - Value Field `json:",omitempty"`
  107 + Value Field `json:",omitempty"`
108 108 Action string `json:",omitempty"`
109 109 }
110 110

0 comments on commit db213c6

Please sign in to comment.
Something went wrong with that request. Please try again.