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


Python statements.DeleteStatement类代码示例

本文整理汇总了Python中cassandra.cqlengine.statements.DeleteStatement的典型用法代码示例。如果您正苦于以下问题:Python DeleteStatement类的具体用法?Python DeleteStatement怎么用?Python DeleteStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: delete

    def delete(self):
        """ Deletes one instance """
        if self.instance is None:
            raise CQLEngineException("DML Query instance attribute is None")

        ds = DeleteStatement(self.column_family_name, timestamp=self._timestamp, conditionals=self._conditional, if_exists=self._if_exists)
        for name, col in self.model._primary_keys.items():
            val = getattr(self.instance, name)
            if val is None and not col.parition_key:
                continue
            ds.add_where(col, EqualsOperator(), val)
        self._execute(ds)
开发者ID:yzhang226,项目名称:python-driver,代码行数:12,代码来源:query.py

示例2: delete

    def delete(self):
        """ Deletes one instance """
        if self.instance is None:
            raise CQLEngineException("DML Query instance attribute is None")

        ds = DeleteStatement(self.column_family_name, timestamp=self._timestamp)
        for name, col in self.model._primary_keys.items():
            if (not col.partition_key) and (getattr(self.instance, name) is None):
                continue

            ds.add_where_clause(
                WhereClause(col.db_field_name, EqualsOperator(), col.to_database(getattr(self.instance, name)))
            )
        self._execute(ds)
开发者ID:pentve,项目名称:python-driver,代码行数:14,代码来源:query.py

示例3: test_context_update

    def test_context_update(self):
        ds = DeleteStatement('table', None)
        ds.add_field(MapDeleteClause('d', {1: 2}, {1: 2, 3: 4}))
        ds.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))

        ds.update_context_id(7)
        self.assertEqual(six.text_type(ds), 'DELETE "d"[%(8)s] FROM table WHERE "a" = %(7)s')
        self.assertEqual(ds.get_context(), {'7': 'b', '8': 3})
开发者ID:alejom99,项目名称:python-driver,代码行数:8,代码来源:test_delete_statement.py

示例4: _delete_null_columns

    def _delete_null_columns(self):
        """
        executes a delete query to remove columns that have changed to null
        """
        ds = DeleteStatement(self.column_family_name, if_exists=self._if_exists)
        deleted_fields = False
        for _, v in self.instance._values.items():
            col = v.column
            if v.deleted:
                ds.add_field(col.db_field_name)
                deleted_fields = True
            elif isinstance(col, columns.Map):
                uc = MapDeleteClause(col.db_field_name, v.value, v.previous_value)
                if uc.get_context_size() > 0:
                    ds.add_field(uc)
                    deleted_fields = True

        if deleted_fields:
            for name, col in self.model._primary_keys.items():
                ds.add_where_clause(WhereClause(
                    col.db_field_name,
                    EqualsOperator(),
                    col.to_database(getattr(self.instance, name))
                ))
            self._execute(ds)
开发者ID:iomedhealth,项目名称:python-driver,代码行数:25,代码来源:query.py

示例5: test_range_deletion_rendering

    def test_range_deletion_rendering(self):
        ds = DeleteStatement('table', None)
        ds.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
        ds.add_where_clause(WhereClause('created_at', GreaterThanOrEqualOperator(), '0'))
        ds.add_where_clause(WhereClause('created_at', LessThanOrEqualOperator(), '10'))
        self.assertEqual(six.text_type(ds), 'DELETE FROM table WHERE "a" = %(0)s AND "created_at" >= %(1)s AND "created_at" <= %(2)s', six.text_type(ds))

        ds = DeleteStatement('table', None)
        ds.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
        ds.add_where_clause(WhereClause('created_at', InOperator(), ['0', '10', '20']))
        self.assertEqual(six.text_type(ds), 'DELETE FROM table WHERE "a" = %(0)s AND "created_at" IN %(1)s', six.text_type(ds))
开发者ID:alejom99,项目名称:python-driver,代码行数:11,代码来源:test_delete_statement.py

示例6: test_context

 def test_context(self):
     ds = DeleteStatement('table', None)
     ds.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
     self.assertEqual(ds.get_context(), {'0': 'b'})
开发者ID:alejom99,项目名称:python-driver,代码行数:4,代码来源:test_delete_statement.py

示例7: test_where_clause_rendering

 def test_where_clause_rendering(self):
     ds = DeleteStatement('table', None)
     ds.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
     self.assertEqual(six.text_type(ds), 'DELETE FROM table WHERE "a" = %(0)s', six.text_type(ds))
开发者ID:alejom99,项目名称:python-driver,代码行数:4,代码来源:test_delete_statement.py

示例8: test_range_deletion_rendering

    def test_range_deletion_rendering(self):
        ds = DeleteStatement('table', None)
        ds.add_where(Column(db_field='a'), EqualsOperator(), 'b')
        ds.add_where(Column(db_field='created_at'), GreaterThanOrEqualOperator(), '0')
        ds.add_where(Column(db_field='created_at'), LessThanOrEqualOperator(), '10')
        self.assertEqual(six.text_type(ds), 'DELETE FROM table WHERE "a" = %(0)s AND "created_at" >= %(1)s AND "created_at" <= %(2)s', six.text_type(ds))

        ds = DeleteStatement('table', None)
        ds.add_where(Column(db_field='a'), EqualsOperator(), 'b')
        ds.add_where(Column(db_field='created_at'), InOperator(), ['0', '10', '20'])
        self.assertEqual(six.text_type(ds), 'DELETE FROM table WHERE "a" = %(0)s AND "created_at" IN %(1)s', six.text_type(ds))

        ds = DeleteStatement('table', None)
        ds.add_where(Column(db_field='a'), NotEqualsOperator(), 'b')
        self.assertEqual(six.text_type(ds), 'DELETE FROM table WHERE "a" != %(0)s', six.text_type(ds))
开发者ID:coldeasy,项目名称:python-driver,代码行数:15,代码来源:test_delete_statement.py

示例9: test_context

 def test_context(self):
     ds = DeleteStatement('table', None)
     ds.add_where(Column(db_field='a'), EqualsOperator(), 'b')
     self.assertEqual(ds.get_context(), {'0': 'b'})
开发者ID:coldeasy,项目名称:python-driver,代码行数:4,代码来源:test_delete_statement.py


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