UNPKG

sql-ddl-to-json-schema

Version:

Parse and convert SQL DDL statements to a JSON Schema.

70 lines (69 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IndexColumn = void 0; const utils_1 = require("../../../../shared/utils"); /** * Index specification of a column. */ class IndexColumn { column; length; sort; /** * Creates an index column from a JSON def. * * @param json JSON format parsed from SQL. */ static fromDef(json) { if (json.id === 'P_INDEX_COLUMN') { return IndexColumn.fromObject(json.def); } throw new TypeError(`Unknown json id to build index column from: ${json.id}`); } /** * Creates an index column from an object containing needed properties. * * @param json Object containing properties. */ static fromObject(json) { const indexColumn = new IndexColumn(); indexColumn.column = json.column; if (json.length) { indexColumn.length = json.length; } if (json.sort) { indexColumn.sort = json.sort; } return indexColumn; } /** * JSON casting of this object calls this method. */ toJSON() { const json = { column: this.column, }; if ((0, utils_1.isDefined)(this.length)) { json.length = this.length; } if ((0, utils_1.isDefined)(this.sort)) { json.sort = this.sort; } return json; } /** * Create a deep clone of this model. */ clone() { const indexColumn = new IndexColumn(); indexColumn.column = this.column; if ((0, utils_1.isDefined)(this.length)) { indexColumn.length = this.length; } if ((0, utils_1.isDefined)(this.sort)) { indexColumn.sort = this.sort; } return indexColumn; } } exports.IndexColumn = IndexColumn;