@dbml/core 3.12.0-alpha-0 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/model_structure/utils.js +0 -6
- package/lib/parse/ANTLR/ASTGeneration/AST.js +47 -2
- package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +213 -44
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +2 -4
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +2 -4
- package/lib/parse/Parser.js +2 -4
- package/package.json +3 -3
- package/types/import/index.d.ts +1 -1
- package/types/model_structure/database.d.ts +8 -8
- package/types/parse/Parser.d.ts +1 -1
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getFullTableName = getFullTableName;
|
|
7
6
|
exports.shouldPrintSchema = shouldPrintSchema;
|
|
8
7
|
exports.shouldPrintSchemaName = shouldPrintSchemaName;
|
|
9
8
|
var _config = require("./config");
|
|
@@ -12,9 +11,4 @@ function shouldPrintSchema(schema) {
|
|
|
12
11
|
}
|
|
13
12
|
function shouldPrintSchemaName(schemaName) {
|
|
14
13
|
return schemaName !== _config.DEFAULT_SCHEMA_NAME;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// TODO: This is an ad hoc function for parsing inserts. It should be replaced with a more robust solution
|
|
18
|
-
function getFullTableName(schemaName, tableName) {
|
|
19
|
-
return "".concat(schemaName && shouldPrintSchemaName(schemaName) ? "".concat(schemaName, ".") : '').concat(tableName);
|
|
20
14
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.Table = exports.Ref = exports.Index = exports.Field = exports.Enum = exports.Endpoint = void 0;
|
|
6
|
+
exports.TableRecord = exports.Table = exports.Ref = exports.Index = exports.Field = exports.Enum = exports.Endpoint = void 0;
|
|
7
7
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
8
8
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
9
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
@@ -290,4 +290,49 @@ var Enum = /*#__PURE__*/function () {
|
|
|
290
290
|
}]);
|
|
291
291
|
return Enum;
|
|
292
292
|
}();
|
|
293
|
-
exports.Enum = Enum;
|
|
293
|
+
exports.Enum = Enum;
|
|
294
|
+
var TableRecord = /*#__PURE__*/function () {
|
|
295
|
+
/**
|
|
296
|
+
* @param {{
|
|
297
|
+
* tableName: string,
|
|
298
|
+
* columns: string[],
|
|
299
|
+
* values: {
|
|
300
|
+
* value: any,
|
|
301
|
+
* type: string,
|
|
302
|
+
* }[]
|
|
303
|
+
* schemaName?: string,
|
|
304
|
+
* }} param0
|
|
305
|
+
*/
|
|
306
|
+
function TableRecord(_ref7) {
|
|
307
|
+
var tableName = _ref7.tableName,
|
|
308
|
+
columns = _ref7.columns,
|
|
309
|
+
values = _ref7.values,
|
|
310
|
+
_ref7$schemaName = _ref7.schemaName,
|
|
311
|
+
schemaName = _ref7$schemaName === void 0 ? undefined : _ref7$schemaName;
|
|
312
|
+
_classCallCheck(this, TableRecord);
|
|
313
|
+
/** @type {string} */
|
|
314
|
+
this.tableName = tableName;
|
|
315
|
+
|
|
316
|
+
/** @type {string | undefined} */
|
|
317
|
+
this.schemaName = schemaName;
|
|
318
|
+
|
|
319
|
+
/** @type {string[]} */
|
|
320
|
+
this.columns = columns;
|
|
321
|
+
|
|
322
|
+
/** @type {{value: any, type: string}[]} */
|
|
323
|
+
this.values = values;
|
|
324
|
+
}
|
|
325
|
+
_createClass(TableRecord, [{
|
|
326
|
+
key: "toJSON",
|
|
327
|
+
value: function toJSON() {
|
|
328
|
+
return {
|
|
329
|
+
tableName: this.tableName,
|
|
330
|
+
schemaName: this.schemaName,
|
|
331
|
+
columns: this.columns,
|
|
332
|
+
values: this.values
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
}]);
|
|
336
|
+
return TableRecord;
|
|
337
|
+
}();
|
|
338
|
+
exports.TableRecord = TableRecord;
|
|
@@ -6,16 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _lodash = require("lodash");
|
|
9
|
-
var _utils = require("../../../../model_structure/utils");
|
|
10
9
|
var _TSqlParserVisitor2 = _interopRequireDefault(require("../../parsers/mssql/TSqlParserVisitor"));
|
|
11
10
|
var _constants = require("../constants");
|
|
12
11
|
var _helpers = require("../helpers");
|
|
13
12
|
var _AST = require("../AST");
|
|
14
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
16
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
18
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
19
14
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
15
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
21
16
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -28,6 +23,10 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
|
|
|
28
23
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
29
24
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
30
25
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
26
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
27
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
28
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
29
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
31
30
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
32
31
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
33
32
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -35,6 +34,10 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
35
34
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
36
35
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /* eslint-disable class-methods-use-this */
|
|
37
36
|
var ADD_DESCRIPTION_FUNCTION_NAME = 'sp_addextendedproperty';
|
|
37
|
+
var CHECK_CONSTRAINT_CONDITION_TYPE = {
|
|
38
|
+
RAW: 'raw',
|
|
39
|
+
ENUM: 'enum'
|
|
40
|
+
};
|
|
38
41
|
var getSchemaAndTableName = function getSchemaAndTableName(names) {
|
|
39
42
|
var tableName = (0, _lodash.last)(names);
|
|
40
43
|
var schemaName = names.length > 1 ? (0, _lodash.nth)(names, -2) : undefined;
|
|
@@ -56,6 +59,8 @@ var getStringFromRawString = function getStringFromRawString(rawString) {
|
|
|
56
59
|
* fieldsData: any[],
|
|
57
60
|
* indexes: any[],
|
|
58
61
|
* tableRefs: any[],
|
|
62
|
+
* columnDefaults: any[],
|
|
63
|
+
* checkConstraints: any[],
|
|
59
64
|
* }}
|
|
60
65
|
*/
|
|
61
66
|
var splitColumnDefTableConstraints = function splitColumnDefTableConstraints(columnDefTableConstraints) {
|
|
@@ -75,25 +80,31 @@ var splitColumnDefTableConstraints = function splitColumnDefTableConstraints(col
|
|
|
75
80
|
case _constants.TABLE_CONSTRAINT_KIND.DEFAULT:
|
|
76
81
|
acc[3].push(columnDefTableConstraint.value);
|
|
77
82
|
break;
|
|
83
|
+
case _constants.TABLE_CONSTRAINT_KIND.CHECK:
|
|
84
|
+
acc[4].push(columnDefTableConstraint.value);
|
|
85
|
+
break;
|
|
78
86
|
default:
|
|
79
87
|
break;
|
|
80
88
|
}
|
|
81
89
|
return acc;
|
|
82
|
-
}, [[], [], [], []]),
|
|
83
|
-
_columnDefTableConstr2 = _slicedToArray(_columnDefTableConstr,
|
|
90
|
+
}, [[], [], [], [], []]),
|
|
91
|
+
_columnDefTableConstr2 = _slicedToArray(_columnDefTableConstr, 5),
|
|
84
92
|
fieldsData = _columnDefTableConstr2[0],
|
|
85
93
|
indexes = _columnDefTableConstr2[1],
|
|
86
94
|
tableRefs = _columnDefTableConstr2[2],
|
|
87
|
-
columnDefaults = _columnDefTableConstr2[3]
|
|
95
|
+
columnDefaults = _columnDefTableConstr2[3],
|
|
96
|
+
checkConstraints = _columnDefTableConstr2[4];
|
|
88
97
|
return {
|
|
89
98
|
fieldsData: fieldsData,
|
|
90
99
|
indexes: indexes,
|
|
91
100
|
tableRefs: tableRefs,
|
|
92
|
-
columnDefaults: columnDefaults
|
|
101
|
+
columnDefaults: columnDefaults,
|
|
102
|
+
checkConstraints: checkConstraints
|
|
93
103
|
};
|
|
94
104
|
};
|
|
95
105
|
var parseFieldsAndInlineRefsFromFieldsData = function parseFieldsAndInlineRefsFromFieldsData(fieldsData, tableName, schemaName) {
|
|
96
106
|
var _fieldsData$reduce = fieldsData.reduce(function (acc, fieldData) {
|
|
107
|
+
var _acc$;
|
|
97
108
|
var inlineRefs = fieldData.inline_refs.map(function (inlineRef) {
|
|
98
109
|
inlineRef.endpoints[0].tableName = tableName;
|
|
99
110
|
inlineRef.endpoints[0].schemaName = schemaName;
|
|
@@ -102,14 +113,17 @@ var parseFieldsAndInlineRefsFromFieldsData = function parseFieldsAndInlineRefsFr
|
|
|
102
113
|
});
|
|
103
114
|
acc[0].push(inlineRefs);
|
|
104
115
|
acc[1].push(fieldData.field);
|
|
116
|
+
(_acc$ = acc[2]).push.apply(_acc$, _toConsumableArray(fieldData.checkConstraints));
|
|
105
117
|
return acc;
|
|
106
|
-
}, [[], []]),
|
|
107
|
-
_fieldsData$reduce2 = _slicedToArray(_fieldsData$reduce,
|
|
118
|
+
}, [[], [], []]),
|
|
119
|
+
_fieldsData$reduce2 = _slicedToArray(_fieldsData$reduce, 3),
|
|
108
120
|
resInlineRefs = _fieldsData$reduce2[0],
|
|
109
|
-
fields = _fieldsData$reduce2[1]
|
|
121
|
+
fields = _fieldsData$reduce2[1],
|
|
122
|
+
checkConstraints = _fieldsData$reduce2[2];
|
|
110
123
|
return {
|
|
111
124
|
inlineRefs: resInlineRefs,
|
|
112
|
-
fields: fields
|
|
125
|
+
fields: fields,
|
|
126
|
+
checkConstraints: checkConstraints
|
|
113
127
|
};
|
|
114
128
|
};
|
|
115
129
|
var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
@@ -222,12 +236,12 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
222
236
|
var schemaName = names.length > 1 ? (0, _lodash.nth)(names, -2) : undefined;
|
|
223
237
|
var columns = ctx.insert_column_name_list() ? ctx.insert_column_name_list().accept(this) : [];
|
|
224
238
|
var values = ctx.insert_statement_value().accept(this);
|
|
225
|
-
var record = {
|
|
226
|
-
schemaName: schemaName,
|
|
239
|
+
var record = new _AST.TableRecord({
|
|
227
240
|
tableName: tableName,
|
|
241
|
+
schemaName: schemaName,
|
|
228
242
|
columns: columns,
|
|
229
243
|
values: values
|
|
230
|
-
};
|
|
244
|
+
});
|
|
231
245
|
this.data.records.push(record);
|
|
232
246
|
}
|
|
233
247
|
|
|
@@ -360,6 +374,9 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
360
374
|
if (ctx.bracket_expression()) {
|
|
361
375
|
return ctx.bracket_expression().accept(this);
|
|
362
376
|
}
|
|
377
|
+
if (ctx.full_column_name()) {
|
|
378
|
+
return ctx.full_column_name().accept(this);
|
|
379
|
+
}
|
|
363
380
|
|
|
364
381
|
// Default case for any other expression type
|
|
365
382
|
return {
|
|
@@ -378,6 +395,23 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
378
395
|
return ctx.expression() ? ctx.expression().accept(this) : null;
|
|
379
396
|
}
|
|
380
397
|
|
|
398
|
+
// full_column_name
|
|
399
|
+
// : ((DELETED | INSERTED | full_table_name) '.')? (
|
|
400
|
+
// column_name = id_
|
|
401
|
+
// | ('$' (IDENTITY | ROWGUID))
|
|
402
|
+
// )
|
|
403
|
+
// ;
|
|
404
|
+
}, {
|
|
405
|
+
key: "visitFull_column_name",
|
|
406
|
+
value: function visitFull_column_name(ctx) {
|
|
407
|
+
var columnName = ctx.id_().accept(this);
|
|
408
|
+
var fullTableName = ctx.full_table_name() ? ctx.full_table_name().accept(this) : [];
|
|
409
|
+
return {
|
|
410
|
+
value: [].concat(_toConsumableArray(fullTableName), [columnName]),
|
|
411
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
381
415
|
// primitive_constant
|
|
382
416
|
// : STRING // string, datetime or uniqueidentifier
|
|
383
417
|
// | BINARY
|
|
@@ -559,16 +593,41 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
559
593
|
var _splitColumnDefTableC = splitColumnDefTableConstraints(columnDefTableConstraints),
|
|
560
594
|
fieldsData = _splitColumnDefTableC.fieldsData,
|
|
561
595
|
indexes = _splitColumnDefTableC.indexes,
|
|
562
|
-
tableRefs = _splitColumnDefTableC.tableRefs
|
|
596
|
+
tableRefs = _splitColumnDefTableC.tableRefs,
|
|
597
|
+
tableCheckConstraints = _splitColumnDefTableC.checkConstraints;
|
|
563
598
|
var _parseFieldsAndInline = parseFieldsAndInlineRefsFromFieldsData(fieldsData, tableName, schemaName),
|
|
564
599
|
inlineRefs = _parseFieldsAndInline.inlineRefs,
|
|
565
|
-
fields = _parseFieldsAndInline.fields
|
|
600
|
+
fields = _parseFieldsAndInline.fields,
|
|
601
|
+
columnCheckConstraints = _parseFieldsAndInline.checkConstraints;
|
|
566
602
|
(_this$data$refs = this.data.refs).push.apply(_this$data$refs, _toConsumableArray((0, _lodash.flatten)(inlineRefs)));
|
|
567
603
|
(_this$data$refs2 = this.data.refs).push.apply(_this$data$refs2, _toConsumableArray(tableRefs.map(function (tableRef) {
|
|
568
604
|
tableRef.endpoints[0].tableName = tableName;
|
|
569
605
|
tableRef.endpoints[0].schemaName = schemaName;
|
|
570
606
|
return tableRef;
|
|
571
607
|
})));
|
|
608
|
+
|
|
609
|
+
// these check constraints represent enums
|
|
610
|
+
var enums = [];
|
|
611
|
+
var checkConstraints = columnCheckConstraints.concat(tableCheckConstraints);
|
|
612
|
+
checkConstraints.forEach(function (checkConstraint) {
|
|
613
|
+
var field = fields.find(function (field) {
|
|
614
|
+
return field.name === checkConstraint.column;
|
|
615
|
+
});
|
|
616
|
+
if (!field) return;
|
|
617
|
+
var enumObject = new _AST.Enum({
|
|
618
|
+
name: "".concat(tableName, "_").concat(field.name, "_enum"),
|
|
619
|
+
values: checkConstraint.columnValues.map(function (value) {
|
|
620
|
+
return {
|
|
621
|
+
name: value
|
|
622
|
+
};
|
|
623
|
+
}),
|
|
624
|
+
schemaName: schemaName
|
|
625
|
+
});
|
|
626
|
+
_this8.data.enums.push(enumObject);
|
|
627
|
+
// TODO: handle multiple enums for the same field
|
|
628
|
+
field.type.type_name = enumObject.name;
|
|
629
|
+
field.type.schemaName = enumObject.schemaName;
|
|
630
|
+
});
|
|
572
631
|
var table = new _AST.Table({
|
|
573
632
|
name: tableName,
|
|
574
633
|
schemaName: schemaName,
|
|
@@ -653,7 +712,8 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
653
712
|
kind: _constants.TABLE_CONSTRAINT_KIND.FIELD,
|
|
654
713
|
value: {
|
|
655
714
|
field: field,
|
|
656
|
-
inline_refs: []
|
|
715
|
+
inline_refs: [],
|
|
716
|
+
checkConstraints: []
|
|
657
717
|
}
|
|
658
718
|
};
|
|
659
719
|
var columnDefinitions = ctx.column_definition_element().map(function (columnDef) {
|
|
@@ -688,8 +748,16 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
688
748
|
definition.value.inline_refs.push(columnDef.value);
|
|
689
749
|
break;
|
|
690
750
|
case _constants.COLUMN_CONSTRAINT_KIND.CHECK:
|
|
691
|
-
|
|
692
|
-
|
|
751
|
+
{
|
|
752
|
+
var _columnDef$value = columnDef.value,
|
|
753
|
+
_type = _columnDef$value.type,
|
|
754
|
+
value = _columnDef$value.value;
|
|
755
|
+
|
|
756
|
+
// we keep the current behavior: when a field has a check constraints cannot be converted to enum, we will ignore it
|
|
757
|
+
if (_type !== CHECK_CONSTRAINT_CONDITION_TYPE.ENUM) return;
|
|
758
|
+
definition.value.checkConstraints.push(value);
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
693
761
|
default:
|
|
694
762
|
break;
|
|
695
763
|
}
|
|
@@ -813,7 +881,76 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
813
881
|
}, {
|
|
814
882
|
key: "visitCheck_constraint",
|
|
815
883
|
value: function visitCheck_constraint(ctx) {
|
|
816
|
-
return (
|
|
884
|
+
return ctx.search_condition().accept(this);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// search_condition
|
|
888
|
+
// : NOT* (predicate | '(' search_condition ')')
|
|
889
|
+
// | search_condition AND search_condition // AND takes precedence over OR
|
|
890
|
+
// | search_condition OR search_condition
|
|
891
|
+
// ;
|
|
892
|
+
}, {
|
|
893
|
+
key: "visitSearch_condition",
|
|
894
|
+
value: function visitSearch_condition(ctx) {
|
|
895
|
+
// we will parse the enum from the most basic condition - map to the old behavior
|
|
896
|
+
// others, we will get the check constraint to ensure the constraint is applied - enhance the old behavior
|
|
897
|
+
if (!ctx.predicate() || ctx.NOT().length) {
|
|
898
|
+
return {
|
|
899
|
+
type: CHECK_CONSTRAINT_CONDITION_TYPE.RAW,
|
|
900
|
+
value: (0, _helpers.getOriginalText)(ctx)
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
var predicate = ctx.predicate().accept(this);
|
|
904
|
+
if (!predicate) {
|
|
905
|
+
return {
|
|
906
|
+
type: CHECK_CONSTRAINT_CONDITION_TYPE.RAW,
|
|
907
|
+
value: (0, _helpers.getOriginalText)(ctx)
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
return {
|
|
911
|
+
type: CHECK_CONSTRAINT_CONDITION_TYPE.ENUM,
|
|
912
|
+
value: predicate
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// predicate
|
|
917
|
+
// : EXISTS '(' subquery ')'
|
|
918
|
+
// | freetext_predicate
|
|
919
|
+
// | expression comparison_operator expression
|
|
920
|
+
// | expression MULT_ASSIGN expression ////SQL-82 syntax for left outer joins; '*='. See https://stackoverflow.com/questions/40665/in-sybase-sql
|
|
921
|
+
// | expression comparison_operator (ALL | SOME | ANY) '(' subquery ')'
|
|
922
|
+
// | expression NOT* BETWEEN expression AND expression
|
|
923
|
+
// | expression NOT* IN '(' (subquery | expression_list_) ')'
|
|
924
|
+
// | expression NOT* LIKE expression (ESCAPE expression)?
|
|
925
|
+
// | expression IS null_notnull
|
|
926
|
+
// ;
|
|
927
|
+
}, {
|
|
928
|
+
key: "visitPredicate",
|
|
929
|
+
value: function visitPredicate(ctx) {
|
|
930
|
+
var _this12 = this;
|
|
931
|
+
if (ctx.IN() && ctx.expression_list_() && ctx.NOT().length === 0) {
|
|
932
|
+
var _expression$value;
|
|
933
|
+
var _ctx$expression$map = ctx.expression().map(function (e) {
|
|
934
|
+
return e.accept(_this12);
|
|
935
|
+
}),
|
|
936
|
+
_ctx$expression$map2 = _slicedToArray(_ctx$expression$map, 1),
|
|
937
|
+
_ctx$expression$map2$ = _ctx$expression$map2[0],
|
|
938
|
+
expression = _ctx$expression$map2$ === void 0 ? {} : _ctx$expression$map2$;
|
|
939
|
+
|
|
940
|
+
// {
|
|
941
|
+
// value: [ 'myschema', 'sample_table', 'column_name' ],
|
|
942
|
+
// type: 'expression'
|
|
943
|
+
// }
|
|
944
|
+
var column = (0, _lodash.last)((_expression$value = expression.value) !== null && _expression$value !== void 0 ? _expression$value : []);
|
|
945
|
+
var expressionList = ctx.expression_list_().accept(this).map(function (e) {
|
|
946
|
+
return e.value;
|
|
947
|
+
});
|
|
948
|
+
return {
|
|
949
|
+
column: column,
|
|
950
|
+
columnValues: expressionList
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
return null;
|
|
817
954
|
}
|
|
818
955
|
}, {
|
|
819
956
|
key: "visitNull_notnull",
|
|
@@ -829,17 +966,17 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
829
966
|
}, {
|
|
830
967
|
key: "visitForeign_key_options",
|
|
831
968
|
value: function visitForeign_key_options(ctx) {
|
|
832
|
-
var
|
|
969
|
+
var _this13 = this;
|
|
833
970
|
var names = ctx.table_name().accept(this);
|
|
834
971
|
var _getSchemaAndTableNam2 = getSchemaAndTableName(names),
|
|
835
972
|
refSchemaName = _getSchemaAndTableNam2.schemaName,
|
|
836
973
|
refTableName = _getSchemaAndTableNam2.tableName;
|
|
837
974
|
var fieldNames = ctx.column_name_list().accept(this);
|
|
838
975
|
var onDelete = ctx.on_delete() ? ctx.on_delete().map(function (action) {
|
|
839
|
-
return action.accept(
|
|
976
|
+
return action.accept(_this13);
|
|
840
977
|
})[0] : null;
|
|
841
978
|
var onUpdate = ctx.on_update() ? ctx.on_update().map(function (action) {
|
|
842
|
-
return action.accept(
|
|
979
|
+
return action.accept(_this13);
|
|
843
980
|
})[0] : null;
|
|
844
981
|
return {
|
|
845
982
|
refTableName: refTableName,
|
|
@@ -856,9 +993,9 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
856
993
|
}, {
|
|
857
994
|
key: "visitColumn_name_list",
|
|
858
995
|
value: function visitColumn_name_list(ctx) {
|
|
859
|
-
var
|
|
996
|
+
var _this14 = this;
|
|
860
997
|
return ctx.id_().map(function (id) {
|
|
861
|
-
return id.accept(
|
|
998
|
+
return id.accept(_this14);
|
|
862
999
|
});
|
|
863
1000
|
}
|
|
864
1001
|
|
|
@@ -910,9 +1047,9 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
910
1047
|
}, {
|
|
911
1048
|
key: "visitTable_constraint",
|
|
912
1049
|
value: function visitTable_constraint(ctx) {
|
|
913
|
-
var
|
|
1050
|
+
var _this15 = this;
|
|
914
1051
|
var name = ctx.id_() ? ctx.id_().map(function (id) {
|
|
915
|
-
return id.accept(
|
|
1052
|
+
return id.accept(_this15);
|
|
916
1053
|
})[0] : '';
|
|
917
1054
|
if (ctx.PRIMARY() || ctx.UNIQUE()) {
|
|
918
1055
|
var columns = ctx.column_name_list_with_order().accept(this);
|
|
@@ -970,6 +1107,14 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
970
1107
|
}
|
|
971
1108
|
};
|
|
972
1109
|
}
|
|
1110
|
+
if (ctx.check_constraint()) {
|
|
1111
|
+
var checkConstraint = ctx.check_constraint().accept(this);
|
|
1112
|
+
if (checkConstraint.type !== CHECK_CONSTRAINT_CONDITION_TYPE.ENUM) return null;
|
|
1113
|
+
return {
|
|
1114
|
+
kind: _constants.TABLE_CONSTRAINT_KIND.CHECK,
|
|
1115
|
+
value: checkConstraint.value
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
973
1118
|
return null;
|
|
974
1119
|
}
|
|
975
1120
|
|
|
@@ -979,10 +1124,10 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
979
1124
|
}, {
|
|
980
1125
|
key: "visitColumn_name_list_with_order",
|
|
981
1126
|
value: function visitColumn_name_list_with_order(ctx) {
|
|
982
|
-
var
|
|
1127
|
+
var _this16 = this;
|
|
983
1128
|
return ctx.id_().map(function (id) {
|
|
984
1129
|
return {
|
|
985
|
-
value: id.accept(
|
|
1130
|
+
value: id.accept(_this16),
|
|
986
1131
|
type: 'column'
|
|
987
1132
|
};
|
|
988
1133
|
});
|
|
@@ -998,10 +1143,10 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
998
1143
|
}, {
|
|
999
1144
|
key: "visitTable_indices",
|
|
1000
1145
|
value: function visitTable_indices(ctx) {
|
|
1001
|
-
var
|
|
1146
|
+
var _this17 = this;
|
|
1002
1147
|
var index = new _AST.Index({
|
|
1003
1148
|
name: ctx.id_().map(function (id) {
|
|
1004
|
-
return id.accept(
|
|
1149
|
+
return id.accept(_this17);
|
|
1005
1150
|
})[0],
|
|
1006
1151
|
unique: !!ctx.UNIQUE(),
|
|
1007
1152
|
columns: ctx.column_name_list_with_order().accept(this)
|
|
@@ -1031,7 +1176,11 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
1031
1176
|
}, {
|
|
1032
1177
|
key: "visitAlter_table",
|
|
1033
1178
|
value: function visitAlter_table(ctx) {
|
|
1034
|
-
var _this$data$refs3,
|
|
1179
|
+
var _this$data$refs3,
|
|
1180
|
+
_this$data$refs4,
|
|
1181
|
+
_table$fields,
|
|
1182
|
+
_table$indexes,
|
|
1183
|
+
_this18 = this;
|
|
1035
1184
|
// table_name() returns an array because there are multiple table_name in the clause (REFERENCES table_name ...)
|
|
1036
1185
|
var names = ctx.table_name()[0].accept(this);
|
|
1037
1186
|
var _getSchemaAndTableNam3 = getSchemaAndTableName(names),
|
|
@@ -1047,7 +1196,8 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
1047
1196
|
fieldsData = _splitColumnDefTableC2.fieldsData,
|
|
1048
1197
|
indexes = _splitColumnDefTableC2.indexes,
|
|
1049
1198
|
tableRefs = _splitColumnDefTableC2.tableRefs,
|
|
1050
|
-
columnDefaults = _splitColumnDefTableC2.columnDefaults
|
|
1199
|
+
columnDefaults = _splitColumnDefTableC2.columnDefaults,
|
|
1200
|
+
checkConstraints = _splitColumnDefTableC2.checkConstraints;
|
|
1051
1201
|
var _parseFieldsAndInline2 = parseFieldsAndInlineRefsFromFieldsData(fieldsData, tableName, schemaName),
|
|
1052
1202
|
inlineRefs = _parseFieldsAndInline2.inlineRefs,
|
|
1053
1203
|
fields = _parseFieldsAndInline2.fields;
|
|
@@ -1066,6 +1216,25 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
1066
1216
|
if (!field) return;
|
|
1067
1217
|
field.dbdefault = columnDefault.defaultValue;
|
|
1068
1218
|
});
|
|
1219
|
+
checkConstraints.forEach(function (checkConstraint) {
|
|
1220
|
+
var field = table.fields.find(function (field) {
|
|
1221
|
+
return field.name === checkConstraint.column;
|
|
1222
|
+
});
|
|
1223
|
+
if (!field) return;
|
|
1224
|
+
var enumObject = new _AST.Enum({
|
|
1225
|
+
name: "".concat(tableName, "_").concat(field.name, "_enum"),
|
|
1226
|
+
values: checkConstraint.columnValues.map(function (value) {
|
|
1227
|
+
return {
|
|
1228
|
+
name: value
|
|
1229
|
+
};
|
|
1230
|
+
}),
|
|
1231
|
+
schemaName: schemaName
|
|
1232
|
+
});
|
|
1233
|
+
_this18.data.enums.push(enumObject);
|
|
1234
|
+
// TODO: handle multiple enums for the same field
|
|
1235
|
+
field.type.type_name = enumObject.name;
|
|
1236
|
+
field.type.schemaName = enumObject.schemaName;
|
|
1237
|
+
});
|
|
1069
1238
|
}
|
|
1070
1239
|
|
|
1071
1240
|
// create_index
|
|
@@ -1208,12 +1377,12 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
1208
1377
|
}, {
|
|
1209
1378
|
key: "visitFunc_proc_name_server_database_schema",
|
|
1210
1379
|
value: function visitFunc_proc_name_server_database_schema(ctx) {
|
|
1211
|
-
var
|
|
1380
|
+
var _this19 = this;
|
|
1212
1381
|
if (ctx.func_proc_name_database_schema()) {
|
|
1213
1382
|
return ctx.func_proc_name_database_schema().accept(this);
|
|
1214
1383
|
} else {
|
|
1215
1384
|
return ctx.id_().map(function (id) {
|
|
1216
|
-
return id.accept(
|
|
1385
|
+
return id.accept(_this19);
|
|
1217
1386
|
});
|
|
1218
1387
|
}
|
|
1219
1388
|
}
|
|
@@ -1225,12 +1394,12 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
1225
1394
|
}, {
|
|
1226
1395
|
key: "visitFunc_proc_name_database_schema",
|
|
1227
1396
|
value: function visitFunc_proc_name_database_schema(ctx) {
|
|
1228
|
-
var
|
|
1397
|
+
var _this20 = this;
|
|
1229
1398
|
if (ctx.func_proc_name_schema()) {
|
|
1230
1399
|
return ctx.func_proc_name_schema().accept(this);
|
|
1231
1400
|
} else {
|
|
1232
1401
|
return ctx.id_().map(function (id) {
|
|
1233
|
-
return id.accept(
|
|
1402
|
+
return id.accept(_this20);
|
|
1234
1403
|
});
|
|
1235
1404
|
}
|
|
1236
1405
|
}
|
|
@@ -1241,9 +1410,9 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
1241
1410
|
}, {
|
|
1242
1411
|
key: "visitFunc_proc_name_schema",
|
|
1243
1412
|
value: function visitFunc_proc_name_schema(ctx) {
|
|
1244
|
-
var
|
|
1413
|
+
var _this21 = this;
|
|
1245
1414
|
return ctx.id_().map(function (id) {
|
|
1246
|
-
return id.accept(
|
|
1415
|
+
return id.accept(_this21);
|
|
1247
1416
|
});
|
|
1248
1417
|
}
|
|
1249
1418
|
|
|
@@ -1254,14 +1423,14 @@ var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
|
1254
1423
|
}, {
|
|
1255
1424
|
key: "visitExecute_statement_arg",
|
|
1256
1425
|
value: function visitExecute_statement_arg(ctx) {
|
|
1257
|
-
var
|
|
1426
|
+
var _this22 = this;
|
|
1258
1427
|
if (ctx.execute_statement_arg_unnamed()) {
|
|
1259
1428
|
return ctx.execute_statement_arg_unnamed().map(function (item) {
|
|
1260
|
-
return item.accept(
|
|
1429
|
+
return item.accept(_this22);
|
|
1261
1430
|
});
|
|
1262
1431
|
}
|
|
1263
1432
|
return ctx.execute_statement_arg_named().map(function (item) {
|
|
1264
|
-
return item.accept(
|
|
1433
|
+
return item.accept(_this22);
|
|
1265
1434
|
});
|
|
1266
1435
|
}
|
|
1267
1436
|
|
|
@@ -9,7 +9,6 @@ var _lodash = require("lodash");
|
|
|
9
9
|
var _MySqlParserVisitor = _interopRequireDefault(require("../../parsers/mysql/MySqlParserVisitor"));
|
|
10
10
|
var _AST = require("../AST");
|
|
11
11
|
var _constants = require("../constants");
|
|
12
|
-
var _utils = require("../../../../model_structure/utils");
|
|
13
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
13
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -1178,17 +1177,16 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
1178
1177
|
var names = ctx.tableName().accept(this);
|
|
1179
1178
|
var tableName = (0, _lodash.last)(names);
|
|
1180
1179
|
var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
|
|
1181
|
-
var fullTableName = (0, _utils.getFullTableName)(schemaName, tableName);
|
|
1182
1180
|
|
|
1183
1181
|
// insert without specified columns
|
|
1184
1182
|
var columns = ctx.fullColumnNameList() ? ctx.fullColumnNameList().accept(this) : [];
|
|
1185
1183
|
var values = ctx.insertStatementValue().accept(this);
|
|
1186
|
-
var record = {
|
|
1184
|
+
var record = new _AST.TableRecord({
|
|
1187
1185
|
schemaName: schemaName,
|
|
1188
1186
|
tableName: tableName,
|
|
1189
1187
|
columns: columns,
|
|
1190
1188
|
values: values
|
|
1191
|
-
};
|
|
1189
|
+
});
|
|
1192
1190
|
this.data.records.push(record);
|
|
1193
1191
|
}
|
|
1194
1192
|
|
|
@@ -9,7 +9,6 @@ var _lodash = require("lodash");
|
|
|
9
9
|
var _PostgreSQLParserVisitor = _interopRequireDefault(require("../../parsers/postgresql/PostgreSQLParserVisitor"));
|
|
10
10
|
var _AST = require("../AST");
|
|
11
11
|
var _constants = require("../constants");
|
|
12
|
-
var _utils = require("../../../../model_structure/utils");
|
|
13
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
13
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -1177,16 +1176,15 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
1177
1176
|
var names = ctx.insert_target().accept(this);
|
|
1178
1177
|
var tableName = (0, _lodash.last)(names);
|
|
1179
1178
|
var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
|
|
1180
|
-
var fullTableName = (0, _utils.getFullTableName)(schemaName, tableName);
|
|
1181
1179
|
var _ctx$insert_rest$acce = ctx.insert_rest().accept(this),
|
|
1182
1180
|
columns = _ctx$insert_rest$acce.columns,
|
|
1183
1181
|
values = _ctx$insert_rest$acce.values;
|
|
1184
|
-
var record = {
|
|
1182
|
+
var record = new _AST.TableRecord({
|
|
1185
1183
|
schemaName: schemaName,
|
|
1186
1184
|
tableName: tableName,
|
|
1187
1185
|
columns: columns,
|
|
1188
1186
|
values: values
|
|
1189
|
-
};
|
|
1187
|
+
});
|
|
1190
1188
|
this.data.records.push(record);
|
|
1191
1189
|
}
|
|
1192
1190
|
}, {
|
package/lib/parse/Parser.js
CHANGED
|
@@ -55,12 +55,10 @@ var Parser = /*#__PURE__*/function () {
|
|
|
55
55
|
case 'schemarb':
|
|
56
56
|
rawDatabase = Parser.parseSchemaRbToJSON(str);
|
|
57
57
|
break;
|
|
58
|
-
case '
|
|
58
|
+
case 'mssqlLegacy':
|
|
59
59
|
rawDatabase = Parser.parseMSSQLToJSON(str);
|
|
60
60
|
break;
|
|
61
|
-
|
|
62
|
-
// When we finish implementing the new parser, it should be mssql and the old one will be mssqlLegacy
|
|
63
|
-
case 'mssqlv2':
|
|
61
|
+
case 'mssql':
|
|
64
62
|
rawDatabase = Parser.parseMSSQLToJSONv2(str);
|
|
65
63
|
break;
|
|
66
64
|
case 'json':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/core",
|
|
3
|
-
"version": "3.12.0
|
|
3
|
+
"version": "3.12.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "Holistics <dev@holistics.io>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"prepublish": "npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@dbml/parse": "^3.12.0
|
|
35
|
+
"@dbml/parse": "^3.12.0",
|
|
36
36
|
"antlr4": "^4.13.1",
|
|
37
37
|
"lodash": "^4.17.15",
|
|
38
38
|
"parsimmon": "^1.13.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"\\.(?!json$)[^.]*$": "@glen/jest-raw-loader"
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "e14cab048ba2c38acb622e780bea160a115a03d5",
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">=16"
|
|
65
65
|
}
|
package/types/import/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare function _import(str: string, format: 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'postgresLegacy'): string;
|
|
1
|
+
declare function _import(str: string, format: 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'postgresLegacy' | 'mssqlLegacy'): string;
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {any} schemaJson
|
|
@@ -17,7 +17,7 @@ export interface Project {
|
|
|
17
17
|
name: string;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
interface
|
|
20
|
+
interface RawTableRecord {
|
|
21
21
|
schemaName: string | undefined;
|
|
22
22
|
tableName: string;
|
|
23
23
|
columns: string[];
|
|
@@ -27,12 +27,12 @@ interface RawRecord {
|
|
|
27
27
|
}[][];
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export interface
|
|
30
|
+
export interface TableRecord extends RawTableRecord {
|
|
31
31
|
id: number;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export interface
|
|
35
|
-
[_id: number]:
|
|
34
|
+
export interface NormalizedRecords {
|
|
35
|
+
[_id: number]: TableRecord;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export interface RawDatabase {
|
|
@@ -43,7 +43,7 @@ export interface RawDatabase {
|
|
|
43
43
|
refs: Ref[];
|
|
44
44
|
tableGroups: TableGroup[];
|
|
45
45
|
project: Project;
|
|
46
|
-
records:
|
|
46
|
+
records: RawTableRecord[];
|
|
47
47
|
}
|
|
48
48
|
declare class Database extends Element {
|
|
49
49
|
dbState: DbState;
|
|
@@ -54,11 +54,11 @@ declare class Database extends Element {
|
|
|
54
54
|
noteToken: Token;
|
|
55
55
|
databaseType: string;
|
|
56
56
|
name: string;
|
|
57
|
-
records:
|
|
57
|
+
records: TableRecord[];
|
|
58
58
|
id: number;
|
|
59
59
|
constructor({ schemas, tables, enums, refs, tableGroups, project, records }: RawDatabase);
|
|
60
60
|
generateId(): void;
|
|
61
|
-
processRecords(rawRecords:
|
|
61
|
+
processRecords(rawRecords: RawTableRecord[]): void;
|
|
62
62
|
processSchemas(rawSchemas: RawSchema[]): void;
|
|
63
63
|
pushSchema(schema: Schema): void;
|
|
64
64
|
checkSchema(schema: Schema): void;
|
|
@@ -242,6 +242,6 @@ export interface NormalizedDatabase {
|
|
|
242
242
|
indexes: NormalizedIndex;
|
|
243
243
|
indexColumns: NormalizedIndexColumn;
|
|
244
244
|
fields: NormalizedField;
|
|
245
|
-
records:
|
|
245
|
+
records: NormalizedRecords;
|
|
246
246
|
}
|
|
247
247
|
export default Database;
|