func ExampleBuilder_WithCondition() {
	svc := dynamodb.New(session.New())

	// Create a condition where the Rating field must be less than 7.
	cond := expression.Name("Rating").LessThan(expression.Value(7))

	// Create a DynamoDB expression from the condition.
	expr, err := expression.NewBuilder().
		WithCondition(cond).
		Build()
	if err != nil {
		fmt.Println(err)
	}

	// Use the built expression to populate the DeleteItem API operation with the
	// condition expression.
	input := &dynamodb.DeleteItemInput{
		Key: map[string]*dynamodb.AttributeValue{
			"Artist": {
				S: aws.String("No One You Know"),
			},
			"SongTitle": {
				S: aws.String("Scared of My Shadow"),
			},
		},
		ExpressionAttributeNames:  expr.Names(),
		ExpressionAttributeValues: expr.Values(),
		ConditionExpression:       expr.Condition(),
		TableName:                 aws.String("Music"),
	}

	result, err := svc.DeleteItem(input)
	if err != nil {
		if aerr, ok := err.(awserr.Error); ok {
			switch aerr.Code() {
			case dynamodb.ErrCodeConditionalCheckFailedException:
				fmt.Println(dynamodb.ErrCodeConditionalCheckFailedException, aerr.Error())
			case dynamodb.ErrCodeProvisionedThroughputExceededException:
				fmt.Println(dynamodb.ErrCodeProvisionedThroughputExceededException, aerr.Error())
			case dynamodb.ErrCodeResourceNotFoundException:
				fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error())
			case dynamodb.ErrCodeItemCollectionSizeLimitExceededException:
				fmt.Println(dynamodb.ErrCodeItemCollectionSizeLimitExceededException, aerr.Error())
			case dynamodb.ErrCodeInternalServerError:
				fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error())
			default:
				fmt.Println(aerr.Error())
			}
		} else {
			// Print the error, cast err to awserr.Error to get the Code and
			// Message from an error.
			fmt.Println(err.Error())
		}
		return
	}

	fmt.Println(result)
}
// Using Condition Expression
//
// This example deletes an item from the Music table if the rating is lower than
// 7.
Using Condition Expression

This example deletes an item from the Music table if the rating is lower than
7.
// Using Condition Expression // // This example deletes an item from the Music table if the rating is lower than // 7 .
func ExampleBuilder_WithCondition() {
	svc := dynamodb.New(session.New())
	cond := expression.Name("Rating").LessThan(expression.Value(7))
	expr, err := expression.NewBuilder().
		WithCondition(cond).
		Build()
	if err != nil {
		fmt.Println(err)
	}
	input := &dynamodb.DeleteItemInput{
		Key: map[string]*dynamodb.AttributeValue{
			"Artist": {
				S: aws.String("No One You Know"),
			},
			"SongTitle": {
				S: aws.String("Scared of My Shadow"),
			},
		},
		ExpressionAttributeNames:  expr.Names(),
		ExpressionAttributeValues: expr.Values(),
		ConditionExpression:       expr.Condition(),
		TableName:                 aws.String("Music"),
	}
	result, err := svc.DeleteItem(input)
	if err != nil {
		if aerr, ok := err.(awserr.Error); ok {
			switch aerr.Code() {
			case dynamodb.ErrCodeConditionalCheckFailedException:
				fmt.Println(dynamodb.ErrCodeConditionalCheckFailedException, aerr.Error())
			case dynamodb.ErrCodeProvisionedThroughputExceededException:
				fmt.Println(dynamodb.ErrCodeProvisionedThroughputExceededException, aerr.Error())
			case dynamodb.ErrCodeResourceNotFoundException:
				fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error())
			case dynamodb.ErrCodeItemCollectionSizeLimitExceededException:
				fmt.Println(dynamodb.ErrCodeItemCollectionSizeLimitExceededException, aerr.Error())
			case dynamodb.ErrCodeInternalServerError:
				fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error())
			default:
				fmt.Println(aerr.Error())
			}
		} else {
			fmt.Println(err.Error())
		}
		return
	}
	fmt.Println(result)
}
func ExampleBuilder_WithCondition ( ) { svc := dynamodb . New ( session . New ( ) ) cond := expression . Name ( " " ) . LessThan ( expression . Value ( 7 ) ) expr , err := expression . NewBuilder ( ) . WithCondition ( cond ) . Build ( ) if err != nil { fmt . Println ( err ) } input := & dynamodb . DeleteItemInput { Key : map [ string ] * dynamodb . AttributeValue { " " : { S : aws . String ( " " ) , } , " " : { S : aws . String ( " " ) , } , } , ExpressionAttributeNames : expr . Names ( ) , ExpressionAttributeValues : expr . Values ( ) , ConditionExpression : expr . Condition ( ) , TableName : aws . String ( " " ) , } result , err := svc . DeleteItem ( input ) if err != nil { if aerr , ok := err . ( awserr . Error ) ; ok { switch aerr . Code ( ) { case dynamodb . ErrCodeConditionalCheckFailedException : fmt . Println ( dynamodb . ErrCodeConditionalCheckFailedException , aerr . Error ( ) ) case dynamodb . ErrCodeProvisionedThroughputExceededException : fmt . Println ( dynamodb . ErrCodeProvisionedThroughputExceededException , aerr . Error ( ) ) case dynamodb . ErrCodeResourceNotFoundException : fmt . Println ( dynamodb . ErrCodeResourceNotFoundException , aerr . Error ( ) ) case dynamodb . ErrCodeItemCollectionSizeLimitExceededException : fmt . Println ( dynamodb . ErrCodeItemCollectionSizeLimitExceededException , aerr . Error ( ) ) case dynamodb . ErrCodeInternalServerError : fmt . Println ( dynamodb . ErrCodeInternalServerError , aerr . Error ( ) ) default : fmt . Println ( aerr . Error ( ) ) } } else { fmt . Println ( err . Error ( ) ) } return } fmt . Println ( result ) }
Using Condition Expression
Using Condition Expression
// Create a condition where the Rating field must be less than 7. // Create a DynamoDB expression from the condition. // Use the built expression to populate the DeleteItem API operation with the // condition expression. // Print the error, cast err to awserr.Error to get the Code and // Message from an error.