MCPcopy Index your code
hub / github.com/apache/cassandra-python-driver / DeleteStatement

Class DeleteStatement

cassandra/cqlengine/statements.py:840–907  ·  view source on GitHub ↗

a cql delete statement

Source from the content-addressed store, hash-verified

838
839
840class DeleteStatement(BaseCQLStatement):
841 """ a cql delete statement """
842
843 def __init__(self, table, fields=None, where=None, timestamp=None, conditionals=None, if_exists=False):
844 super(DeleteStatement, self).__init__(
845 table,
846 where=where,
847 timestamp=timestamp,
848 conditionals=conditionals
849 )
850 self.fields = []
851 if isinstance(fields, str):
852 fields = [fields]
853 for field in fields or []:
854 self.add_field(field)
855
856 self.if_exists = if_exists
857
858 def update_context_id(self, i):
859 super(DeleteStatement, self).update_context_id(i)
860 for field in self.fields:
861 field.set_context_id(self.context_counter)
862 self.context_counter += field.get_context_size()
863 for t in self.conditionals:
864 t.set_context_id(self.context_counter)
865 self.context_counter += t.get_context_size()
866
867 def get_context(self):
868 ctx = super(DeleteStatement, self).get_context()
869 for field in self.fields:
870 field.update_context(ctx)
871 for clause in self.conditionals:
872 clause.update_context(ctx)
873 return ctx
874
875 def add_field(self, field):
876 if isinstance(field, str):
877 field = FieldDeleteClause(field)
878 if not isinstance(field, BaseClause):
879 raise StatementException("only instances of AssignmentClause can be added to statements")
880 field.set_context_id(self.context_counter)
881 self.context_counter += field.get_context_size()
882 self.fields.append(field)
883
884 def __unicode__(self):
885 qs = ['DELETE']
886 if self.fields:
887 qs += [', '.join(['{0}'.format(f) for f in self.fields])]
888 qs += ['FROM', self.table]
889
890 delete_option = []
891
892 if self.timestamp:
893 delete_option += ["TIMESTAMP {0}".format(self.timestamp_normalized)]
894
895 if delete_option:
896 qs += [" USING {0} ".format(" AND ".join(delete_option))]
897

Callers 15

test_field_renderingMethod · 0.90
test_table_renderingMethod · 0.90
test_context_updateMethod · 0.90
test_contextMethod · 0.90
deleteMethod · 0.90

Calls

no outgoing calls