简体   繁体   English

从 dynamoDB 返回更新的项目

[英]Returning updated item from dynamoDB

I am using the dynamoDB ExpressionSpecBuilder (Java) to create my update query for an item in the database.我正在使用 dynamoDB ExpressionSpecBuilder (Java) 为数据库中的项目创建更新查询。 I would like the entire modified resource to be returned, without having to specify all attributes inidividually.我希望返回整个修改后的资源,而不必单独指定所有属性。

Is there a way to do that?有没有办法做到这一点?

If you are forced to use ExpressionSpecBuilder I couldn't find any way.如果您被迫使用ExpressionSpecBuilder ,我找不到任何方法。

However, there are other alternatives like UpdateItemRequest where you can set the ReturnValues property to ALL_NEW and get all attributes as a map:但是,还有其他替代方法,例如UpdateItemRequest ,您可以在其中将ReturnValues属性设置为ALL_NEW并将所有属性获取为 map:

UpdateItemRequest updateProgramCounterRequest = new UpdateItemRequest()
   .withTableName(...)
   .withUpdateExpression(...)
   .withReturnValues(ReturnValue.ALL_NEW);

UpdateItemResult updateItemResult = amazonDynamoDB.updateItem(updateItemRequest);
Map<String, AttributeValue> attributes = updateItemResult.getAttributes();

Then you can map them to your resource.然后你可以 map 他们到你的资源。

A higher level approach is using DynamoDBMapper.更高级别的方法是使用 DynamoDBMapper。 Depending on the type of update you need to do, you may also be able to achieve it using save method and modifying the DynamoDBMapperConfig.SaveBehavior property as described on javadoc: https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/datamodeling/DynamoDBMapper.html#save-T-com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression-com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig-根据您需要执行的更新类型,您也可以使用save方法并修改DynamoDBMapperConfig.SaveBehavior属性来实现它,如 javadoc 中所述: https://docs.aws.amazon.com/AWSJavaSDK/latest/ javadoc/com/amazonaws/services/dynamodbv2/datamodeling/DynamoDBMapper.html#save-T-com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression-com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM