__init__.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:cruddy 作者: Min-ops 项目源码 文件源码
def increment_counter(self, id, counter_name, increment=1,
                          id_name='id', **kwargs):
        """
        Atomically increments a counter attribute in the item identified by
        ``id``.  You must specify the name of the attribute as ``counter_name``
        and, optionally, the ``increment`` which defaults to ``1``.
        """
        response = self._new_response()
        if self._check_supported_op('increment_counter', response):
            params = {
                'Key': {id_name: id},
                'UpdateExpression': 'set #ctr = #ctr + :val',
                'ExpressionAttributeNames': {"#ctr": counter_name},
                'ExpressionAttributeValues': {
                    ':val': decimal.Decimal(increment)},
                'ReturnValues': 'UPDATED_NEW'
            }
            self._call_ddb_method(self.table.update_item, params, response)
            if response.status == 'success':
                if 'Attributes' in response.raw_response:
                    self._replace_decimals(response.raw_response)
                    attr = response.raw_response['Attributes'][counter_name]
                    response.data = attr
        response.prepare()
        return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号