Skip to content

Commit

Permalink
Merge pull request #6 from LaurenceGA/update-item-return
Browse files Browse the repository at this point in the history
Allow for returning output when updating items
  • Loading branch information
nabeken authored Oct 1, 2020
2 parents 3ef003f + aac1004 commit c7373f4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ aws-go-dynamodb is a Amazon DynamoDB library built with [aws/aws-sdk-go](https:/

## Testing

If you want to run the tests, you *SHOULD* use a decicated DynamoDB table for the tests.
If you want to run the tests, you *SHOULD* use a dedicated DynamoDB table for the tests.

You can specify the table name in environment variable.
You can specify the table name in an environment variable.

```sh
$ cd table
Expand Down
8 changes: 8 additions & 0 deletions table/option/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ func UpdateExpressionAttributeValue(placeholder string, value *dynamodb.Attribut
req.ExpressionAttributeValues[placeholder] = value
}
}

// UpdateReturnValues sets the attributes to return in dynamodb.UpdateItemOutput.
// Default is dynamodb.ReturnValueNone.
func UpdateReturnValues(returnValue string) UpdateItemInput {
return func(req *dynamodb.UpdateItemInput) {
req.ReturnValues = aws.String(returnValue)
}
}
5 changes: 2 additions & 3 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (t *Table) PutItem(v interface{}, opts ...option.PutItemInput) error {
}

// UpdateItem updates the item on the table.
func (t *Table) UpdateItem(hashKeyValue, rangeKeyValue *dynamodb.AttributeValue, opts ...option.UpdateItemInput) error {
func (t *Table) UpdateItem(hashKeyValue, rangeKeyValue *dynamodb.AttributeValue, opts ...option.UpdateItemInput) (*dynamodb.UpdateItemOutput, error) {
req := &dynamodb.UpdateItemInput{
TableName: t.Name,
}
Expand All @@ -102,8 +102,7 @@ func (t *Table) UpdateItem(hashKeyValue, rangeKeyValue *dynamodb.AttributeValue,
f(req)
}

_, err := t.DynamoDB.UpdateItem(req)
return err
return t.DynamoDB.UpdateItem(req)
}

// GetItem get the item from the table and convert it to v.
Expand Down
4 changes: 2 additions & 2 deletions table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestTable(t *testing.T) {

// Update the item with incrementing counter and setting role as StringSet
{
err := dtable.UpdateItem(
_, err := dtable.UpdateItem(
hashKey,
rangeKey,
option.UpdateExpressionAttributeName("login_count", "#count"),
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestTable(t *testing.T) {

// Update the item with decrementing counter and removing role
{
err := dtable.UpdateItem(
_, err := dtable.UpdateItem(
hashKey,
rangeKey,
option.UpdateExpressionAttributeName("login_count", "#count"),
Expand Down

0 comments on commit c7373f4

Please sign in to comment.