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

	// Create an update to set two fields in the table.
	update := expression.Set(
		expression.Name("Year"),
		expression.Value(2015),
	).Set(
		expression.Name("AlbumTitle"),
		expression.Value("Louder Than Ever"),
	)

	// Create the DynamoDB expression from the Update.
	expr, err := expression.NewBuilder().
		WithUpdate(update).
		Build()

	// Use the built expression to populate the DynamoDB UpdateItem API
	// input parameters.
	input := &dynamodb.UpdateItemInput{
		ExpressionAttributeNames:  expr.Names(),
		ExpressionAttributeValues: expr.Values(),
		Key: map[string]*dynamodb.AttributeValue{
			"Artist": {
				S: aws.String("Acme Band"),
			},
			"SongTitle": {
				S: aws.String("Happy Day"),
			},
		},
		ReturnValues:     aws.String("ALL_NEW"),
		TableName:        aws.String("Music"),
		UpdateExpression: expr.Update(),
	}

	result, err := svc.UpdateItem(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 Update Expression
//
// This example updates an item in the Music table. It adds a new attribute (Year) and
// modifies the AlbumTitle attribute.  All of the attributes in the item, as they appear
// after the update, are returned in the response.
Using Update Expression

This example updates an item in the Music table. It adds a new attribute (Year) and
modifies the AlbumTitle attribute.  All of the attributes in the item, as they appear
after the update, are returned in the response.
// Using Update Expression // // This example updates an item in the Music table . It adds a new attribute ( Year ) and // modifies the AlbumTitle attribute . All of the attributes in the item as they appear // after the update are returned in the response .
func ExampleBuilder_WithUpdate() {
	svc := dynamodb.New(session.New())
	update := expression.Set(
		expression.Name("Year"),
		expression.Value(2015),
	).Set(
		expression.Name("AlbumTitle"),
		expression.Value("Louder Than Ever"),
	)
	expr, err := expression.NewBuilder().
		WithUpdate(update).
		Build()
	input := &dynamodb.UpdateItemInput{
		ExpressionAttributeNames:  expr.Names(),
		ExpressionAttributeValues: expr.Values(),
		Key: map[string]*dynamodb.AttributeValue{
			"Artist": {
				S: aws.String("Acme Band"),
			},
			"SongTitle": {
				S: aws.String("Happy Day"),
			},
		},
		ReturnValues:     aws.String("ALL_NEW"),
		TableName:        aws.String("Music"),
		UpdateExpression: expr.Update(),
	}
	result, err := svc.UpdateItem(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_WithUpdate ( ) { svc := dynamodb . New ( session . New ( ) ) update := expression . Set ( expression . Name ( " " ) , expression . Value ( 2015 ) , ) . Set ( expression . Name ( " " ) , expression . Value ( " " ) , ) expr , err := expression . NewBuilder ( ) . WithUpdate ( update ) . Build ( ) input := & dynamodb . UpdateItemInput { ExpressionAttributeNames : expr . Names ( ) , ExpressionAttributeValues : expr . Values ( ) , Key : map [ string ] * dynamodb . AttributeValue { " " : { S : aws . String ( " " ) , } , " " : { S : aws . String ( " " ) , } , } , ReturnValues : aws . String ( " " ) , TableName : aws . String ( " " ) , UpdateExpression : expr . Update ( ) , } result , err := svc . UpdateItem ( 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 Update Expression
Using Update Expression
// Create an update to set two fields in the table. // Create the DynamoDB expression from the Update. // Use the built expression to populate the DynamoDB UpdateItem API // input parameters. // Print the error, cast err to awserr.Error to get the Code and // Message from an error.