Skip to content

Instantly share code, notes, and snippets.

@nabeken
Created October 25, 2015 10:23
Show Gist options
  • Save nabeken/709933249a58b6477e85 to your computer and use it in GitHub Desktop.
Save nabeken/709933249a58b6477e85 to your computer and use it in GitHub Desktop.
// Add conditon and it should fail
{
err := dtable.PutItem(
items[0],
option.PutExpressionAttributeName("date", "#date"),
option.PutCondition("attribute_not_exists(#date)"),
)
assert.Error(err)
dynamoErr, ok := err.(awserr.Error)
assert.True(ok, "err must be awserr.Error")
assert.Equal("ConditionalCheckFailedException", dynamoErr.Code())
}
// Update the item with incrementing counter and setting role as StringSet
{
err := dtable.UpdateItem(
hashKey,
rangeKey,
option.UpdateExpressionAttributeName("login_count", "#count"),
option.UpdateExpressionAttributeName("role", "#role"),
option.UpdateExpressionAttributeValue(":i", attributes.Number(1)),
option.UpdateExpressionAttributeValue(":role", attributes.StringSet(role)),
option.UpdateExpression("ADD #count :i SET #role = :role"),
)
if err != nil {
t.Error(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment