使用Swift 3在DynamoDB中保留关键字ExpressionAttributeValues [英] reserved keyword ExpressionAttributeValues in DynamoDB using Swift 3

查看:133
本文介绍了使用Swift 3在DynamoDB中保留关键字ExpressionAttributeValues的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够在没有:status的情况下得到响应:接受表达式属性值,但是有了它,当我在projectionExpression行中使用#status时,会出现以下错误(状态是DynamoDB中的保留字,因此我有在每个 https://stackoverflow.com/a/45952329/5921575 )上添加井号标签:

I am able to get a response without the :status : accept expression attribute value but with it, I get the following error when I am using the #status in the projectionExpression line (status is a reserved word in DynamoDB so I had to add hashtag there per https://stackoverflow.com/a/45952329/5921575):

Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=0 "(null)" 
UserInfo={__type=com.amazon.coral.validate#ValidationException, 
message=Value provided in ExpressionAttributeValues unused in expressions: keys: {:status}}

这里是代码:

queryExpression.keyConditionExpression = "#userId= :userId"
queryExpression.expressionAttributeNames = ["#userId":"userId", "#status":"status"]
queryExpression.expressionAttributeValues = [":userId":userID, ":status":"accept"]
queryExpression.projectionExpression = "#status"

我可以不用:status: accept但我不想得到一个许多没有接受价值的物品。我在此链接或stackoverflow上的任何地方都找不到答案:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html

I can go without the ":status":"accept" but I do not want to get a lot of items that do not have the accept value. I can't find an answer in this link or anywhere on stackoverflow: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html

谢谢!

推荐答案

有点晚了,但是:您的投影表达式不应为 #status,而应为非状态字。状态是保留字,因此请勿将其用于投影表达式。有关需要使用保留字的处理方法,请参见此处的文档: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html#Expressions.ExpressionAttributeNames.ReservedWords

A bit late, but: Your projection expression should not be "#status" but another word that isn't status. Status is the reserved word, so don't use that for the projection expression. See here for docs on what to do when you need to use a reserved word: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html#Expressions.ExpressionAttributeNames.ReservedWords

userId不需要投影表达式,因为它不是保留字。请参阅此处以获取保留字的列表: https://docs.aws .amazon.com / amazondynamodb / latest / developerguide / ReservedWords.html

userId, on the other hand, does not require a projection expression because it is not a reserved word. See here for a list of reserved words: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html

但是,您不需要投影表达式。您可以简单地使用下面的代码。定义 queryExpression.expressionAttributeNames以创建状态属性值的替代名称。在这里,我用短语 statusVal代替。

However, you don't need a projection expression. You can simply use the code below. Define "queryExpression.expressionAttributeNames" to create a substitute name for the status attribute value. Here, I used the phrase "statusVal" as a substitute.

尝试一下。 (对我有用)

Try this. (It worked for me)

let queryExpression = AWSDynamoDBQueryExpression()
queryExpression.expressionAttributeNames = ["#statusVal":"status"] // Using statusVal because it is not reserved. You only need statusVal here because it is the only attribute that also happens to be an AWS reserved word.
queryExpression.keyConditionExpression = "userId = :uId AND #statusVal = :sV"
queryExpression.expressionAttributeValues = [
     ":uId" : String(describing: userId),
     ":sV" : "accept"]

然后使用AWSDynamoDBObjectMapper执行操作!祝你好运!

And then perform the operation using AWSDynamoDBObjectMapper! Good luck!

这篇关于使用Swift 3在DynamoDB中保留关键字ExpressionAttributeValues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆