本文整理汇总了Python中cassandra.cqlengine.statements.UpdateStatement.add_update方法的典型用法代码示例。如果您正苦于以下问题:Python UpdateStatement.add_update方法的具体用法?Python UpdateStatement.add_update怎么用?Python UpdateStatement.add_update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.cqlengine.statements.UpdateStatement
的用法示例。
在下文中一共展示了UpdateStatement.add_update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from cassandra.cqlengine.statements import UpdateStatement [as 别名]
# 或者: from cassandra.cqlengine.statements.UpdateStatement import add_update [as 别名]
def update(self):
"""
updates a row.
This is a blind update call.
All validation and cleaning needs to happen
prior to calling this.
"""
if self.instance is None:
raise CQLEngineException("DML Query intance attribute is None")
assert type(self.instance) == self.model
null_clustering_key = False if len(self.instance._clustering_keys) == 0 else True
static_changed_only = True
statement = UpdateStatement(self.column_family_name, ttl=self._ttl, timestamp=self._timestamp,
conditionals=self._conditional, if_exists=self._if_exists)
for name, col in self.instance._clustering_keys.items():
null_clustering_key = null_clustering_key and col._val_is_null(getattr(self.instance, name, None))
updated_columns = set()
# get defined fields and their column names
for name, col in self.model._columns.items():
# if clustering key is null, don't include non static columns
if null_clustering_key and not col.static and not col.partition_key:
continue
if not col.is_primary_key:
val = getattr(self.instance, name, None)
val_mgr = self.instance._values[name]
if val is None:
continue
if not val_mgr.changed and not isinstance(col, columns.Counter):
continue
static_changed_only = static_changed_only and col.static
statement.add_update(col, val, previous=val_mgr.previous_value)
updated_columns.add(col.db_field_name)
if statement.assignments:
for name, col in self.model._primary_keys.items():
# only include clustering key if clustering key is not null, and non static columns are changed to avoid cql error
if (null_clustering_key or static_changed_only) and (not col.partition_key):
continue
statement.add_where(col, EqualsOperator(), getattr(self.instance, name))
self._execute(statement)
if not null_clustering_key:
# remove conditions on fields that have been updated
delete_conditionals = [condition for condition in self._conditional
if condition.field not in updated_columns] if self._conditional else None
self._delete_null_columns(delete_conditionals)
示例2: test_update_empty_set_removal_does_not_assign
# 需要导入模块: from cassandra.cqlengine.statements import UpdateStatement [as 别名]
# 或者: from cassandra.cqlengine.statements.UpdateStatement import add_update [as 别名]
def test_update_empty_set_removal_does_not_assign(self):
us = UpdateStatement('table')
us.add_update(Set(Text, db_field='a'), set(), 'remove')
self.assertFalse(us.assignments)
示例3: test_update_list_append_with_empty_list
# 需要导入模块: from cassandra.cqlengine.statements import UpdateStatement [as 别名]
# 或者: from cassandra.cqlengine.statements.UpdateStatement import add_update [as 别名]
def test_update_list_append_with_empty_list(self):
us = UpdateStatement('table')
us.add_update(List(Text, db_field='a'), [], 'append')
self.assertFalse(us.assignments)
示例4: test_update_set_add
# 需要导入模块: from cassandra.cqlengine.statements import UpdateStatement [as 别名]
# 或者: from cassandra.cqlengine.statements.UpdateStatement import add_update [as 别名]
def test_update_set_add(self):
us = UpdateStatement('table')
us.add_update(Set(Text, db_field='a'), set((1,)), 'add')
self.assertEqual(six.text_type(us), 'UPDATE table SET "a" = "a" + %(0)s')