sql-ddl-to-json-schema
Version:
Parse and convert SQL DDL statements to a JSON Schema.
63 lines (62 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Database = void 0;
const table_1 = require("./table");
/**
* Database, which contains array of tables in compact format.
*/
class Database {
/**
* Tables array in compact JSON format.
*/
compactJsonTables = [];
/**
* Table models after parsed.
*/
tables = [];
/**
* Getter for tables.
*/
getTables() {
return this.tables;
}
/**
* Setter for tables.
*
* @param tables Table models.
*/
setTables(tables) {
this.tables = tables;
}
/**
* Get table with given name.
*
* @param name Table name.
*/
getTable(name) {
return this.tables.find((t) => t.name === name);
}
/**
* Pushes a table to database.
*
* @param table Table to be added.
*/
pushTable(table) {
/**
* Do not add table with same name.
*/
if (this.tables.some((t) => t.name === table.name)) {
return;
}
this.tables.push(table);
}
/**
* Build JSON Schema from compact JSON format.
*
* @param tables Tables array in compact JSON format.
*/
parseCompactJson(tables) {
this.setTables(tables.map((table) => table_1.Table.fromCompactJson(table)));
}
}
exports.Database = Database;