Posted: 30/Jan/2024
You can use expression
package in the AWS Go SDK for DynamoDB to programmatically build key condition and filter expressions and use them with Query
API.
Here is an example that queries for a specific thread based on the forum name (partition key) and subject (sort key):
keyConditionBuilder := expression.Key("ForumName").Equal(expression.Value("Amazon DynamoDB"))
filterExpressionBuilder := expression.Name("Views").GreaterThanEqual(expression.Value(3))
expr, _ := expression.NewBuilder().
WithKeyCondition(keyConditionBuilder).
WithFilter(filterExpressionBuilder).
Build()
_, err := client.Query(context.Background(), &dynamodb.QueryInput{
TableName: aws.String("Thread"),
KeyConditionExpression: expr.KeyCondition(),
FilterExpression: expr.Filter(),
ExpressionAttributeNames: expr.Names(),
ExpressionAttributeValues: expr.Values(),
})
Recommended reading - Key and NameBuilder in the package API docs
Top comments (0)