Quantcast
Channel: DEV Community: Abhishek Gupta
Viewing all articles
Browse latest Browse all 205

[20 Days of DynamoDB] Day 14 - Using the DynamoDB expression package to build Key Condition and Filter expressions

$
0
0

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


Viewing all articles
Browse latest Browse all 205

Trending Articles