def ddl_content_to_intermediary(data): tables = ddlparser.parse(data) int_tables = [] all_relations = [] for table in tables: columns = [] for column in table.columns: intermediary_column = Column(column.name, type=str(column.data_type), is_key=column.is_primary_key) columns.append(intermediary_column) uniq_references_to_tables = set() for reference in column.references: uniq_references_to_tables.add(reference.table_name) relations = [ Relation(table_name, table.fullname, '+', '1') for table_name in uniq_references_to_tables ] all_relations.extend(relations) int_tables.append(Table(name=table.fullname, columns=columns)) return int_tables, all_relations
def column_to_intermediary(col, type_formatter=format_type): """Transform an SQLAlchemy Column object to it's intermediary representation. """ return Column( name=col.name, type=type_formatter(col.type), is_key=col.primary_key, )