def table_override(original, base, overrides={}): result = Table(original.name, base.metadata, schema=original.schema) for col in original.columns: if col.name not in overrides: result.append_column(col.copy()) else: new_col = overrides[col.name].copy() new_col.name = col.name result.append_column(new_col) return result
def view(name, schema, metadata, selectable): """ Create a view for the given select. A table is returned which can be used to query the view. """ # a temporary MetaData object is used to avoid that this table is actually # created t = Table(name, MetaData(), schema=schema) for c in selectable.c: t.append_column(Column(c.name, c.type, primary_key=c.primary_key)) return t