sql-ddl-to-json-schema
Version:
Parse and convert SQL DDL statements to a JSON Schema.
96 lines (95 loc) • 3.06 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IndexOptions = void 0;
const utils_1 = require("../../../../shared/utils");
/**
* Table index options.
*/
class IndexOptions {
keyBlockSize;
indexType;
parser;
comment;
algorithm;
lock;
/**
* Creates index options instance from an array of options.
*
* @param options JSON format parsed from SQL.
*/
static fromArray(options) {
const indexOptions = new IndexOptions();
options.forEach((option) => {
if ((0, utils_1.isDefined)(option.def.comment)) {
indexOptions.comment = option.def.comment.toLowerCase();
}
if ((0, utils_1.isDefined)(option.def.indexType)) {
indexOptions.indexType = option.def.indexType.def.toLowerCase();
}
if ((0, utils_1.isDefined)(option.def.keyBlockSize)) {
indexOptions.keyBlockSize = option.def.keyBlockSize;
}
if ((0, utils_1.isDefined)(option.def.parser)) {
indexOptions.parser = option.def.parser;
}
if ((0, utils_1.isDefined)(option.def.algorithm)) {
indexOptions.algorithm = option.def.algorithm;
}
if ((0, utils_1.isDefined)(option.def.lock)) {
indexOptions.lock = option.def.lock;
}
});
return indexOptions;
}
/**
* JSON casting of this object calls this method.
*/
toJSON() {
const json = {};
if ((0, utils_1.isDefined)(this.keyBlockSize)) {
json.keyBlockSize = this.keyBlockSize;
}
if ((0, utils_1.isDefined)(this.indexType)) {
json.indexType = this.indexType;
}
if ((0, utils_1.isDefined)(this.algorithm)) {
json.algorithm = this.algorithm;
}
if ((0, utils_1.isDefined)(this.comment)) {
json.comment = this.comment;
}
if ((0, utils_1.isDefined)(this.parser)) {
json.parser = this.parser;
}
if ((0, utils_1.isDefined)(this.lock)) {
json.lock = this.lock;
}
return json;
}
/**
* Create a deep clone of this model.
*/
clone() {
const options = new IndexOptions();
if ((0, utils_1.isDefined)(this.keyBlockSize)) {
options.keyBlockSize = this.keyBlockSize;
}
if ((0, utils_1.isDefined)(this.indexType)) {
options.indexType = this.indexType;
}
if ((0, utils_1.isDefined)(this.algorithm)) {
options.algorithm = this.algorithm;
}
if ((0, utils_1.isDefined)(this.comment)) {
options.comment = this.comment;
}
if ((0, utils_1.isDefined)(this.parser)) {
options.parser = this.parser;
}
if ((0, utils_1.isDefined)(this.lock)) {
options.lock = this.lock;
}
return options;
}
}
exports.IndexOptions = IndexOptions;