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

Class InsertStatement

cassandra/cqlengine/statements.py:721–762  ·  view source on GitHub ↗

an cql insert statement

Source from the content-addressed store, hash-verified

719
720
721class InsertStatement(AssignmentStatement):
722 """ an cql insert statement """
723
724 def __init__(self,
725 table,
726 assignments=None,
727 where=None,
728 ttl=None,
729 timestamp=None,
730 if_not_exists=False):
731 super(InsertStatement, self).__init__(table,
732 assignments=assignments,
733 where=where,
734 ttl=ttl,
735 timestamp=timestamp)
736
737 self.if_not_exists = if_not_exists
738
739 def __unicode__(self):
740 qs = ['INSERT INTO {0}'.format(self.table)]
741
742 # get column names and context placeholders
743 fields = [a.insert_tuple() for a in self.assignments]
744 columns, values = zip(*fields)
745
746 qs += ["({0})".format(', '.join(['"{0}"'.format(c) for c in columns]))]
747 qs += ['VALUES']
748 qs += ["({0})".format(', '.join(['%({0})s'.format(v) for v in values]))]
749
750 if self.if_not_exists:
751 qs += ["IF NOT EXISTS"]
752
753 using_options = []
754 if self.ttl:
755 using_options += ["TTL {}".format(self.ttl)]
756
757 if self.timestamp:
758 using_options += ["TIMESTAMP {}".format(self.timestamp_normalized)]
759
760 if using_options:
761 qs += ["USING {}".format(" AND ".join(using_options))]
762 return ' '.join(qs)
763
764
765class UpdateStatement(AssignmentStatement):

Callers 5

test_statementMethod · 0.90
test_context_updateMethod · 0.90
_insert_statementMethod · 0.90
saveMethod · 0.90

Calls

no outgoing calls

Tested by 4

test_statementMethod · 0.72
test_context_updateMethod · 0.72
_insert_statementMethod · 0.72