Esempio n. 1
0
 def _keys_to_args(self, row, keys):
     keys = ensure_tuple(keys)
     keys = [normalize_column_name(k) for k in keys]
     # keys = [self.has_column(k) for k in keys]
     row = row.copy()
     args = {k: row.pop(k) for k in keys if k in row}
     return args, row
Esempio n. 2
0
 def _args_to_order_by(self, order_by):
     orderings = []
     for ordering in ensure_tuple(order_by):
         if ordering is None:
             continue
         column = ordering.lstrip('-')
         if column not in self.table.columns:
             continue
         if ordering.startswith('-'):
             orderings.append(self.table.c[column].desc())
         else:
             orderings.append(self.table.c[column].asc())
     return orderings
Esempio n. 3
0
 def _args_to_order_by(self, order_by):
     orderings = []
     for ordering in ensure_tuple(order_by):
         if ordering is None:
             continue
         column = ordering.lstrip('-')
         column = self._get_column_name(column)
         if not self.has_column(column):
             continue
         if ordering.startswith('-'):
             orderings.append(self.table.c[column].desc())
         else:
             orderings.append(self.table.c[column].asc())
     return orderings
Esempio n. 4
0
    def create_index(self, columns, name=None, **kw):
        """Create an index to speed up queries on a table.

        If no ``name`` is given a random name is created.
        ::

            table.create_index(['name', 'country'])
        """
        columns = [normalize_column_name(c) for c in ensure_tuple(columns)]
        with self.db.lock:
            if not self.exists:
                raise DatasetException("Table has not been created yet.")

            if not self.has_index(columns):
                self._threading_warn()
                name = name or index_name(self.name, columns)
                columns = [self.table.c[c] for c in columns]
                idx = Index(name, *columns, **kw)
                idx.create(self.db.executable)
Esempio n. 5
0
 def _keys_to_args(self, row, keys):
     keys = ensure_tuple(keys)
     keys = [self._get_column_name(k) for k in keys]
     row = row.copy()
     args = {k: row.pop(k, None) for k in keys}
     return args, row