Amazon web services dynamodb:有条件地创建/更新项并返回当前值

Amazon web services dynamodb:有条件地创建/更新项并返回当前值,amazon-web-services,go,amazon-dynamodb,Amazon Web Services,Go,Amazon Dynamodb,在dynamoDB中是否可以有条件地创建/更新项并返回其当前值 在下面我们有三种状态,一种是用户还不在表中,一种是用户在表中但没有CreatedAt字段,另一种是用户存在并有CreatedAt字段 out, err := db.UpdateItem(&dynamodb.UpdateItemInput{ TableName: aws.String("User"), Key: map[string]*dynamodb.AttributeValue{ "ID": {S: aws

在dynamoDB中是否可以有条件地创建/更新项并返回其当前值

在下面我们有三种状态,一种是用户还不在表中,一种是用户在表中但没有CreatedAt字段,另一种是用户存在并有CreatedAt字段

out, err := db.UpdateItem(&dynamodb.UpdateItemInput{
  TableName: aws.String("User"),
  Key: map[string]*dynamodb.AttributeValue{
    "ID": {S: aws.String(u.ID)},
  },
  ExpressionAttributeNames: map[string]*string{
    "#c": aws.String("CreatedAt"),
  },
  ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{
    ":c": {S: aws.String(u.CreatedAt.Format(time.RFC3339))},
  }
  ConditionExpression: aws.String("attribute_not_exists(#c)"),
  UpdateExpression:    aws.String("SET #c = :c"),
  ReturnValues:        aws.String("ALL_NEW"),
})
if isConditionError(err) {
  // out.Attributes == nil
  // .: out.Attributes["CreatedAt"] == ""
}
当用户不存在时,将按预期创建用户

当用户没有CreatedAt字段时,它会按预期添加该字段

当条件失败时(即用户有CreatedAt的值),我想知道数据库在CreatedAt字段中对该用户说了什么。不幸的是,不管我是为returnValue指定ALL_NEW还是ALL_OLD,out.Attributes总是为nil

我想避免两次调用数据库来获取这些信息,因为我知道dynamo正在读取这些信息来评估情况,所以我认为这是合理的。我该怎么做