@dbml/core 3.0.0 → 3.1.1
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/database.js +5 -3
- package/lib/model_structure/enum.js +6 -3
- package/lib/model_structure/enumValue.js +6 -3
- package/lib/model_structure/field.js +6 -3
- package/lib/model_structure/schema.js +6 -3
- package/lib/model_structure/table.js +6 -3
- package/lib/parse/ANTLR/ASTGeneration/AST.js +54 -8
- package/lib/parse/ANTLR/ASTGeneration/ParserErrorListener.js +11 -6
- package/lib/parse/ANTLR/ASTGeneration/constants.js +39 -0
- package/lib/parse/ANTLR/ASTGeneration/index.js +33 -11
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +1148 -0
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +64 -62
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.g4 +1357 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.interp +3515 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.js +1211 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.tokens +2300 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.g4 +3494 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.interp +2694 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.js +3 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.tokens +2300 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParserVisitor.js +4360 -0
- package/lib/parse/Parser.js +8 -0
- package/package.json +3 -3
|
@@ -8,6 +8,7 @@ exports["default"] = void 0;
|
|
|
8
8
|
var _lodash = require("lodash");
|
|
9
9
|
var _PostgreSQLParserVisitor = _interopRequireDefault(require("../../parsers/postgresql/PostgreSQLParserVisitor"));
|
|
10
10
|
var _AST = require("../AST");
|
|
11
|
+
var _constants = require("../constants");
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
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; }
|
|
13
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; }
|
|
@@ -37,22 +38,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
37
38
|
var COMMAND_KIND = {
|
|
38
39
|
REF: 'ref'
|
|
39
40
|
};
|
|
40
|
-
var TABLE_CONSTRAINT_KIND = {
|
|
41
|
-
FIELD: 'field',
|
|
42
|
-
INDEX: 'index',
|
|
43
|
-
FK: 'fk',
|
|
44
|
-
UNIQUE: 'unique'
|
|
45
|
-
};
|
|
46
41
|
var COMMENT_OBJECT_TYPE = {
|
|
47
42
|
TABLE: 'table'
|
|
48
43
|
};
|
|
49
|
-
|
|
50
|
-
// legacy - for compatibility with model_structure
|
|
51
|
-
var CONSTRAINT_TYPE = {
|
|
52
|
-
COLUMN: 'column',
|
|
53
|
-
STRING: 'string',
|
|
54
|
-
EXPRESSION: 'expression'
|
|
55
|
-
};
|
|
56
44
|
var findTable = function findTable(tables, schemaName, tableName) {
|
|
57
45
|
var realSchemaName = schemaName || 'public';
|
|
58
46
|
var table = tables.find(function (table) {
|
|
@@ -157,7 +145,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
157
145
|
return e;
|
|
158
146
|
});
|
|
159
147
|
var _tableElements$reduce = tableElements.reduce(function (acc, ele) {
|
|
160
|
-
if (ele.kind === TABLE_CONSTRAINT_KIND.FIELD) acc[0].push(ele.value);else if (ele.kind === TABLE_CONSTRAINT_KIND.INDEX) acc[1].push(ele.value);else if (ele.kind === TABLE_CONSTRAINT_KIND.FK) acc[2].push(ele.value);else if (ele.kind === TABLE_CONSTRAINT_KIND.UNIQUE) acc[1].push(ele.value);
|
|
148
|
+
if (ele.kind === _constants.TABLE_CONSTRAINT_KIND.FIELD) acc[0].push(ele.value);else if (ele.kind === _constants.TABLE_CONSTRAINT_KIND.INDEX) acc[1].push(ele.value);else if (ele.kind === _constants.TABLE_CONSTRAINT_KIND.FK) acc[2].push(ele.value);else if (ele.kind === _constants.TABLE_CONSTRAINT_KIND.UNIQUE) acc[1].push(ele.value);
|
|
161
149
|
return acc;
|
|
162
150
|
}, [[], [], []]),
|
|
163
151
|
_tableElements$reduce2 = _slicedToArray(_tableElements$reduce, 3),
|
|
@@ -237,7 +225,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
237
225
|
value: function visitConstraintelem(ctx) {
|
|
238
226
|
if (ctx.PRIMARY()) {
|
|
239
227
|
return {
|
|
240
|
-
kind: TABLE_CONSTRAINT_KIND.INDEX,
|
|
228
|
+
kind: _constants.TABLE_CONSTRAINT_KIND.INDEX,
|
|
241
229
|
value: new _AST.Index({
|
|
242
230
|
pk: true,
|
|
243
231
|
columns: ctx.columnlist().accept(this)
|
|
@@ -262,7 +250,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
262
250
|
});
|
|
263
251
|
var actions = ctx.key_actions().accept(this);
|
|
264
252
|
return {
|
|
265
|
-
kind: TABLE_CONSTRAINT_KIND.FK,
|
|
253
|
+
kind: _constants.TABLE_CONSTRAINT_KIND.FK,
|
|
266
254
|
value: {
|
|
267
255
|
endpoints: [{
|
|
268
256
|
tableName: null,
|
|
@@ -282,7 +270,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
282
270
|
}
|
|
283
271
|
if (ctx.UNIQUE()) {
|
|
284
272
|
return {
|
|
285
|
-
kind: TABLE_CONSTRAINT_KIND.UNIQUE,
|
|
273
|
+
kind: _constants.TABLE_CONSTRAINT_KIND.UNIQUE,
|
|
286
274
|
value: new _AST.Index({
|
|
287
275
|
unique: true,
|
|
288
276
|
columns: ctx.columnlist().accept(this)
|
|
@@ -315,7 +303,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
315
303
|
value: function visitColumnElem(ctx) {
|
|
316
304
|
return {
|
|
317
305
|
value: ctx.colid().accept(this),
|
|
318
|
-
type: CONSTRAINT_TYPE.COLUMN
|
|
306
|
+
type: _constants.CONSTRAINT_TYPE.COLUMN
|
|
319
307
|
};
|
|
320
308
|
}
|
|
321
309
|
|
|
@@ -330,7 +318,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
330
318
|
var columnTypeName = type.type_name.toLowerCase();
|
|
331
319
|
if (serialIncrementType.has(columnTypeName)) contraints.increment = true;
|
|
332
320
|
return {
|
|
333
|
-
kind: TABLE_CONSTRAINT_KIND.FIELD,
|
|
321
|
+
kind: _constants.TABLE_CONSTRAINT_KIND.FIELD,
|
|
334
322
|
value: {
|
|
335
323
|
field: new _AST.Field(_objectSpread({
|
|
336
324
|
name: name,
|
|
@@ -352,7 +340,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
352
340
|
ctx.colconstraint().forEach(function (c) {
|
|
353
341
|
var constraint = c.accept(_this5);
|
|
354
342
|
if (!constraint) return;
|
|
355
|
-
if (constraint.kind ===
|
|
343
|
+
if (constraint.kind === _constants.COLUMN_CONSTRAINT_KIND.INLINE_REF) {
|
|
356
344
|
r.inline_refs.push(constraint.value);
|
|
357
345
|
return;
|
|
358
346
|
}
|
|
@@ -389,29 +377,37 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
389
377
|
key: "visitColconstraintelem",
|
|
390
378
|
value: function visitColconstraintelem(ctx) {
|
|
391
379
|
if (ctx.NULL_P()) {
|
|
392
|
-
var
|
|
393
|
-
if (ctx.NOT())
|
|
380
|
+
var notNull = false;
|
|
381
|
+
if (ctx.NOT()) notNull = true;
|
|
394
382
|
return {
|
|
395
|
-
kind:
|
|
396
|
-
value:
|
|
383
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.NOT_NULL,
|
|
384
|
+
value: notNull
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
if (ctx.UNIQUE()) {
|
|
388
|
+
return {
|
|
389
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.UNIQUE,
|
|
390
|
+
value: true
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
if (ctx.PRIMARY()) {
|
|
394
|
+
return {
|
|
395
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.PK,
|
|
396
|
+
value: true
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
if (ctx.DEFAULT()) {
|
|
400
|
+
return {
|
|
401
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.DEFAULT,
|
|
402
|
+
value: ctx.b_expr().accept(this)
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
if (ctx.IDENTITY_P()) {
|
|
406
|
+
return {
|
|
407
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.INCREMENT,
|
|
408
|
+
value: true
|
|
397
409
|
};
|
|
398
410
|
}
|
|
399
|
-
if (ctx.UNIQUE()) return {
|
|
400
|
-
kind: 'unique',
|
|
401
|
-
value: true
|
|
402
|
-
};
|
|
403
|
-
if (ctx.PRIMARY()) return {
|
|
404
|
-
kind: 'pk',
|
|
405
|
-
value: true
|
|
406
|
-
};
|
|
407
|
-
if (ctx.DEFAULT()) return {
|
|
408
|
-
kind: 'dbdefault',
|
|
409
|
-
value: ctx.b_expr().accept(this)
|
|
410
|
-
};
|
|
411
|
-
if (ctx.IDENTITY_P()) return {
|
|
412
|
-
kind: 'increment',
|
|
413
|
-
value: true
|
|
414
|
-
};
|
|
415
411
|
if (ctx.REFERENCES()) {
|
|
416
412
|
var _ctx$opt_column_list$2;
|
|
417
413
|
var names = ctx.qualified_name().accept(this);
|
|
@@ -422,7 +418,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
422
418
|
});
|
|
423
419
|
var actions = ctx.key_actions().accept(this);
|
|
424
420
|
return {
|
|
425
|
-
kind:
|
|
421
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.INLINE_REF,
|
|
426
422
|
value: {
|
|
427
423
|
endpoints: [{
|
|
428
424
|
tableName: null,
|
|
@@ -449,7 +445,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
449
445
|
if (ctx.c_expr()) return ctx.c_expr().accept(this);
|
|
450
446
|
return {
|
|
451
447
|
value: ctx.getText(),
|
|
452
|
-
type:
|
|
448
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
453
449
|
};
|
|
454
450
|
}
|
|
455
451
|
|
|
@@ -460,11 +456,11 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
460
456
|
if (ctx.aexprconst()) return ctx.aexprconst().accept(this);
|
|
461
457
|
if (ctx.a_expr()) return {
|
|
462
458
|
value: ctx.a_expr().getText(),
|
|
463
|
-
type:
|
|
459
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
464
460
|
};
|
|
465
461
|
return {
|
|
466
462
|
value: ctx.getText(),
|
|
467
|
-
type:
|
|
463
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
468
464
|
};
|
|
469
465
|
}
|
|
470
466
|
}, {
|
|
@@ -472,7 +468,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
472
468
|
value: function visitC_expr_exists(ctx) {
|
|
473
469
|
return {
|
|
474
470
|
value: ctx.getText(),
|
|
475
|
-
type:
|
|
471
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
476
472
|
};
|
|
477
473
|
}
|
|
478
474
|
}, {
|
|
@@ -480,7 +476,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
480
476
|
value: function visitC_expr_case(ctx) {
|
|
481
477
|
return {
|
|
482
478
|
value: ctx.getText(),
|
|
483
|
-
type:
|
|
479
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
484
480
|
};
|
|
485
481
|
}
|
|
486
482
|
|
|
@@ -488,21 +484,27 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
488
484
|
}, {
|
|
489
485
|
key: "visitAexprconst",
|
|
490
486
|
value: function visitAexprconst(ctx) {
|
|
491
|
-
if (ctx.sconst() && ctx.getChildCount() === 1)
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
}
|
|
487
|
+
if (ctx.sconst() && ctx.getChildCount() === 1) {
|
|
488
|
+
return {
|
|
489
|
+
value: ctx.sconst().accept(this),
|
|
490
|
+
type: _constants.DATA_TYPE.STRING
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
if (ctx.TRUE_P() || ctx.FALSE_P() || ctx.NULL_P()) {
|
|
494
|
+
return {
|
|
495
|
+
value: ctx.getText(),
|
|
496
|
+
type: _constants.DATA_TYPE.BOOLEAN
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
if (ctx.iconst() || ctx.fconst) {
|
|
500
|
+
return {
|
|
501
|
+
value: ctx.getText(),
|
|
502
|
+
type: _constants.DATA_TYPE.NUMBER
|
|
503
|
+
};
|
|
504
|
+
}
|
|
503
505
|
return {
|
|
504
506
|
value: ctx.getText(),
|
|
505
|
-
type:
|
|
507
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
506
508
|
};
|
|
507
509
|
}
|
|
508
510
|
|
|
@@ -875,12 +877,12 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
875
877
|
if (ctx.colid()) {
|
|
876
878
|
return {
|
|
877
879
|
value: ctx.colid().accept(this),
|
|
878
|
-
type: CONSTRAINT_TYPE.STRING
|
|
880
|
+
type: _constants.CONSTRAINT_TYPE.STRING
|
|
879
881
|
};
|
|
880
882
|
}
|
|
881
883
|
return {
|
|
882
884
|
value: ctx.getText(),
|
|
883
|
-
type: CONSTRAINT_TYPE.EXPRESSION
|
|
885
|
+
type: _constants.CONSTRAINT_TYPE.EXPRESSION
|
|
884
886
|
};
|
|
885
887
|
}
|
|
886
888
|
|
|
@@ -915,7 +917,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
915
917
|
if (!cmd) return;
|
|
916
918
|
var kind = null;
|
|
917
919
|
switch (cmd.kind) {
|
|
918
|
-
case TABLE_CONSTRAINT_KIND.FK:
|
|
920
|
+
case _constants.TABLE_CONSTRAINT_KIND.FK:
|
|
919
921
|
kind = COMMAND_KIND.REF;
|
|
920
922
|
cmd.value.endpoints[0].tableName = tableName;
|
|
921
923
|
cmd.value.endpoints[0].schemaName = schemaName;
|