コード例 #1
0
 def _Insert(self,
             key,
             columns,
             keyspace_name=None,
             cf_name=None,
             batch=None,
             column_family=None):
     if cf_name is None and batch is None:
         raise VncError("one of cf_name or batch args "
                        "should be provided to insert {} for {}".format(
                            columns, key))
     if column_family:
         raise VncError("driver does not support column_family's arg "
                        "to insert {} for {}".format(columns, key))
     if batch is not None:
         cf_name = batch.cf_name
     cql = """
       INSERT INTO "{}"
       (key, column1, value)
       VALUES (textAsBlob(%s), textAsBlob(%s), %s)
     """.format(cf_name)
     if batch is not None:
         for column, value in columns.items():
             batch.add_insert(
                 key, cql,
                 [StringType(key),
                  StringType(column),
                  StringType(value)])
     else:
         self._cql_execute(cf_name, key, cql, columns)
コード例 #2
0
 def _Get_One_Col(self, cf_name, key, column):
     col = self.multiget(cf_name, [key], columns=[column])
     if key not in col:
         raise NoIdError(key)
     elif len(col[key]) > 1:
         raise VncError('Multi match %s for %s' % (column, key))
     return col[key][column]
コード例 #3
0
    def _Remove(self, key, columns=None, keyspace_name=None, cf_name=None,
               batch=None, column_family=None):
        """Remove a specified row or a set of columns within the row"""

        if batch:
            batch.remove(key, columns)
        elif column_family:
            column_famlily.remove(key, columns)
        elif cf_name:
            self._cf_dict[cf_name].remove(key, columns)
        else:
            raise VncError('No cf or batch for db remove %s for %s'
                % (columns, key))
コード例 #4
0
    def _Insert(self, key, columns, keyspace_name=None, cf_name=None,
               batch=None, column_family=None):
        """Insert columns with value in a row in a column family"""

        if batch:
            batch.insert(key, columns)
        elif column_family:
            column_famlily.insert(key, columns)
        elif cf_name:
            self._cf_dict[cf_name].insert(key, columns)
        else:
            raise VncError('No cf or batch for db insert %s for %s'
                % (columns, key))
コード例 #5
0
 def _Remove(self,
             key,
             columns=None,
             keyspace_name=None,
             cf_name=None,
             batch=None,
             column_family=None):
     if cf_name is None and batch is None:
         raise VncError("one of cf_name or batch args "
                        "should be provided to remove {} for {}".format(
                            columns, key))
     if column_family:
         raise VncError("driver does not support column_family's arg "
                        "to remove {} for {}".format(columns, key))
     if batch is not None:
         cf_name = batch.cf_name
     if not columns:
         cql = """
           DELETE FROM "{}"
           WHERE key = textAsBlob(%s)
         """.format(cf_name)
         if batch is not None:
             batch.add_remove(key, cql, [StringType(key)])
         else:
             ses = self.get_cf(cf_name)
             ses.execute(cql, [StringType(key)])
     else:
         cql = """
           DELETE FROM "{}"
           WHERE key = textAsBlob(%s)
           AND column1 = textAsBlob(%s)
         """.format(cf_name)
         if batch is not None:
             for column in columns:
                 batch.add_remove(
                     key, cql,
                     [StringType(key), StringType(column)])
         else:
             self._cql_execute(cf_name, key, cql, columns)