Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for returning output when updating items #6

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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