本文整理汇总了Python中dynamo3.ItemUpdate.put方法的典型用法代码示例。如果您正苦于以下问题:Python ItemUpdate.put方法的具体用法?Python ItemUpdate.put怎么用?Python ItemUpdate.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dynamo3.ItemUpdate
的用法示例。
在下文中一共展示了ItemUpdate.put方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_condition_converts_eq_null
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_condition_converts_eq_null(self):
""" Conditional converts eq=None to null=True """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a'})
update = ItemUpdate.put('foo', set([1, 2]), eq=set())
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
update = ItemUpdate.put('foo', set([2]), eq=set())
with self.assertRaises(CheckFailed):
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
示例2: test_expect_condition
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_expect_condition(self):
""" Update can expect a field to meet a condition """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a', 'foo': 5})
update = ItemUpdate.put('foo', 10, lt=5)
with self.assertRaises(CheckFailed):
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
示例3: test_expect_condition_or
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_expect_condition_or(self):
""" Expected conditionals can be OR'd together """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a', 'foo': 5})
update = ItemUpdate.put('foo', 10, lt=5)
self.dynamo.update_item('foobar', {'id': 'a'}, [update],
expect_or=True, baz__null=True)
示例4: test_expect_not_exists_deprecated
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_expect_not_exists_deprecated(self):
""" Update can expect a field to not exist """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a', 'foo': 'bar'})
update = ItemUpdate.put('foo', 'baz', expected=None)
with self.assertRaises(CheckFailed):
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
示例5: test_expect_field_deprecated
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_expect_field_deprecated(self):
""" Update can expect a field to have a value """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a', 'foo': 'bar'})
update = ItemUpdate.put('foo', 'baz', expected='wat')
with self.assertRaises(CheckFailed):
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
示例6: test_return_item
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_return_item(self):
""" Update can return the updated item """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a'})
ret = self.dynamo.update_item('foobar', {'id': 'a'},
[ItemUpdate.put('foo', 'bar')],
returns=ALL_NEW)
self.assertEqual(ret, {'id': 'a', 'foo': 'bar'})
示例7: test_update_field
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_update_field(self):
""" Update an item field """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a'})
self.dynamo.update_item('foobar', {'id': 'a'},
[ItemUpdate.put('foo', 'bar')])
item = list(self.dynamo.scan('foobar'))[0]
self.assertEqual(item, {'id': 'a', 'foo': 'bar'})
示例8: test_write_converts_none
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_write_converts_none(self):
""" Write operation converts None values to a DELETE """
hash_key = DynamoKey('id', data_type=STRING)
self.dynamo.create_table('foobar', hash_key=hash_key)
self.dynamo.put_item('foobar', {'id': 'a', 'foo': 'bar'})
update = ItemUpdate.put('foo', None)
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
ret = list(self.dynamo.scan('foobar'))
self.assertItemsEqual(ret, [{'id': 'a'}])
示例9: test_sync_only_updates_changed
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_sync_only_updates_changed(self):
""" Sync only updates fields that have been changed """
with patch.object(self.engine, 'dynamo') as dynamo:
captured_updates = []
def update_item(_, __, updates, *___, **____):
""" Mock update_item and capture the passed updateds """
captured_updates.extend(updates)
return {}
dynamo.update_item.side_effect = update_item
p = Post('a', 'b', 4)
self.engine.save(p)
p.foobar = set('a')
p.points = Decimal('2')
p.sync(raise_on_conflict=False)
self.assertEqual(len(captured_updates), 2)
self.assertTrue(ItemUpdate.put('foobar', ANY) in captured_updates)
self.assertTrue(ItemUpdate.put('points', ANY) in captured_updates)
示例10: test_return_metadata
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_return_metadata(self):
""" The Update return value contains capacity metadata """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a'})
ret = self.dynamo.update_item('foobar', {'id': 'a'},
[ItemUpdate.put('foo', 'bar')],
returns=ALL_NEW,
return_capacity=TOTAL)
self.assertTrue(is_number(ret.capacity))
self.assertTrue(is_number(ret.table_capacity))
self.assertTrue(isinstance(ret.indexes, dict))
self.assertTrue(isinstance(ret.global_indexes, dict))
示例11: test_item_update_eq
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_item_update_eq(self):
""" ItemUpdates should be equal """
a, b = ItemUpdate.put('foo', 'bar'), ItemUpdate.put('foo', 'bar')
self.assertEqual(a, b)
self.assertEqual(hash(a), hash(b))
self.assertFalse(a != b)
示例12: test_expect_dupe_fail2
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_expect_dupe_fail2(self):
""" Update cannot expect a field to meet multiple constraints """
self.make_table()
update = ItemUpdate.put('foo', 10, lt=5)
with self.assertRaises(ValueError):
self.dynamo.update_item('foobar', {'id': 'a'}, [update], foo__gt=1)
示例13: test_expect_dupe_fail
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def test_expect_dupe_fail(self):
""" Update cannot expect a field to meet multiple constraints """
self.make_table()
with self.assertRaises(ValueError):
update = ItemUpdate.put('foo', 10, lt=5, gt=1)
示例14: sync
# 需要导入模块: from dynamo3 import ItemUpdate [as 别名]
# 或者: from dynamo3.ItemUpdate import put [as 别名]
def sync(self, items, raise_on_conflict=None, consistent=False, constraints=None):
"""
Sync model changes back to database
This will push any updates to the database, and ensure that all of the
synced items have the most up-to-date data.
Parameters
----------
items : list or :class:`~flywheel.models.Model`
Models to sync
raise_on_conflict : bool, optional
If True, raise exception if any of the fields that are being
updated were concurrently changed in the database (default set by
:attr:`.default_conflict`)
consistent : bool, optional
If True, force a consistent read from the db. This will only take
effect if the sync is only performing a read. (default False)
constraints : list, optional
List of more complex constraints that must pass for the update to
complete. Must be used with raise_on_conflict=True. Format is the
same as query filters (e.g. Model.fieldname > 5)
Raises
------
exc : :class:`dynamo3.CheckFailed`
If raise_on_conflict=True and the model changed underneath us
"""
if raise_on_conflict is None:
raise_on_conflict = self.default_conflict in ('update', 'raise')
if constraints is not None and not raise_on_conflict:
raise ValueError("Cannot pass constraints to sync() when raise_on_conflict is False")
if isinstance(items, Model):
items = [items]
refresh_models = []
for item in items:
# Look for any mutable fields (e.g. sets) that have changed
for name in item.keys_():
if name in item.__dirty__ or name in item.__incrs__:
continue
field = item.meta_.fields.get(name)
if field is None:
value = item.get_(name)
if Field.is_overflow_mutable(value):
if value != item.cached_(name):
item.__dirty__.add(name)
elif field.is_mutable:
cached_var = item.cached_(name)
if field.resolve(item) != cached_var:
for related in item.meta_.related_fields[name]:
item.__dirty__.add(related)
if not item.__dirty__ and not item.__incrs__:
refresh_models.append(item)
continue
fields = item.__dirty__
item.pre_save_(self)
# If the model has changed any field that is part of a composite
# field, FORCE the sync to raise on conflict. This prevents the
# composite key from potentially getting into an inconsistent state
_raise_on_conflict = raise_on_conflict
for name in itertools.chain(item.__incrs__, fields):
for related_name in item.meta_.related_fields.get(name, []):
field = item.meta_.fields[related_name]
if field.composite:
_raise_on_conflict = True
break
keywords = {}
constrained_fields = set()
if _raise_on_conflict and constraints is not None:
for constraint in constraints:
constrained_fields.update(constraint.eq_fields.keys())
constrained_fields.update(constraint.fields.keys())
keywords.update(constraint.scan_kwargs())
updates = []
# Set dynamo keys
for name in fields:
field = item.meta_.fields.get(name)
value = getattr(item, name)
kwargs = {}
if _raise_on_conflict and name not in constrained_fields:
kwargs = {'eq': item.ddb_dump_cached_(name)}
update = ItemUpdate.put(name, item.ddb_dump_field_(name),
**kwargs)
updates.append(update)
# Atomic increment fields
for name, value in six.iteritems(item.__incrs__):
kwargs = {}
# We don't need to ddb_dump because we know they're all native
if isinstance(value, SetDelta):
update = ItemUpdate(value.action, name, value.values)
else:
update = ItemUpdate.add(name, value)
updates.append(update)
#.........这里部分代码省略.........