UNPKG

quick-erd

Version:

quick and easy text-based ERD + code generator for migration, query, typescript types and orm entity

26 lines (25 loc) 909 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sortTables = sortTables; function sortTables(table_list) { table_list = table_list.slice(); for (let i = 0; i < table_list.length; i++) { table_list.slice().forEach(self => { self.field_list.forEach(field => { const ref = field.references; if (!ref) return; const other = table_list.find(table => table.name === ref.table); if (!other) return; const selfIndex = table_list.indexOf(self); const otherIndex = table_list.indexOf(other); if (otherIndex <= selfIndex) return; table_list[otherIndex] = self; table_list[selfIndex] = other; }); }); } return table_list; }