DEV Community

Abhishek Gupta for AWS

Posted on • Originally published at community.aws

2

[20 Days of DynamoDB] Day 13 - Using the DynamoDB expression package to build Condition expressions

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(),
    })
Enter fullscreen mode Exit fullscreen mode

Recommended reading - WithCondition method in the package API docs

Billboard image

The fastest way to detect downtimes

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitoring.

Get started now

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay