Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

return the consumed capacity Units

  • Loading branch information...
commit db213c64075eb1796de0bd853040dee20f20bb26 1 parent 4605869
@fabiokung authored
Showing with 16 additions and 7 deletions.
  1. +15 −6 dynamodb.go
  2. +1 −1  json.go
View
21 dynamodb.go
@@ -44,14 +44,14 @@ func NewTable(name string, region *Region, awsAccessKeyId string,
return &Table{name, region, k, s, debugMode}
}
-func (t *Table) UpdateItem(key interface{}, item map[string]interface{}) error {
+func (t *Table) UpdateItem(key interface{}, item map[string]interface{}) (uint64, error) {
k, err := NewField(key)
if err != nil {
- return err
+ return 0, err
}
attrs, err := valuesToAttributeMap(item)
if err != nil {
- return err
+ return 0, err
}
r := new(UpdateItemRequest)
@@ -60,12 +60,21 @@ func (t *Table) UpdateItem(key interface{}, item map[string]interface{}) error {
r.AttributeUpdates = attrs
r.ReturnValues = "UPDATED_OLD"
- _, err = t.doDynamoRequest("UpdateItem", r)
+ rawResp, err := t.doDynamoRequest("UpdateItem", r)
if err != nil {
- return err
+ return 0, err
}
- return nil
+ type UpdateItemResponse struct {
+ ConsumedCapacityUnits uint64
+ }
+
+ resp := new(UpdateItemResponse)
+ err = json.Unmarshal(rawResp, &resp)
+ if err != nil {
+ return 0, err
+ }
+ return resp.ConsumedCapacityUnits, nil
}
func (t *Table) Query(key interface{}, consistent bool) ([]map[string]interface{}, error) {
View
2  json.go
@@ -104,7 +104,7 @@ type UpdateItemRequest struct {
}
type Attribute struct {
- Value Field `json:",omitempty"`
+ Value Field `json:",omitempty"`
Action string `json:",omitempty"`
}
Please sign in to comment.
Something went wrong with that request. Please try again.