def _ensure_columns(self, row, types={}): # Keep order of inserted columns for column in row.keys(): if normalize_column_name(column) in self._normalized_columns: continue if column in types: _type = types[column] else: _type = guess_type(row[column]) log.debug("Creating column: %s (%s) on %r" % (column, _type, self.table.name)) self.create_column(column, _type)
def create_column(self, name, type): """ Explicitely create a new column ``name`` of a specified type. ``type`` must be a `SQLAlchemy column type <http://docs.sqlalchemy.org/en/rel_0_8/core/types.html>`_. :: table.create_column('created_at', sqlalchemy.DateTime) """ self._check_dropped() self.database._acquire() try: if normalize_column_name(name) not in self._normalized_columns: self.database.op.add_column(self.table.name, Column(name, type), self.table.schema) self.table = self.database.update_table(self.table.name) finally: self.database._release()
def create_column(self, name, type): """ Explicitely create a new column ``name`` of a specified type. ``type`` must be a `SQLAlchemy column type <http://docs.sqlalchemy.org/en/rel_0_8/core/types.html>`_. :: table.create_column('created_at', sqlalchemy.DateTime) """ self._check_dropped() self.database._acquire() try: if normalize_column_name(name) not in self._normalized_columns: self.database.op.add_column(self.table.name, Column(name, type)) self.table = self.database.update_table(self.table.name) finally: self.database._release()
def _has_column(self, column): return normalize_column_name(column) in self._normalized_columns
def _prune_row(self, row): """Remove keys from row not in column set.""" # normalize keys row = {normalize_column_name(k): v for k, v in row.items()} # filter out keys not in column set return {k: row[k] for k in row if k in self._normalized_columns}