简体   繁体   English

Boto3 更新多个值

[英]Boto3 updating multiple values

in the boto3 documentation updating an item is described by this example:在 boto3 文档中更新一个项目是由这个例子描述的:

table.update_item(
    Key={
        'username': 'janedoe',
        'last_name': 'Doe'
    },
    UpdateExpression='SET age = :val1',
    ExpressionAttributeValues={
        ':val1': 26
    }
)

But what am i supposed to do, if i want to update several values of the item.但是,如果我想更新该项目的多个值,我该怎么办。 I couldn't find any information on this.我找不到这方面的任何信息。 Can anybody help?有人可以帮忙吗? Thank you!谢谢!

EDIT:编辑:

Ok, it seems to work like this, can anybody confirm wether this is the right way.好的,它似乎是这样工作的,任何人都可以确认这是正确的方法。 Just to be sure i'm not doing anything totally wrong here.只是为了确保我在这里没有做任何完全错误的事情。

table.update_item(
                    Key={
                        'id': item['id']
                    },
                    UpdateExpression='SET value1 = :val1, value2 = :val2',
                    ExpressionAttributeValues={
                        ':val1': someValue1,
                        ':val2': someValue2
                    }
                )

Thanks!谢谢!

Yes, that's the way to do.是的,这就是方法。 Even many actions can be done in single expression as shown here .甚至许多动作可以在单一的表达来完成如图所示这里 For ex: multiple 'PUT' and 'DELETE' in single expression.例如:单个表达式中的多个“PUT”和“DELETE”。

显示文档示例的快照

For others finding this, theres a library you can use to help with the weird boto3 stuff like ExpressionAttributeValues .对于发现此问题的其他人,您可以使用一个库来帮助处理奇怪的 boto3 内容,例如ExpressionAttributeValues This way you can make normal developer/human calls.通过这种方式,您可以进行正常的开发人员/人工调用。

https://github.com/rayepps/dynamof https://github.com/rayepps/dynamof

db(update(
  table_name='users',
  key={ 'id': item['id'] },
  attributes={
      'age': 26,
      'name': 'Carl'
  }))

disclaimer: I wrote it免责声明:我写的

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

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