Posted: 25/Jan/2024
Thanks to the expression
package in the AWS Go SDK for DynamoDB, you can programmatically build Condition expressions and use them with write operations. Here is an example with the DeleteItem
API:
conditionExpressionBuilder := expression.Name("inactive_days").GreaterThanEqual(expression.Value(20))
conditionExpression, _ := expression.NewBuilder().WithCondition(conditionExpressionBuilder).Build()
_, err := client.DeleteItem(context.Background(), &dynamodb.DeleteItemInput{
TableName: aws.String(tableName),
Key: map[string]types.AttributeValue{
"email": &types.AttributeValueMemberS{Value: email},
},
ConditionExpression: conditionExpression.Condition(),
ExpressionAttributeNames: conditionExpression.Names(),
ExpressionAttributeValues: conditionExpression.Values(),
})
Recommended reading - WithCondition method in the package API docs
Top comments (0)