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


Python UpdateStatement.add_where_clause方法代码示例

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


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

示例1: test_context_update

# 需要导入模块: from cassandra.cqlengine.statements import UpdateStatement [as 别名]
# 或者: from cassandra.cqlengine.statements.UpdateStatement import add_where_clause [as 别名]
 def test_context_update(self):
     us = UpdateStatement('table')
     us.add_assignment_clause(AssignmentClause('a', 'b'))
     us.add_assignment_clause(AssignmentClause('c', 'd'))
     us.add_where_clause(WhereClause('a', EqualsOperator(), 'x'))
     us.update_context_id(3)
     self.assertEqual(six.text_type(us), 'UPDATE table SET "a" = %(4)s, "c" = %(5)s WHERE "a" = %(3)s')
     self.assertEqual(us.get_context(), {'4': 'b', '5': 'd', '3': 'x'})
开发者ID:dkua,项目名称:python-driver,代码行数:10,代码来源:test_update_statement.py

示例2: update

# 需要导入模块: from cassandra.cqlengine.statements import UpdateStatement [as 别名]
# 或者: from cassandra.cqlengine.statements.UpdateStatement import add_where_clause [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))
        # 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)

        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_clause(WhereClause(
                    col.db_field_name,
                    EqualsOperator(),
                    col.to_database(getattr(self.instance, name))
                ))
            self._execute(statement)

        if not null_clustering_key:
            self._delete_null_columns()
开发者ID:alejom99,项目名称:python-driver,代码行数:50,代码来源:query.py

示例3: update

# 需要导入模块: from cassandra.cqlengine.statements import UpdateStatement [as 别名]
# 或者: from cassandra.cqlengine.statements.UpdateStatement import add_where_clause [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,
                                    transactions=self._transaction, 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))
        # 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
                if isinstance(col, (columns.BaseContainerColumn, columns.Counter)):
                    # get appropriate clause
                    if isinstance(col, columns.List):
                        klass = ListUpdateClause
                    elif isinstance(col, columns.Map):
                        klass = MapUpdateClause
                    elif isinstance(col, columns.Set):
                        klass = SetUpdateClause
                    elif isinstance(col, columns.Counter):
                        klass = CounterUpdateClause
                    else:
                        raise RuntimeError

                    clause = klass(col.db_field_name, val,
                                   previous=val_mgr.previous_value, column=col)
                    if clause.get_context_size() > 0:
                        statement.add_assignment_clause(clause)
                else:
                    statement.add_assignment_clause(AssignmentClause(
                        col.db_field_name,
                        col.to_database(val)
                    ))

        if statement.get_context_size() > 0 or self.instance._has_counter:
            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_clause(WhereClause(
                    col.db_field_name,
                    EqualsOperator(),
                    col.to_database(getattr(self.instance, name))
                ))
            self._execute(statement)

        if not null_clustering_key:
            self._delete_null_columns()
开发者ID:iomedhealth,项目名称:python-driver,代码行数:71,代码来源:query.py

示例4: test_additional_rendering

# 需要导入模块: from cassandra.cqlengine.statements import UpdateStatement [as 别名]
# 或者: from cassandra.cqlengine.statements.UpdateStatement import add_where_clause [as 别名]
 def test_additional_rendering(self):
     us = UpdateStatement('table', ttl=60)
     us.add_assignment_clause(AssignmentClause('a', 'b'))
     us.add_where_clause(WhereClause('a', EqualsOperator(), 'x'))
     self.assertIn('USING TTL 60', six.text_type(us))
开发者ID:dkua,项目名称:python-driver,代码行数:7,代码来源:test_update_statement.py

示例5: test_context

# 需要导入模块: from cassandra.cqlengine.statements import UpdateStatement [as 别名]
# 或者: from cassandra.cqlengine.statements.UpdateStatement import add_where_clause [as 别名]
 def test_context(self):
     us = UpdateStatement('table')
     us.add_assignment_clause(AssignmentClause('a', 'b'))
     us.add_assignment_clause(AssignmentClause('c', 'd'))
     us.add_where_clause(WhereClause('a', EqualsOperator(), 'x'))
     self.assertEqual(us.get_context(), {'0': 'b', '1': 'd', '2': 'x'})
开发者ID:dkua,项目名称:python-driver,代码行数:8,代码来源:test_update_statement.py

示例6: test_rendering

# 需要导入模块: from cassandra.cqlengine.statements import UpdateStatement [as 别名]
# 或者: from cassandra.cqlengine.statements.UpdateStatement import add_where_clause [as 别名]
 def test_rendering(self):
     us = UpdateStatement('table')
     us.add_assignment_clause(AssignmentClause('a', 'b'))
     us.add_assignment_clause(AssignmentClause('c', 'd'))
     us.add_where_clause(WhereClause('a', EqualsOperator(), 'x'))
     self.assertEqual(six.text_type(us), 'UPDATE table SET "a" = %(0)s, "c" = %(1)s WHERE "a" = %(2)s', six.text_type(us))
开发者ID:dkua,项目名称:python-driver,代码行数:8,代码来源:test_update_statement.py


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