@dbml/core 4.0.0 → 5.0.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/export/DbmlExporter.js +19 -19
- package/lib/export/MysqlExporter.js +21 -21
- package/lib/export/OracleExporter.js +21 -21
- package/lib/export/PostgresExporter.js +21 -21
- package/lib/export/SqlServerExporter.js +23 -23
- package/lib/model_structure/{constraint.js → check.js} +9 -9
- package/lib/model_structure/database.js +1 -1
- package/lib/model_structure/dbState.js +1 -1
- package/lib/model_structure/field.js +13 -13
- package/lib/model_structure/table.js +19 -19
- package/lib/model_structure/tablePartial.js +3 -3
- package/lib/parse/ANTLR/ASTGeneration/AST.js +8 -8
- package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +9 -9
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +5 -5
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +6 -6
- package/lib/parse/schemarb/parser.pegjs +14 -14
- package/lib/parse/schemarbParser.js +18 -18
- package/package.json +3 -3
- package/types/model_structure/{constraint.d.ts → check.d.ts} +5 -5
- package/types/model_structure/database.d.ts +2 -2
- package/types/model_structure/dbState.d.ts +1 -0
- package/types/model_structure/field.d.ts +7 -7
- package/types/model_structure/table.d.ts +8 -8
- package/types/model_structure/tablePartial.d.ts +4 -4
|
@@ -11,7 +11,7 @@ var _field = _interopRequireDefault(require("./field"));
|
|
|
11
11
|
var _indexes = _interopRequireDefault(require("./indexes"));
|
|
12
12
|
var _config = require("./config");
|
|
13
13
|
var _utils = require("./utils");
|
|
14
|
-
var
|
|
14
|
+
var _check = _interopRequireDefault(require("./check"));
|
|
15
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
16
16
|
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
17
17
|
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."); }
|
|
@@ -45,8 +45,8 @@ var Table = /*#__PURE__*/function (_Element) {
|
|
|
45
45
|
fields = _ref$fields === void 0 ? [] : _ref$fields,
|
|
46
46
|
_ref$indexes = _ref.indexes,
|
|
47
47
|
indexes = _ref$indexes === void 0 ? [] : _ref$indexes,
|
|
48
|
-
_ref$
|
|
49
|
-
|
|
48
|
+
_ref$checks = _ref.checks,
|
|
49
|
+
checks = _ref$checks === void 0 ? [] : _ref$checks,
|
|
50
50
|
_ref$schema = _ref.schema,
|
|
51
51
|
schema = _ref$schema === void 0 ? {} : _ref$schema,
|
|
52
52
|
token = _ref.token,
|
|
@@ -64,7 +64,7 @@ var Table = /*#__PURE__*/function (_Element) {
|
|
|
64
64
|
_this.headerColor = headerColor;
|
|
65
65
|
_this.fields = [];
|
|
66
66
|
_this.indexes = [];
|
|
67
|
-
_this.
|
|
67
|
+
_this.checks = [];
|
|
68
68
|
_this.schema = schema;
|
|
69
69
|
_this.partials = partials;
|
|
70
70
|
_this.dbState = _this.schema.dbState;
|
|
@@ -75,7 +75,7 @@ var Table = /*#__PURE__*/function (_Element) {
|
|
|
75
75
|
_this.processPartials();
|
|
76
76
|
_this.checkFieldCount();
|
|
77
77
|
_this.processIndexes(indexes);
|
|
78
|
-
_this.
|
|
78
|
+
_this.processChecks(checks);
|
|
79
79
|
return _this;
|
|
80
80
|
}
|
|
81
81
|
_inherits(Table, _Element);
|
|
@@ -143,19 +143,19 @@ var Table = /*#__PURE__*/function (_Element) {
|
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
}, {
|
|
146
|
-
key: "
|
|
147
|
-
value: function
|
|
146
|
+
key: "processChecks",
|
|
147
|
+
value: function processChecks(checks) {
|
|
148
148
|
var _this5 = this;
|
|
149
|
-
|
|
150
|
-
_this5.
|
|
149
|
+
checks.forEach(function (check) {
|
|
150
|
+
_this5.pushCheck(new _check["default"](_objectSpread(_objectSpread({}, check), {}, {
|
|
151
151
|
table: _this5
|
|
152
152
|
})));
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
155
|
}, {
|
|
156
|
-
key: "
|
|
157
|
-
value: function
|
|
158
|
-
this.
|
|
156
|
+
key: "pushCheck",
|
|
157
|
+
value: function pushCheck(check) {
|
|
158
|
+
this.checks.push(check);
|
|
159
159
|
}
|
|
160
160
|
}, {
|
|
161
161
|
key: "findField",
|
|
@@ -272,10 +272,10 @@ var Table = /*#__PURE__*/function (_Element) {
|
|
|
272
272
|
injectedPartial: tablePartial
|
|
273
273
|
})));
|
|
274
274
|
});
|
|
275
|
-
tablePartial.
|
|
276
|
-
_this6.
|
|
277
|
-
name:
|
|
278
|
-
// deduplicate
|
|
275
|
+
tablePartial.checks.forEach(function (check) {
|
|
276
|
+
_this6.checks.push(new _check["default"](_objectSpread(_objectSpread({}, check), {}, {
|
|
277
|
+
name: check.name && "".concat(_this6.name, ".").concat(check.name),
|
|
278
|
+
// deduplicate check names when instantiated to tables
|
|
279
279
|
table: _this6,
|
|
280
280
|
injectedPartial: tablePartial
|
|
281
281
|
})));
|
|
@@ -309,7 +309,7 @@ var Table = /*#__PURE__*/function (_Element) {
|
|
|
309
309
|
indexIds: this.indexes.map(function (i) {
|
|
310
310
|
return i.id;
|
|
311
311
|
}),
|
|
312
|
-
|
|
312
|
+
checkIds: this.checks.map(function (c) {
|
|
313
313
|
return c.id;
|
|
314
314
|
})
|
|
315
315
|
};
|
|
@@ -345,8 +345,8 @@ var Table = /*#__PURE__*/function (_Element) {
|
|
|
345
345
|
this.indexes.forEach(function (index) {
|
|
346
346
|
return index.normalize(model);
|
|
347
347
|
});
|
|
348
|
-
this.
|
|
349
|
-
return
|
|
348
|
+
this.checks.forEach(function (check) {
|
|
349
|
+
return check.normalize(model);
|
|
350
350
|
});
|
|
351
351
|
}
|
|
352
352
|
}]);
|
|
@@ -33,8 +33,8 @@ var TablePartial = /*#__PURE__*/function (_Element) {
|
|
|
33
33
|
fields = _ref$fields === void 0 ? [] : _ref$fields,
|
|
34
34
|
_ref$indexes = _ref.indexes,
|
|
35
35
|
indexes = _ref$indexes === void 0 ? [] : _ref$indexes,
|
|
36
|
-
_ref$
|
|
37
|
-
|
|
36
|
+
_ref$checks = _ref.checks,
|
|
37
|
+
checks = _ref$checks === void 0 ? [] : _ref$checks,
|
|
38
38
|
token = _ref.token,
|
|
39
39
|
headerColor = _ref.headerColor,
|
|
40
40
|
_ref$noteToken = _ref.noteToken,
|
|
@@ -48,7 +48,7 @@ var TablePartial = /*#__PURE__*/function (_Element) {
|
|
|
48
48
|
_this.headerColor = headerColor;
|
|
49
49
|
_this.fields = fields;
|
|
50
50
|
_this.indexes = indexes;
|
|
51
|
-
_this.
|
|
51
|
+
_this.checks = checks;
|
|
52
52
|
_this.dbState = dbState;
|
|
53
53
|
_this.generateId();
|
|
54
54
|
return _this;
|
|
@@ -71,7 +71,7 @@ var Field = exports.Field = /*#__PURE__*/function () {
|
|
|
71
71
|
* unique: boolean,
|
|
72
72
|
* pk: boolean,
|
|
73
73
|
* note: {value: string},
|
|
74
|
-
*
|
|
74
|
+
* checks: {expression: string, name?: string}[]
|
|
75
75
|
* }} param0
|
|
76
76
|
*/
|
|
77
77
|
function Field(_ref2) {
|
|
@@ -83,7 +83,7 @@ var Field = exports.Field = /*#__PURE__*/function () {
|
|
|
83
83
|
unique = _ref2.unique,
|
|
84
84
|
pk = _ref2.pk,
|
|
85
85
|
note = _ref2.note,
|
|
86
|
-
|
|
86
|
+
checks = _ref2.checks;
|
|
87
87
|
_classCallCheck(this, Field);
|
|
88
88
|
/** @type {string} */
|
|
89
89
|
this.name = name;
|
|
@@ -110,7 +110,7 @@ var Field = exports.Field = /*#__PURE__*/function () {
|
|
|
110
110
|
this.note = note;
|
|
111
111
|
|
|
112
112
|
/** @type {{expression: string, name?: string}[]} */
|
|
113
|
-
this.
|
|
113
|
+
this.checks = checks;
|
|
114
114
|
}
|
|
115
115
|
return _createClass(Field, [{
|
|
116
116
|
key: "toJSON",
|
|
@@ -124,7 +124,7 @@ var Field = exports.Field = /*#__PURE__*/function () {
|
|
|
124
124
|
unique: this.unique,
|
|
125
125
|
pk: this.pk,
|
|
126
126
|
note: this.note,
|
|
127
|
-
|
|
127
|
+
checks: this.checks
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
}]);
|
|
@@ -137,7 +137,7 @@ var Table = exports.Table = /*#__PURE__*/function () {
|
|
|
137
137
|
* fields: Field[],
|
|
138
138
|
* indexes: Index[],
|
|
139
139
|
* note: {value: string},
|
|
140
|
-
*
|
|
140
|
+
* checks: {expression: string, name?: string}[]
|
|
141
141
|
* }} param0
|
|
142
142
|
*/
|
|
143
143
|
function Table(_ref3) {
|
|
@@ -146,7 +146,7 @@ var Table = exports.Table = /*#__PURE__*/function () {
|
|
|
146
146
|
fields = _ref3.fields,
|
|
147
147
|
indexes = _ref3.indexes,
|
|
148
148
|
note = _ref3.note,
|
|
149
|
-
|
|
149
|
+
checks = _ref3.checks;
|
|
150
150
|
_classCallCheck(this, Table);
|
|
151
151
|
/** @type {string} */
|
|
152
152
|
this.name = name;
|
|
@@ -164,7 +164,7 @@ var Table = exports.Table = /*#__PURE__*/function () {
|
|
|
164
164
|
this.note = note;
|
|
165
165
|
|
|
166
166
|
/** @type {{expression: string, name?: string}[]} */
|
|
167
|
-
this.
|
|
167
|
+
this.checks = checks || [];
|
|
168
168
|
}
|
|
169
169
|
return _createClass(Table, [{
|
|
170
170
|
key: "toJSON",
|
|
@@ -180,7 +180,7 @@ var Table = exports.Table = /*#__PURE__*/function () {
|
|
|
180
180
|
return i.toJSON();
|
|
181
181
|
}),
|
|
182
182
|
note: this.note,
|
|
183
|
-
|
|
183
|
+
checks: this.checks
|
|
184
184
|
};
|
|
185
185
|
}
|
|
186
186
|
}]);
|
|
@@ -609,7 +609,7 @@ var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor
|
|
|
609
609
|
schemaName: schemaName,
|
|
610
610
|
fields: fields,
|
|
611
611
|
indexes: tableIndices.concat(indexes),
|
|
612
|
-
|
|
612
|
+
checks: tableCheckConstraints
|
|
613
613
|
});
|
|
614
614
|
this.data.tables.push(table);
|
|
615
615
|
}
|
|
@@ -728,16 +728,16 @@ var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor
|
|
|
728
728
|
var _columnDef$value = columnDef.value,
|
|
729
729
|
_expression = _columnDef$value.expression,
|
|
730
730
|
name = _columnDef$value.name;
|
|
731
|
-
if (!field.
|
|
732
|
-
field.
|
|
731
|
+
if (!field.checks) {
|
|
732
|
+
field.checks = [];
|
|
733
733
|
}
|
|
734
|
-
var
|
|
734
|
+
var checkObj = {
|
|
735
735
|
expression: _expression
|
|
736
736
|
};
|
|
737
737
|
if (name) {
|
|
738
|
-
|
|
738
|
+
checkObj.name = name;
|
|
739
739
|
}
|
|
740
|
-
field.
|
|
740
|
+
field.checks.push(checkObj);
|
|
741
741
|
break;
|
|
742
742
|
}
|
|
743
743
|
default:
|
|
@@ -1183,13 +1183,13 @@ var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor
|
|
|
1183
1183
|
field.dbdefault = columnDefault.defaultValue;
|
|
1184
1184
|
});
|
|
1185
1185
|
checkConstraints.forEach(function (checkConstraint) {
|
|
1186
|
-
var
|
|
1186
|
+
var checkObj = {
|
|
1187
1187
|
expression: checkConstraint.expression
|
|
1188
1188
|
};
|
|
1189
1189
|
if (checkConstraint.name) {
|
|
1190
|
-
|
|
1190
|
+
checkObj.name = checkConstraint.name;
|
|
1191
1191
|
}
|
|
1192
|
-
table.
|
|
1192
|
+
table.checks.push(checkObj);
|
|
1193
1193
|
});
|
|
1194
1194
|
}
|
|
1195
1195
|
|
|
@@ -157,7 +157,7 @@ var MySQLASTGen = exports["default"] = /*#__PURE__*/function (_MySQLParserVisito
|
|
|
157
157
|
indexes = _definitions$reduce2[1],
|
|
158
158
|
tableRefs = _definitions$reduce2[2],
|
|
159
159
|
singlePkIndex = _definitions$reduce2[3],
|
|
160
|
-
|
|
160
|
+
tableChecks = _definitions$reduce2[4];
|
|
161
161
|
var inlineRefsOfFields = fieldsData.map(function (fieldData) {
|
|
162
162
|
var _field$type$type_name;
|
|
163
163
|
var field = fieldData.field,
|
|
@@ -202,7 +202,7 @@ var MySQLASTGen = exports["default"] = /*#__PURE__*/function (_MySQLParserVisito
|
|
|
202
202
|
return fd.field;
|
|
203
203
|
}),
|
|
204
204
|
indexes: indexes,
|
|
205
|
-
|
|
205
|
+
checks: tableChecks
|
|
206
206
|
}, tableOptions));
|
|
207
207
|
if (singlePkIndex) {
|
|
208
208
|
var field = table.fields.find(function (f) {
|
|
@@ -413,7 +413,7 @@ var MySQLASTGen = exports["default"] = /*#__PURE__*/function (_MySQLParserVisito
|
|
|
413
413
|
var type = ctx.dataType().accept(this);
|
|
414
414
|
var constraints = {
|
|
415
415
|
inlineRefs: [],
|
|
416
|
-
|
|
416
|
+
checks: []
|
|
417
417
|
};
|
|
418
418
|
ctx.columnConstraint().forEach(function (c) {
|
|
419
419
|
var constraint = c.accept(_this9);
|
|
@@ -423,7 +423,7 @@ var MySQLASTGen = exports["default"] = /*#__PURE__*/function (_MySQLParserVisito
|
|
|
423
423
|
return;
|
|
424
424
|
}
|
|
425
425
|
if (constraint.kind === _constants.COLUMN_CONSTRAINT_KIND.CHECK) {
|
|
426
|
-
constraints.
|
|
426
|
+
constraints.checks.push(constraint.value);
|
|
427
427
|
return;
|
|
428
428
|
}
|
|
429
429
|
constraints[constraint.kind] = constraint.value;
|
|
@@ -1091,7 +1091,7 @@ var MySQLASTGen = exports["default"] = /*#__PURE__*/function (_MySQLParserVisito
|
|
|
1091
1091
|
ref.endpoints[0].tableName = tableName;
|
|
1092
1092
|
_this13.data.refs.push(ref);
|
|
1093
1093
|
} else if (alter.kind === ALTER_KIND.ADD_CHECK) {
|
|
1094
|
-
table.
|
|
1094
|
+
table.checks.push(alter.value);
|
|
1095
1095
|
}
|
|
1096
1096
|
return null;
|
|
1097
1097
|
});
|
|
@@ -165,7 +165,7 @@ var PostgresASTGen = exports["default"] = /*#__PURE__*/function (_PostgreSQLPars
|
|
|
165
165
|
fieldsData = _tableElements$reduce2[0],
|
|
166
166
|
indexes = _tableElements$reduce2[1],
|
|
167
167
|
tableRefs = _tableElements$reduce2[2],
|
|
168
|
-
|
|
168
|
+
tableChecks = _tableElements$reduce2[3];
|
|
169
169
|
(_this$data$refs = this.data.refs).push.apply(_this$data$refs, _toConsumableArray((0, _lodash.flatten)(fieldsData.map(function (fieldData) {
|
|
170
170
|
return fieldData.inline_refs.map(function (inlineRef) {
|
|
171
171
|
inlineRef.endpoints[0].tableName = tableName;
|
|
@@ -186,7 +186,7 @@ var PostgresASTGen = exports["default"] = /*#__PURE__*/function (_PostgreSQLPars
|
|
|
186
186
|
return fd.field;
|
|
187
187
|
}),
|
|
188
188
|
indexes: indexes,
|
|
189
|
-
|
|
189
|
+
checks: tableChecks
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
192
|
|
|
@@ -359,7 +359,7 @@ var PostgresASTGen = exports["default"] = /*#__PURE__*/function (_PostgreSQLPars
|
|
|
359
359
|
var _this5 = this;
|
|
360
360
|
var r = {
|
|
361
361
|
inline_refs: [],
|
|
362
|
-
|
|
362
|
+
checks: []
|
|
363
363
|
};
|
|
364
364
|
ctx.colconstraint().forEach(function (c) {
|
|
365
365
|
var constraint = c.accept(_this5);
|
|
@@ -369,7 +369,7 @@ var PostgresASTGen = exports["default"] = /*#__PURE__*/function (_PostgreSQLPars
|
|
|
369
369
|
return;
|
|
370
370
|
}
|
|
371
371
|
if (constraint.kind === _constants.COLUMN_CONSTRAINT_KIND.CHECK) {
|
|
372
|
-
r.
|
|
372
|
+
r.checks.push(constraint.value);
|
|
373
373
|
return;
|
|
374
374
|
}
|
|
375
375
|
r[constraint.kind] = constraint.value;
|
|
@@ -972,8 +972,8 @@ var PostgresASTGen = exports["default"] = /*#__PURE__*/function (_PostgreSQLPars
|
|
|
972
972
|
{
|
|
973
973
|
var table = findTable(_this8.data.tables, schemaName, tableName);
|
|
974
974
|
if (!table) break;
|
|
975
|
-
if (!table.
|
|
976
|
-
table.
|
|
975
|
+
if (!table.checks) table.checks = [];
|
|
976
|
+
table.checks.push(cmd.value);
|
|
977
977
|
break;
|
|
978
978
|
}
|
|
979
979
|
case _constants.TABLE_CONSTRAINT_KIND.UNIQUE:
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
if (!table) {
|
|
28
28
|
error("Table ${tableName} not found");
|
|
29
29
|
}
|
|
30
|
-
if (!table.
|
|
31
|
-
table.
|
|
30
|
+
if (!table.checks) {
|
|
31
|
+
table.checks = [];
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const check = { expression };
|
|
34
34
|
if (name) {
|
|
35
|
-
|
|
35
|
+
check.name = name;
|
|
36
36
|
}
|
|
37
|
-
table.
|
|
37
|
+
table.checks.push(check);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function addPrimaryKey(fields = [], props = []) {
|
|
@@ -284,8 +284,8 @@ rule = tableData:create_table_syntax {
|
|
|
284
284
|
|
|
285
285
|
add_check_constraint_syntax
|
|
286
286
|
= sp* add_check_constraint sp* tableName:(symbol / name) "," sp* expression:name props:check_constraint_props* {
|
|
287
|
-
const
|
|
288
|
-
addCheckConstraintToTable(tableName, expression,
|
|
287
|
+
const checkName = props.find(p => p.name)?.name;
|
|
288
|
+
addCheckConstraintToTable(tableName, expression, checkName);
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
add_foreign_key_syntax
|
|
@@ -319,8 +319,8 @@ create_table_syntax
|
|
|
319
319
|
fields: addPrimaryKey(body.fields),
|
|
320
320
|
// index: _.union(...body.index)
|
|
321
321
|
})
|
|
322
|
-
if (body.
|
|
323
|
-
table.
|
|
322
|
+
if (body.checks && body.checks.length > 0) {
|
|
323
|
+
table.checks = body.checks;
|
|
324
324
|
}
|
|
325
325
|
return {
|
|
326
326
|
table,
|
|
@@ -333,7 +333,7 @@ table_body = fields:field* {
|
|
|
333
333
|
fields: fields.filter(field => field.isField).map(field => field.field),
|
|
334
334
|
index: fields.filter(field => field.isIndex).map(field => field.index),
|
|
335
335
|
references: fields.filter(field => field.isReferences).map(field => field.reference),
|
|
336
|
-
|
|
336
|
+
checks: fields.filter(field => field.isCheck).map(field => field.check),
|
|
337
337
|
});
|
|
338
338
|
}
|
|
339
339
|
|
|
@@ -342,7 +342,7 @@ field = whitespace* field:table_field_syntax whatever* endline { return field }
|
|
|
342
342
|
table_field_syntax
|
|
343
343
|
= field_index_syntax
|
|
344
344
|
/ reference: field_reference_syntax { return ({ reference, isReferences: true })}
|
|
345
|
-
/
|
|
345
|
+
/ check: field_check_constraint_syntax { return ({ check, isCheck: true })}
|
|
346
346
|
/ field:field_type_syntax { return ({ field, isField: true }) }
|
|
347
347
|
|
|
348
348
|
field_index_syntax = index sp+ whateters
|
|
@@ -350,13 +350,13 @@ field_reference_syntax = references sp+ reference:reference_value {
|
|
|
350
350
|
return reference;
|
|
351
351
|
}
|
|
352
352
|
field_check_constraint_syntax = check_constraint sp+ expression:name props:check_constraint_props* {
|
|
353
|
-
const
|
|
353
|
+
const check = { expression };
|
|
354
354
|
for (let i = 0; i < props.length; i++) {
|
|
355
355
|
if (props[i].name) {
|
|
356
|
-
|
|
356
|
+
check.name = props[i].name;
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
|
-
return
|
|
359
|
+
return check;
|
|
360
360
|
}
|
|
361
361
|
field_type_syntax = type:field_type sp+ name:name {
|
|
362
362
|
return ({
|
|
@@ -129,10 +129,10 @@ function peg$parse(input, options) {
|
|
|
129
129
|
peg$c4 = peg$literalExpectation(",", false),
|
|
130
130
|
peg$c5 = function peg$c5(tableName, expression, props) {
|
|
131
131
|
var _props$find;
|
|
132
|
-
var
|
|
132
|
+
var checkName = (_props$find = props.find(function (p) {
|
|
133
133
|
return p.name;
|
|
134
134
|
})) === null || _props$find === void 0 ? void 0 : _props$find.name;
|
|
135
|
-
addCheckConstraintToTable(tableName, expression,
|
|
135
|
+
addCheckConstraintToTable(tableName, expression, checkName);
|
|
136
136
|
},
|
|
137
137
|
peg$c6 = function peg$c6(fromTable, toTable, props) {
|
|
138
138
|
var foreign = refactorForeign(createForeign(fromTable, toTable, props));
|
|
@@ -168,8 +168,8 @@ function peg$parse(input, options) {
|
|
|
168
168
|
fields: addPrimaryKey(body.fields)
|
|
169
169
|
// index: _.union(...body.index)
|
|
170
170
|
};
|
|
171
|
-
if (body.
|
|
172
|
-
table.
|
|
171
|
+
if (body.checks && body.checks.length > 0) {
|
|
172
|
+
table.checks = body.checks;
|
|
173
173
|
}
|
|
174
174
|
return {
|
|
175
175
|
table: table,
|
|
@@ -193,10 +193,10 @@ function peg$parse(input, options) {
|
|
|
193
193
|
}).map(function (field) {
|
|
194
194
|
return field.reference;
|
|
195
195
|
}),
|
|
196
|
-
|
|
197
|
-
return field.
|
|
196
|
+
checks: fields.filter(function (field) {
|
|
197
|
+
return field.isCheck;
|
|
198
198
|
}).map(function (field) {
|
|
199
|
-
return field.
|
|
199
|
+
return field.check;
|
|
200
200
|
})
|
|
201
201
|
};
|
|
202
202
|
},
|
|
@@ -209,10 +209,10 @@ function peg$parse(input, options) {
|
|
|
209
209
|
isReferences: true
|
|
210
210
|
};
|
|
211
211
|
},
|
|
212
|
-
peg$c16 = function peg$c16(
|
|
212
|
+
peg$c16 = function peg$c16(check) {
|
|
213
213
|
return {
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
check: check,
|
|
215
|
+
isCheck: true
|
|
216
216
|
};
|
|
217
217
|
},
|
|
218
218
|
peg$c17 = function peg$c17(field) {
|
|
@@ -225,15 +225,15 @@ function peg$parse(input, options) {
|
|
|
225
225
|
return reference;
|
|
226
226
|
},
|
|
227
227
|
peg$c19 = function peg$c19(expression, props) {
|
|
228
|
-
var
|
|
228
|
+
var check = {
|
|
229
229
|
expression: expression
|
|
230
230
|
};
|
|
231
231
|
for (var i = 0; i < props.length; i++) {
|
|
232
232
|
if (props[i].name) {
|
|
233
|
-
|
|
233
|
+
check.name = props[i].name;
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
-
return
|
|
236
|
+
return check;
|
|
237
237
|
},
|
|
238
238
|
peg$c20 = function peg$c20(type, name) {
|
|
239
239
|
return {
|
|
@@ -2466,16 +2466,16 @@ function peg$parse(input, options) {
|
|
|
2466
2466
|
if (!table) {
|
|
2467
2467
|
error("Table ${tableName} not found");
|
|
2468
2468
|
}
|
|
2469
|
-
if (!table.
|
|
2470
|
-
table.
|
|
2469
|
+
if (!table.checks) {
|
|
2470
|
+
table.checks = [];
|
|
2471
2471
|
}
|
|
2472
|
-
var
|
|
2472
|
+
var check = {
|
|
2473
2473
|
expression: expression
|
|
2474
2474
|
};
|
|
2475
2475
|
if (name) {
|
|
2476
|
-
|
|
2476
|
+
check.name = name;
|
|
2477
2477
|
}
|
|
2478
|
-
table.
|
|
2478
|
+
table.checks.push(check);
|
|
2479
2479
|
}
|
|
2480
2480
|
function addPrimaryKey() {
|
|
2481
2481
|
var fields = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.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": "^
|
|
35
|
+
"@dbml/parse": "^5.0.0",
|
|
36
36
|
"antlr4": "^4.13.1",
|
|
37
37
|
"lodash": "^4.17.15",
|
|
38
38
|
"parsimmon": "^1.13.0",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"^lodash-es$": "lodash"
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "a2d029e9c3c78ab0956312495165ec3115b5bc00",
|
|
66
66
|
"engines": {
|
|
67
67
|
"node": ">=16"
|
|
68
68
|
}
|
|
@@ -4,7 +4,7 @@ import Field from './field';
|
|
|
4
4
|
import Table from './table';
|
|
5
5
|
import TablePartial from './tablePartial';
|
|
6
6
|
|
|
7
|
-
interface
|
|
7
|
+
interface RawCheck {
|
|
8
8
|
token: Token;
|
|
9
9
|
name: string;
|
|
10
10
|
expression: string;
|
|
@@ -13,14 +13,14 @@ interface RawConstraint {
|
|
|
13
13
|
injectedPartial?: TablePartial | null;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
declare class
|
|
16
|
+
declare class Check extends Element {
|
|
17
17
|
name: string;
|
|
18
18
|
expression: string;
|
|
19
19
|
table: Table;
|
|
20
20
|
column: Field | null;
|
|
21
21
|
injectedPartial: TablePartial | null;
|
|
22
22
|
|
|
23
|
-
constructor({ token, name, expression, table, column, injectedPartial }:
|
|
23
|
+
constructor({ token, name, expression, table, column, injectedPartial }: RawCheck);
|
|
24
24
|
generateId(): void;
|
|
25
25
|
export(): {
|
|
26
26
|
name: string;
|
|
@@ -38,7 +38,7 @@ declare class Constraint extends Element {
|
|
|
38
38
|
normalize(model: NormalizedDatabase): void;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export interface
|
|
41
|
+
export interface NormalizedCheck {
|
|
42
42
|
[_id: number]: {
|
|
43
43
|
id: number;
|
|
44
44
|
name: string;
|
|
@@ -49,4 +49,4 @@ export interface NormalizedConstraint {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export default
|
|
52
|
+
export default Check;
|
|
@@ -11,7 +11,7 @@ import { NormalizedEnumValue } from './enumValue';
|
|
|
11
11
|
import { NormalizedField } from './field';
|
|
12
12
|
import { NormalizedIndexColumn } from './indexColumn';
|
|
13
13
|
import { NormalizedIndex } from './indexes';
|
|
14
|
-
import {
|
|
14
|
+
import { NormalizedCheck } from './check';
|
|
15
15
|
import TablePartial, { NormalizedTablePartial } from './tablePartial';
|
|
16
16
|
export interface Project {
|
|
17
17
|
note: RawNote;
|
|
@@ -300,7 +300,7 @@ export interface NormalizedDatabase {
|
|
|
300
300
|
enumValues: NormalizedEnumValue;
|
|
301
301
|
indexes: NormalizedIndex;
|
|
302
302
|
indexColumns: NormalizedIndexColumn;
|
|
303
|
-
|
|
303
|
+
checks: NormalizedCheck;
|
|
304
304
|
fields: NormalizedField;
|
|
305
305
|
records: NormalizedRecords;
|
|
306
306
|
tablePartials: NormalizedTablePartial;
|
|
@@ -5,7 +5,7 @@ import Endpoint from './endpoint';
|
|
|
5
5
|
import Enum from './enum';
|
|
6
6
|
import Table from './table';
|
|
7
7
|
import TablePartial from './tablePartial';
|
|
8
|
-
import
|
|
8
|
+
import Check from './check';
|
|
9
9
|
interface RawField {
|
|
10
10
|
name: string;
|
|
11
11
|
type: any;
|
|
@@ -16,7 +16,7 @@ interface RawField {
|
|
|
16
16
|
note: RawNote;
|
|
17
17
|
dbdefault: any;
|
|
18
18
|
increment: boolean;
|
|
19
|
-
|
|
19
|
+
checks?: any[];
|
|
20
20
|
table: Table;
|
|
21
21
|
}
|
|
22
22
|
declare class Field extends Element {
|
|
@@ -30,16 +30,16 @@ declare class Field extends Element {
|
|
|
30
30
|
noteToken: Token;
|
|
31
31
|
dbdefault: any;
|
|
32
32
|
increment: boolean;
|
|
33
|
-
|
|
33
|
+
checks: Check[];
|
|
34
34
|
table: Table;
|
|
35
35
|
endpoints: Endpoint[];
|
|
36
36
|
_enum: Enum;
|
|
37
37
|
injectedPartial?: TablePartial;
|
|
38
38
|
injectedToken: Token;
|
|
39
|
-
constructor({ name, type, unique, pk, token, not_null, note, dbdefault, increment,
|
|
39
|
+
constructor({ name, type, unique, pk, token, not_null, note, dbdefault, increment, checks, table }: RawField);
|
|
40
40
|
generateId(): void;
|
|
41
41
|
pushEndpoint(endpoint: any): void;
|
|
42
|
-
|
|
42
|
+
processChecks(checks: any[]): void;
|
|
43
43
|
export(): {
|
|
44
44
|
name: string;
|
|
45
45
|
type: any;
|
|
@@ -68,7 +68,7 @@ declare class Field extends Element {
|
|
|
68
68
|
dbdefault: any;
|
|
69
69
|
increment: boolean;
|
|
70
70
|
injectedPartialId?: number;
|
|
71
|
-
|
|
71
|
+
checkIds: number[];
|
|
72
72
|
};
|
|
73
73
|
normalize(model: NormalizedDatabase): void;
|
|
74
74
|
}
|
|
@@ -87,7 +87,7 @@ export interface NormalizedField {
|
|
|
87
87
|
endpointIds: number[];
|
|
88
88
|
enumId: number;
|
|
89
89
|
injectedPartialId?: number;
|
|
90
|
-
|
|
90
|
+
checkIds: number[];
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
export default Field;
|