本文整理汇总了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
示例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_()
示例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
示例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