Ejemplo n.º 1
0
    def run_idl(self, txn):
        table_schema = self.api._tables[self.table]
        idx = idlutils.get_index_column(table_schema)
        columns = self.columns or list(table_schema.columns.keys()) + ['_uuid']
        # If there's an index for this table, we'll fetch all columns and
        # remove the unwanted ones based on self.records. Otherwise, let's try
        # to get the uuid of the wanted ones which is an O(n^2) operation.
        if not idx and self.records:
            rows = []
            for record in self.records:
                try:
                    rows.append(
                        idlutils.row_by_record(self.api.idl, self.table,
                                               record))
                except idlutils.RowNotFound:
                    if self.if_exists:
                        continue
                    self._raise_notfound()
        else:
            rows = table_schema.rows.values()

        if idx and self.records:
            match = lambda row: getattr(row, idx) in self.records
        else:
            match = lambda row: True

        self.result = [{c: idlutils.get_column_value(row, c)
                        for c in columns} for row in rows if match(row)]

        if (not self.if_exists and idx and self.records
                and len(self.result) < len(self.records)):
            self._raise_notfound()
Ejemplo n.º 2
0
 def __init__(self, api, table, records, columns, if_exists):
     super(DbListCommand, self).__init__(api)
     self.table = self.api._tables[table]
     self.columns = columns or self.table.columns.keys() + ['_uuid']
     self.if_exists = if_exists
     idx = idlutils.get_index_column(self.table)
     if records:
         self.records = [uuid for uuid, row in self.table.rows.items()
                         if getattr(row, idx) in records]
     else:
         self.records = self.table.rows.keys()
Ejemplo n.º 3
0
 def __init__(self, api, table, records, columns, if_exists):
     super(DbListCommand, self).__init__(api)
     self.table = self.api._tables[table]
     self.columns = columns or self.table.columns.keys() + ['_uuid']
     self.if_exists = if_exists
     idx = idlutils.get_index_column(self.table)
     if records:
         self.records = [
             uuid for uuid, row in self.table.rows.items()
             if getattr(row, idx) in records
         ]
     else:
         self.records = self.table.rows.keys()
Ejemplo n.º 4
0
 def row_by_index(self, table, match, *default):
     tab = self.api._tables[table]
     idx = idlutils.get_index_column(tab)
     return self.row_by_value(table, idx, match, *default)
Ejemplo n.º 5
0
 def row_by_index(self, table, match, *default):
     tab = self.api._tables[table]
     idx = idlutils.get_index_column(tab)
     return self.row_by_value(table, idx, match, *default)