当前位置: 首页>>代码示例>>Python>>正文


Python Item.prepare_full方法代码示例

本文整理汇总了Python中boto.dynamodb2.items.Item.prepare_full方法的典型用法代码示例。如果您正苦于以下问题:Python Item.prepare_full方法的具体用法?Python Item.prepare_full怎么用?Python Item.prepare_full使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto.dynamodb2.items.Item的用法示例。


在下文中一共展示了Item.prepare_full方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: flush

# 需要导入模块: from boto.dynamodb2.items import Item [as 别名]
# 或者: from boto.dynamodb2.items.Item import prepare_full [as 别名]
    def flush(self):
        batch_data = {
            self.table.table_name: [
                # We'll insert data here shortly.
            ],
        }

        for put in self._to_put:
            item = Item(self.table, data=put)
            batch_data[self.table.table_name].append({
                'PutRequest': {
                    'Item': item.prepare_full(),
                }
            })

        for delete in self._to_delete:
            batch_data[self.table.table_name].append({
                'DeleteRequest': {
                    'Key': self.table._encode_keys(delete),
                }
            })

        resp = self.table.connection.batch_write_item(batch_data)
        self.handle_unprocessed(resp)

        self._to_put = []
        self._to_delete = []
        return True
开发者ID:YongMan,项目名称:boto,代码行数:30,代码来源:table.py

示例2: save

# 需要导入模块: from boto.dynamodb2.items import Item [as 别名]
# 或者: from boto.dynamodb2.items.Item import prepare_full [as 别名]
    def save(self, items, overwrite=None):
        """
        Save models to dynamo

        Parameters
        ----------
        items : list or :class:`~flywheel.models.Model`
        overwrite : bool, optional
            If False, raise exception if item already exists (default set by
            :attr:`.default_conflict`)

        Raises
        ------
        exc : :class:`boto.dynamodb2.exceptions.ConditionalCheckFailedException`
            If overwrite is False and an item already exists in the database

        Notes
        -----
        Overwrite will replace the *entire* item with the new one, not just
        different fields. After calling save(overwrite=True) you are guaranteed
        that the item in the database is exactly the item you saved.

        Due to the structure of the AWS API, saving with overwrite=True is much
        faster because the requests can be batched.

        """
        if overwrite is None:
            overwrite = self.default_conflict in ('update', 'overwrite')
        if isinstance(items, Model):
            items = [items]
        if not items:
            return
        tables = defaultdict(list)
        for item in items:
            tables[item.meta_.ddb_tablename].append(item)
        for tablename, items in tables.iteritems():
            table = Table(tablename, connection=self.dynamo)
            if overwrite:
                with table.batch_write() as batch:
                    for item in items:
                        item.pre_save_(self)
                        batch.put_item(data=item.ddb_dump_())
                        item.post_save_()
            else:
                for item in items:
                    expected = {}
                    for name in item.meta_.fields:
                        expected[name] = {
                            'Exists': False,
                        }
                    item.pre_save_(self)
                    boto_item = Item(table, data=item.ddb_dump_())
                    self.dynamo.put_item(tablename, boto_item.prepare_full(),
                                         expected=expected)
                    item.post_save_()
开发者ID:hoov,项目名称:flywheel,代码行数:57,代码来源:engine.py

示例3: flush

# 需要导入模块: from boto.dynamodb2.items import Item [as 别名]
# 或者: from boto.dynamodb2.items.Item import prepare_full [as 别名]
    def flush(self):
        batch_data = {
            self.table.table_name: [
                # We'll insert data here shortly.
            ],
        }

        for put in self._to_put:
            item = Item(self.table, data=put)
            batch_data[self.table.table_name].append({
                'PutRequest': {
                    'Item': item.prepare_full(),
                }
            })

        for delete in self._to_delete:
            batch_data[self.table.table_name].append({
                'DeleteRequest': {
                    'Key': self.table._encode_keys(delete),
                }
            })
            
        
        response = self.table.connection.batch_write_item(batch_data)
        self._to_put = []
        self._to_delete = []
        
        # handle unprocessed items
        unprocessed = response.get('UnprocessedItems', None)
        if unprocessed:
            unprocessed_list = unprocessed[self.table.table_name]
            item = Item(self)
            for u in unprocessed_list:
                if u.has_key("PutRequest"):
                    item.load({
                        'Item': u['PutRequest']['Item'],
                    })
                    self._to_put.append(item._data)
                elif u.has_key("DeleteRequest"):
                    item.load({
                        'Item': u['DeleteRequest']['Key'],
                    })
                    self._to_delete.append(item._data)
                else:
                    raise Exception("Error respond")
        return True
开发者ID:MingChenSlot,项目名称:SelfScalingBenchmarkForDynamoDB,代码行数:48,代码来源:BatchTable.py

示例4: flush

# 需要导入模块: from boto.dynamodb2.items import Item [as 别名]
# 或者: from boto.dynamodb2.items.Item import prepare_full [as 别名]
    def flush(self):
        batch_data = {
            self.table.table_name: [
                # We'll insert data here shortly.
            ]
        }

        for put in self._to_put:
            item = Item(self.table, data=put)
            batch_data[self.table.table_name].append({"PutRequest": {"Item": item.prepare_full()}})

        for delete in self._to_delete:
            batch_data[self.table.table_name].append({"DeleteRequest": {"Key": self.table._encode_keys(delete)}})

        self.table.connection.batch_write_item(batch_data)
        self._to_put = []
        self._to_delete = []
        return True
开发者ID:9seconds,项目名称:boto,代码行数:20,代码来源:table.py


注:本文中的boto.dynamodb2.items.Item.prepare_full方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。