@dbml/core 2.6.1 → 3.1.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/MysqlExporter.js +3 -3
- package/lib/export/PostgresExporter.js +2 -2
- package/lib/export/SqlServerExporter.js +2 -2
- package/lib/export/index.js +1 -1
- package/lib/import/index.js +1 -1
- 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/mysql/MySQLBaseCommon.js +31 -0
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLBaseLexer.js +40 -0
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLBaseRecognizer.js +32 -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/ANTLR/parsers/mysql/predefined.tokens +744 -0
- package/lib/parse/Parser.js +73 -38
- package/package.json +3 -2
- package/types/parse/Parser.d.ts +3 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PipesAsConcat = exports.NoMode = exports.NoBackslashEscapes = exports.IgnoreSpace = exports.HighNotPrecedence = exports.AnsiQuotes = void 0;
|
|
7
|
+
exports.isSqlModeActive = isSqlModeActive;
|
|
8
|
+
exports.serverVersion = void 0;
|
|
9
|
+
/* eslint-disable no-bitwise */
|
|
10
|
+
|
|
11
|
+
// SqlMode definition: https://github.com/mysql/mysql-workbench/blob/6e135fb33942123c57f059139cbd787bea4f3f9b/library/parsers/mysql/MySQLRecognizerCommon.h#L51
|
|
12
|
+
var NoMode = 0;
|
|
13
|
+
exports.NoMode = NoMode;
|
|
14
|
+
var AnsiQuotes = 1 << 0;
|
|
15
|
+
exports.AnsiQuotes = AnsiQuotes;
|
|
16
|
+
var HighNotPrecedence = 1 << 1;
|
|
17
|
+
exports.HighNotPrecedence = HighNotPrecedence;
|
|
18
|
+
var PipesAsConcat = 1 << 2;
|
|
19
|
+
exports.PipesAsConcat = PipesAsConcat;
|
|
20
|
+
var IgnoreSpace = 1 << 3;
|
|
21
|
+
exports.IgnoreSpace = IgnoreSpace;
|
|
22
|
+
var NoBackslashEscapes = 1 << 4;
|
|
23
|
+
// These flags affect parsing behavior. https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html
|
|
24
|
+
exports.NoBackslashEscapes = NoBackslashEscapes;
|
|
25
|
+
var sqlMode = NoMode;
|
|
26
|
+
// https://github.com/mysql/mysql-workbench/blob/6e135fb33942123c57f059139cbd787bea4f3f9b/library/parsers/mysql/MySQLRecognizerCommon.cpp#L51
|
|
27
|
+
function isSqlModeActive(mode) {
|
|
28
|
+
return (sqlMode & mode) !== 0;
|
|
29
|
+
}
|
|
30
|
+
var serverVersion = 80000;
|
|
31
|
+
exports.serverVersion = serverVersion;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _antlr = _interopRequireDefault(require("antlr4"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
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); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
16
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
17
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
18
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
19
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
+
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; } }
|
|
21
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
|
+
/* Based on Oracle base class: https://github.com/mysql/mysql-workbench/blob/8.0/library/parsers/mysql/MySQLBaseLexer.h */
|
|
23
|
+
var MySQLBaseLexer = /*#__PURE__*/function (_antlr4$Lexer) {
|
|
24
|
+
_inherits(MySQLBaseLexer, _antlr4$Lexer);
|
|
25
|
+
var _super = _createSuper(MySQLBaseLexer);
|
|
26
|
+
function MySQLBaseLexer() {
|
|
27
|
+
_classCallCheck(this, MySQLBaseLexer);
|
|
28
|
+
return _super.apply(this, arguments);
|
|
29
|
+
}
|
|
30
|
+
_createClass(MySQLBaseLexer, [{
|
|
31
|
+
key: "setType",
|
|
32
|
+
value:
|
|
33
|
+
// https://www.antlr.org/api/Java/org/antlr/v4/runtime/Lexer.html#setType(int)
|
|
34
|
+
function setType(val) {
|
|
35
|
+
this.type = val;
|
|
36
|
+
}
|
|
37
|
+
}]);
|
|
38
|
+
return MySQLBaseLexer;
|
|
39
|
+
}(_antlr["default"].Lexer);
|
|
40
|
+
exports["default"] = MySQLBaseLexer;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _antlr = _interopRequireDefault(require("antlr4"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
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); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
16
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
17
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
18
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
19
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
+
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; } }
|
|
21
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
|
+
/* Based on Oracle base class: https://github.com/mysql/mysql-workbench/blob/8.0/library/parsers/mysql/MySQLBaseRecognizer.h */
|
|
23
|
+
var MySQLBaseRecognizer = /*#__PURE__*/function (_antlr4$Parser) {
|
|
24
|
+
_inherits(MySQLBaseRecognizer, _antlr4$Parser);
|
|
25
|
+
var _super = _createSuper(MySQLBaseRecognizer);
|
|
26
|
+
function MySQLBaseRecognizer() {
|
|
27
|
+
_classCallCheck(this, MySQLBaseRecognizer);
|
|
28
|
+
return _super.apply(this, arguments);
|
|
29
|
+
}
|
|
30
|
+
return _createClass(MySQLBaseRecognizer);
|
|
31
|
+
}(_antlr["default"].Parser);
|
|
32
|
+
exports["default"] = MySQLBaseRecognizer;
|
|
@@ -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;
|