@dbml/core 3.11.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/LICENSE +0 -0
- package/README.md +0 -0
- package/lib/export/DbmlExporter.js +0 -0
- package/lib/export/JsonExporter.js +0 -0
- package/lib/export/ModelExporter.js +0 -0
- package/lib/export/MysqlExporter.js +0 -0
- package/lib/export/OracleExporter.js +0 -0
- package/lib/export/PostgresExporter.js +0 -0
- package/lib/export/README.md +0 -0
- package/lib/export/SqlServerExporter.js +0 -0
- package/lib/export/index.js +0 -0
- package/lib/export/utils.js +0 -0
- package/lib/import/index.js +0 -0
- package/lib/index.js +0 -0
- package/lib/model_structure/config.js +0 -0
- package/lib/model_structure/database.js +39 -10
- package/lib/model_structure/dbState.js +1 -0
- package/lib/model_structure/element.js +0 -0
- package/lib/model_structure/endpoint.js +0 -0
- package/lib/model_structure/enum.js +0 -0
- package/lib/model_structure/enumValue.js +0 -0
- package/lib/model_structure/field.js +0 -0
- package/lib/model_structure/indexColumn.js +0 -0
- package/lib/model_structure/indexes.js +0 -0
- package/lib/model_structure/ref.js +0 -0
- package/lib/model_structure/schema.js +0 -0
- package/lib/model_structure/stickyNote.js +0 -0
- package/lib/model_structure/table.js +0 -0
- package/lib/model_structure/tableGroup.js +0 -0
- package/lib/model_structure/utils.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/AST.js +47 -2
- package/lib/parse/ANTLR/ASTGeneration/ParserErrorListener.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/SyntaxError.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/constants.js +4 -2
- package/lib/parse/ANTLR/ASTGeneration/helpers.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/index.js +21 -5
- package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +1503 -0
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +157 -4
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLLexerBase.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLParserBase.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +223 -5
- package/lib/parse/ANTLR/ASTGeneration/snowflake/SnowflakeASTGen.js +0 -0
- package/lib/parse/ANTLR/README.md +6 -1
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.g4 +1300 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.interp +3643 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.js +1255 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.tokens +2385 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.g4 +6313 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.interp +3034 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.js +3 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.tokens +2385 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParserVisitor.js +5732 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.g4 +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.interp +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.js +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.tokens +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.g4 +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.interp +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.js +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.tokens +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParserVisitor.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.g4 +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.interp +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.tokens +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/README.md +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.g4 +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.interp +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.js +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.tokens +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.g4 +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.interp +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.js +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.tokens +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParserVisitor.js +0 -0
- package/lib/parse/Parser.js +9 -1
- package/lib/parse/buildParser.js +0 -0
- package/lib/parse/databaseGenerator.js +0 -0
- package/lib/parse/dbml/parser.pegjs +0 -0
- package/lib/parse/dbmlParser.js +0 -0
- package/lib/parse/error.js +0 -0
- package/lib/parse/mssql/base_parsers.js +0 -0
- package/lib/parse/mssql/column_definition/actions.js +0 -0
- package/lib/parse/mssql/column_definition/index.js +0 -0
- package/lib/parse/mssql/constraint_definition/actions.js +0 -0
- package/lib/parse/mssql/constraint_definition/index.js +0 -0
- package/lib/parse/mssql/expression.js +0 -0
- package/lib/parse/mssql/fk_definition/actions.js +0 -0
- package/lib/parse/mssql/fk_definition/index.js +0 -0
- package/lib/parse/mssql/index.js +0 -0
- package/lib/parse/mssql/index_definition/actions.js +0 -0
- package/lib/parse/mssql/index_definition/index.js +0 -0
- package/lib/parse/mssql/keyword_parsers.js +0 -0
- package/lib/parse/mssql/keyword_utils.js +0 -0
- package/lib/parse/mssql/statements/actions.js +0 -0
- package/lib/parse/mssql/statements/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/add/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/add/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/comments/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/comments/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_index/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_index/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_table/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_table/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/index.js +0 -0
- package/lib/parse/mssql/utils.js +0 -0
- package/lib/parse/mssql/whitespaces.js +0 -0
- package/lib/parse/mssqlParser.js +0 -0
- package/lib/parse/mysql/parser.pegjs +0 -0
- package/lib/parse/mysqlParser.js +0 -0
- package/lib/parse/postgresParser.js +0 -0
- package/lib/parse/postgresql/Base_rules.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Commands.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Comment.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_index.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table_of.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table_partition_of.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_type/Create_type.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_type/Create_type_enum.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_type/Create_type_range.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Ignore_syntax.pegjs +0 -0
- package/lib/parse/postgresql/Expression.pegjs +0 -0
- package/lib/parse/postgresql/InitializerUtils.pegjs +0 -0
- package/lib/parse/postgresql/Keywords.pegjs +0 -0
- package/lib/parse/postgresql/get_parser.js +0 -0
- package/lib/parse/postgresql/parser.pegjs +0 -0
- package/lib/parse/schemarb/parser.pegjs +0 -0
- package/lib/parse/schemarbParser.js +0 -0
- package/lib/utils/version.js +0 -0
- package/package.json +3 -3
- package/types/export/ModelExporter.d.ts +0 -0
- package/types/export/index.d.ts +0 -0
- package/types/import/index.d.ts +1 -1
- package/types/index.d.ts +0 -0
- package/types/model_structure/database.d.ts +34 -1
- package/types/model_structure/dbState.d.ts +0 -0
- package/types/model_structure/element.d.ts +0 -0
- package/types/model_structure/endpoint.d.ts +0 -0
- package/types/model_structure/enum.d.ts +0 -0
- package/types/model_structure/enumValue.d.ts +0 -0
- package/types/model_structure/field.d.ts +0 -0
- package/types/model_structure/indexColumn.d.ts +0 -0
- package/types/model_structure/indexes.d.ts +0 -0
- package/types/model_structure/ref.d.ts +0 -0
- package/types/model_structure/schema.d.ts +0 -0
- package/types/model_structure/stickyNote.d.ts +0 -0
- package/types/model_structure/table.d.ts +0 -0
- package/types/model_structure/tableGroup.d.ts +0 -0
- package/types/parse/Parser.d.ts +3 -2
- package/types/parse/error.d.ts +0 -0
|
@@ -0,0 +1,1503 @@
|
|
|
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 _lodash = require("lodash");
|
|
9
|
+
var _TSqlParserVisitor2 = _interopRequireDefault(require("../../parsers/mssql/TSqlParserVisitor"));
|
|
10
|
+
var _constants = require("../constants");
|
|
11
|
+
var _helpers = require("../helpers");
|
|
12
|
+
var _AST = require("../AST");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
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); } }
|
|
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; }
|
|
17
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
18
|
+
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); }
|
|
19
|
+
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); }
|
|
20
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
21
|
+
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); }; }
|
|
22
|
+
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); }
|
|
23
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
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; } }
|
|
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); }
|
|
30
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
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."); }
|
|
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); }
|
|
33
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
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; } }
|
|
35
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /* eslint-disable class-methods-use-this */
|
|
36
|
+
var ADD_DESCRIPTION_FUNCTION_NAME = 'sp_addextendedproperty';
|
|
37
|
+
var CHECK_CONSTRAINT_CONDITION_TYPE = {
|
|
38
|
+
RAW: 'raw',
|
|
39
|
+
ENUM: 'enum'
|
|
40
|
+
};
|
|
41
|
+
var getSchemaAndTableName = function getSchemaAndTableName(names) {
|
|
42
|
+
var tableName = (0, _lodash.last)(names);
|
|
43
|
+
var schemaName = names.length > 1 ? (0, _lodash.nth)(names, -2) : undefined;
|
|
44
|
+
return {
|
|
45
|
+
schemaName: schemaName,
|
|
46
|
+
tableName: tableName
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
var getStringFromRawString = function getStringFromRawString(rawString) {
|
|
50
|
+
if (rawString.startsWith("N'")) {
|
|
51
|
+
return rawString;
|
|
52
|
+
}
|
|
53
|
+
return rawString.slice(1, rawString.length - 1);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {any[]} columnDefTableConstraints
|
|
58
|
+
* @returns {{
|
|
59
|
+
* fieldsData: any[],
|
|
60
|
+
* indexes: any[],
|
|
61
|
+
* tableRefs: any[],
|
|
62
|
+
* columnDefaults: any[],
|
|
63
|
+
* checkConstraints: any[],
|
|
64
|
+
* }}
|
|
65
|
+
*/
|
|
66
|
+
var splitColumnDefTableConstraints = function splitColumnDefTableConstraints(columnDefTableConstraints) {
|
|
67
|
+
var _columnDefTableConstr = columnDefTableConstraints.reduce(function (acc, columnDefTableConstraint) {
|
|
68
|
+
switch (columnDefTableConstraint.kind) {
|
|
69
|
+
case _constants.TABLE_CONSTRAINT_KIND.FIELD:
|
|
70
|
+
acc[0].push(columnDefTableConstraint.value);
|
|
71
|
+
break;
|
|
72
|
+
case _constants.TABLE_CONSTRAINT_KIND.INDEX:
|
|
73
|
+
case _constants.TABLE_CONSTRAINT_KIND.PK:
|
|
74
|
+
case _constants.TABLE_CONSTRAINT_KIND.UNIQUE:
|
|
75
|
+
acc[1].push(columnDefTableConstraint.value);
|
|
76
|
+
break;
|
|
77
|
+
case _constants.TABLE_CONSTRAINT_KIND.FK:
|
|
78
|
+
acc[2].push(columnDefTableConstraint.value);
|
|
79
|
+
break;
|
|
80
|
+
case _constants.TABLE_CONSTRAINT_KIND.DEFAULT:
|
|
81
|
+
acc[3].push(columnDefTableConstraint.value);
|
|
82
|
+
break;
|
|
83
|
+
case _constants.TABLE_CONSTRAINT_KIND.CHECK:
|
|
84
|
+
acc[4].push(columnDefTableConstraint.value);
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
return acc;
|
|
90
|
+
}, [[], [], [], [], []]),
|
|
91
|
+
_columnDefTableConstr2 = _slicedToArray(_columnDefTableConstr, 5),
|
|
92
|
+
fieldsData = _columnDefTableConstr2[0],
|
|
93
|
+
indexes = _columnDefTableConstr2[1],
|
|
94
|
+
tableRefs = _columnDefTableConstr2[2],
|
|
95
|
+
columnDefaults = _columnDefTableConstr2[3],
|
|
96
|
+
checkConstraints = _columnDefTableConstr2[4];
|
|
97
|
+
return {
|
|
98
|
+
fieldsData: fieldsData,
|
|
99
|
+
indexes: indexes,
|
|
100
|
+
tableRefs: tableRefs,
|
|
101
|
+
columnDefaults: columnDefaults,
|
|
102
|
+
checkConstraints: checkConstraints
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
var parseFieldsAndInlineRefsFromFieldsData = function parseFieldsAndInlineRefsFromFieldsData(fieldsData, tableName, schemaName) {
|
|
106
|
+
var _fieldsData$reduce = fieldsData.reduce(function (acc, fieldData) {
|
|
107
|
+
var _acc$;
|
|
108
|
+
var inlineRefs = fieldData.inline_refs.map(function (inlineRef) {
|
|
109
|
+
inlineRef.endpoints[0].tableName = tableName;
|
|
110
|
+
inlineRef.endpoints[0].schemaName = schemaName;
|
|
111
|
+
inlineRef.endpoints[0].fieldNames = [fieldData.field.name];
|
|
112
|
+
return inlineRef;
|
|
113
|
+
});
|
|
114
|
+
acc[0].push(inlineRefs);
|
|
115
|
+
acc[1].push(fieldData.field);
|
|
116
|
+
(_acc$ = acc[2]).push.apply(_acc$, _toConsumableArray(fieldData.checkConstraints));
|
|
117
|
+
return acc;
|
|
118
|
+
}, [[], [], []]),
|
|
119
|
+
_fieldsData$reduce2 = _slicedToArray(_fieldsData$reduce, 3),
|
|
120
|
+
resInlineRefs = _fieldsData$reduce2[0],
|
|
121
|
+
fields = _fieldsData$reduce2[1],
|
|
122
|
+
checkConstraints = _fieldsData$reduce2[2];
|
|
123
|
+
return {
|
|
124
|
+
inlineRefs: resInlineRefs,
|
|
125
|
+
fields: fields,
|
|
126
|
+
checkConstraints: checkConstraints
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
130
|
+
_inherits(MssqlASTGen, _TSqlParserVisitor);
|
|
131
|
+
var _super = _createSuper(MssqlASTGen);
|
|
132
|
+
function MssqlASTGen() {
|
|
133
|
+
var _this;
|
|
134
|
+
_classCallCheck(this, MssqlASTGen);
|
|
135
|
+
_this = _super.call(this);
|
|
136
|
+
_this.data = {
|
|
137
|
+
schemas: [],
|
|
138
|
+
tables: [],
|
|
139
|
+
refs: [],
|
|
140
|
+
enums: [],
|
|
141
|
+
tableGroups: [],
|
|
142
|
+
aliases: [],
|
|
143
|
+
project: {},
|
|
144
|
+
records: []
|
|
145
|
+
};
|
|
146
|
+
return _this;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// tsql_file
|
|
150
|
+
// : batch* EOF
|
|
151
|
+
// | execute_body_batch go_statement* EOF
|
|
152
|
+
// ;
|
|
153
|
+
_createClass(MssqlASTGen, [{
|
|
154
|
+
key: "visitTsql_file",
|
|
155
|
+
value: function visitTsql_file(ctx) {
|
|
156
|
+
var _this2 = this;
|
|
157
|
+
ctx.batch().forEach(function (batch) {
|
|
158
|
+
return batch.accept(_this2);
|
|
159
|
+
});
|
|
160
|
+
return this.data;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// batch
|
|
164
|
+
// : go_statement
|
|
165
|
+
// | execute_body_batch? (go_statement | sql_clauses+) go_statement*
|
|
166
|
+
// | batch_level_statement go_statement*
|
|
167
|
+
// ;
|
|
168
|
+
}, {
|
|
169
|
+
key: "visitBatch",
|
|
170
|
+
value: function visitBatch(ctx) {
|
|
171
|
+
var _this3 = this;
|
|
172
|
+
if (ctx.sql_clauses()) {
|
|
173
|
+
ctx.sql_clauses().forEach(function (sqlClause) {
|
|
174
|
+
return sqlClause.accept(_this3);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// sql_clauses
|
|
180
|
+
// : dml_clause SEMI?
|
|
181
|
+
// | cfl_statement SEMI?
|
|
182
|
+
// | another_statement SEMI?
|
|
183
|
+
// | ddl_clause SEMI?
|
|
184
|
+
// | dbcc_clause SEMI?
|
|
185
|
+
// | backup_statement SEMI?
|
|
186
|
+
// | SEMI
|
|
187
|
+
// ;
|
|
188
|
+
}, {
|
|
189
|
+
key: "visitSql_clauses",
|
|
190
|
+
value: function visitSql_clauses(ctx) {
|
|
191
|
+
if (ctx.ddl_clause()) {
|
|
192
|
+
ctx.ddl_clause().accept(this);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (ctx.dml_clause()) {
|
|
196
|
+
ctx.dml_clause().accept(this);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (ctx.another_statement()) {
|
|
200
|
+
ctx.another_statement().accept(this);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// dml_clause
|
|
205
|
+
// : merge_statement
|
|
206
|
+
// | delete_statement
|
|
207
|
+
// | insert_statement
|
|
208
|
+
// | select_statement_standalone
|
|
209
|
+
// | update_statement
|
|
210
|
+
// ;
|
|
211
|
+
}, {
|
|
212
|
+
key: "visitDml_clause",
|
|
213
|
+
value: function visitDml_clause(ctx) {
|
|
214
|
+
if (ctx.insert_statement()) {
|
|
215
|
+
ctx.insert_statement().accept(this);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// insert_statement
|
|
220
|
+
// : with_expression? INSERT (TOP '(' expression ')' PERCENT?)? INTO? (
|
|
221
|
+
// ddl_object
|
|
222
|
+
// | rowset_function_limited
|
|
223
|
+
// ) with_table_hints? ('(' insert_column_name_list ')')? output_clause? insert_statement_value for_clause? option_clause? ';'?
|
|
224
|
+
// ;
|
|
225
|
+
}, {
|
|
226
|
+
key: "visitInsert_statement",
|
|
227
|
+
value: function visitInsert_statement(ctx) {
|
|
228
|
+
// [ 'users' ]
|
|
229
|
+
// [ 'test', 'users' ]
|
|
230
|
+
// [ 'db', 'test', 'users' ]
|
|
231
|
+
// [ 'server', 'db', 'test', 'users' ]
|
|
232
|
+
// The last: table name
|
|
233
|
+
// The second-last: schema name
|
|
234
|
+
var names = ctx.ddl_object().accept(this);
|
|
235
|
+
var tableName = (0, _lodash.last)(names);
|
|
236
|
+
var schemaName = names.length > 1 ? (0, _lodash.nth)(names, -2) : undefined;
|
|
237
|
+
var columns = ctx.insert_column_name_list() ? ctx.insert_column_name_list().accept(this) : [];
|
|
238
|
+
var values = ctx.insert_statement_value().accept(this);
|
|
239
|
+
var record = new _AST.TableRecord({
|
|
240
|
+
tableName: tableName,
|
|
241
|
+
schemaName: schemaName,
|
|
242
|
+
columns: columns,
|
|
243
|
+
values: values
|
|
244
|
+
});
|
|
245
|
+
this.data.records.push(record);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ddl_object
|
|
249
|
+
// : full_table_name
|
|
250
|
+
// | LOCAL_ID
|
|
251
|
+
// ;
|
|
252
|
+
}, {
|
|
253
|
+
key: "visitDdl_object",
|
|
254
|
+
value: function visitDdl_object(ctx) {
|
|
255
|
+
return ctx.full_table_name().accept(this);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// full_table_name
|
|
259
|
+
// : (
|
|
260
|
+
// linkedServer = id_ '.' '.' schema = id_ '.'
|
|
261
|
+
// | server = id_ '.' database = id_ '.' schema = id_ '.'
|
|
262
|
+
// | database = id_ '.' schema = id_? '.'
|
|
263
|
+
// | schema = id_ '.'
|
|
264
|
+
// )? table = id_
|
|
265
|
+
// ;
|
|
266
|
+
}, {
|
|
267
|
+
key: "visitFull_table_name",
|
|
268
|
+
value: function visitFull_table_name(ctx) {
|
|
269
|
+
var _this4 = this;
|
|
270
|
+
return ctx.id_().map(function (id) {
|
|
271
|
+
return id.accept(_this4);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// id_
|
|
276
|
+
// : ID
|
|
277
|
+
// | TEMP_ID
|
|
278
|
+
// | DOUBLE_QUOTE_ID
|
|
279
|
+
// | DOUBLE_QUOTE_BLANK
|
|
280
|
+
// | SQUARE_BRACKET_ID
|
|
281
|
+
// | keyword
|
|
282
|
+
// | RAW
|
|
283
|
+
// ;
|
|
284
|
+
}, {
|
|
285
|
+
key: "visitId_",
|
|
286
|
+
value: function visitId_(ctx) {
|
|
287
|
+
if (ctx.DOUBLE_QUOTE_ID() || ctx.SQUARE_BRACKET_ID()) return (0, _helpers.getOriginalText)(ctx).slice(1, -1);
|
|
288
|
+
return (0, _helpers.getOriginalText)(ctx);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// insert_column_name_list
|
|
292
|
+
// : col += insert_column_id (',' col += insert_column_id)*
|
|
293
|
+
// ;
|
|
294
|
+
}, {
|
|
295
|
+
key: "visitInsert_column_name_list",
|
|
296
|
+
value: function visitInsert_column_name_list(ctx) {
|
|
297
|
+
var _this5 = this;
|
|
298
|
+
var columns = ctx.insert_column_id().map(function (column) {
|
|
299
|
+
return column.accept(_this5);
|
|
300
|
+
});
|
|
301
|
+
return (0, _lodash.flattenDepth)(columns, 1);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// insert_column_id
|
|
305
|
+
// : (ignore += id_? '.')* id_
|
|
306
|
+
// ;
|
|
307
|
+
|
|
308
|
+
// insert_statement_value
|
|
309
|
+
// : table_value_constructor
|
|
310
|
+
// | derived_table
|
|
311
|
+
// | execute_statement
|
|
312
|
+
// | DEFAULT VALUES
|
|
313
|
+
// ;
|
|
314
|
+
}, {
|
|
315
|
+
key: "visitInsert_statement_value",
|
|
316
|
+
value: function visitInsert_statement_value(ctx) {
|
|
317
|
+
if (!ctx.table_value_constructor()) return [];
|
|
318
|
+
var rawValues = ctx.table_value_constructor().accept(this);
|
|
319
|
+
return rawValues;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// table_value_constructor
|
|
323
|
+
// : VALUES '(' exps += expression_list_ ')' (',' '(' exps += expression_list_ ')')*
|
|
324
|
+
// ;
|
|
325
|
+
}, {
|
|
326
|
+
key: "visitTable_value_constructor",
|
|
327
|
+
value: function visitTable_value_constructor(ctx) {
|
|
328
|
+
var _this6 = this;
|
|
329
|
+
return ctx.expression_list_().map(function (expression) {
|
|
330
|
+
return expression.accept(_this6);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// expression_list_
|
|
335
|
+
// : exp += expression (',' exp += expression)*
|
|
336
|
+
// ;
|
|
337
|
+
}, {
|
|
338
|
+
key: "visitExpression_list_",
|
|
339
|
+
value: function visitExpression_list_(ctx) {
|
|
340
|
+
var _this7 = this;
|
|
341
|
+
return ctx.expression().map(function (expression) {
|
|
342
|
+
return expression.accept(_this7);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// expression
|
|
347
|
+
// : primitive_expression
|
|
348
|
+
// | function_call
|
|
349
|
+
// | expression '.' (value_call | query_call | exist_call | modify_call)
|
|
350
|
+
// | expression '.' hierarchyid_call
|
|
351
|
+
// | expression COLLATE id_
|
|
352
|
+
// | case_expression
|
|
353
|
+
// | full_column_name
|
|
354
|
+
// | bracket_expression
|
|
355
|
+
// | unary_operator_expression
|
|
356
|
+
// | expression op = ('*' | '/' | '%') expression
|
|
357
|
+
// | expression op = ('+' | '-' | '&' | '^' | '|' | '||') expression
|
|
358
|
+
// | expression time_zone
|
|
359
|
+
// | over_clause
|
|
360
|
+
// | DOLLAR_ACTION
|
|
361
|
+
// ;
|
|
362
|
+
}, {
|
|
363
|
+
key: "visitExpression",
|
|
364
|
+
value: function visitExpression(ctx) {
|
|
365
|
+
if (ctx.primitive_expression()) {
|
|
366
|
+
return ctx.primitive_expression().accept(this);
|
|
367
|
+
}
|
|
368
|
+
if (ctx.function_call()) {
|
|
369
|
+
return ctx.function_call().accept(this);
|
|
370
|
+
}
|
|
371
|
+
if (ctx.unary_operator_expression()) {
|
|
372
|
+
return ctx.unary_operator_expression().accept(this);
|
|
373
|
+
}
|
|
374
|
+
if (ctx.bracket_expression()) {
|
|
375
|
+
return ctx.bracket_expression().accept(this);
|
|
376
|
+
}
|
|
377
|
+
if (ctx.full_column_name()) {
|
|
378
|
+
return ctx.full_column_name().accept(this);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Default case for any other expression type
|
|
382
|
+
return {
|
|
383
|
+
value: (0, _helpers.getOriginalText)(ctx),
|
|
384
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// bracket_expression
|
|
389
|
+
// : '(' expression ')'
|
|
390
|
+
// | '(' subquery ')'
|
|
391
|
+
// ;
|
|
392
|
+
}, {
|
|
393
|
+
key: "visitBracket_expression",
|
|
394
|
+
value: function visitBracket_expression(ctx) {
|
|
395
|
+
return ctx.expression() ? ctx.expression().accept(this) : null;
|
|
396
|
+
}
|
|
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
|
+
|
|
415
|
+
// primitive_constant
|
|
416
|
+
// : STRING // string, datetime or uniqueidentifier
|
|
417
|
+
// | BINARY
|
|
418
|
+
// | (DECIMAL | REAL | FLOAT) // float or decimal
|
|
419
|
+
// | dollar = '$' ('-' | '+')? (DECIMAL | FLOAT) // money
|
|
420
|
+
// | parameter
|
|
421
|
+
// ;
|
|
422
|
+
}, {
|
|
423
|
+
key: "visitPrimitive_constant",
|
|
424
|
+
value: function visitPrimitive_constant(ctx) {
|
|
425
|
+
if (ctx.STRING() || ctx.BINARY()) {
|
|
426
|
+
var value = getStringFromRawString(ctx.getText());
|
|
427
|
+
return {
|
|
428
|
+
value: value,
|
|
429
|
+
type: value.startsWith("N'") ? _constants.DATA_TYPE.EXPRESSION : _constants.DATA_TYPE.STRING
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
if (ctx.DOLLAR()) {
|
|
433
|
+
var dollar = (0, _lodash.first)(ctx.children).getText();
|
|
434
|
+
var sign = ctx.children.length > 2 ? (0, _lodash.nth)(ctx.children, -2) : '';
|
|
435
|
+
var _value = (0, _lodash.last)(ctx.children).getText();
|
|
436
|
+
return {
|
|
437
|
+
value: "".concat(dollar).concat(sign).concat(_value),
|
|
438
|
+
type: _constants.DATA_TYPE.STRING
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
if (ctx.REAL() || ctx.DECIMAL() || ctx.FLOAT()) {
|
|
442
|
+
return {
|
|
443
|
+
value: ctx.getText(),
|
|
444
|
+
type: _constants.DATA_TYPE.NUMBER
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
return {
|
|
448
|
+
value: (0, _helpers.getOriginalText)(ctx),
|
|
449
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// function_call
|
|
454
|
+
// : ranking_windowed_function # RANKING_WINDOWED_FUNC
|
|
455
|
+
// | aggregate_windowed_function # AGGREGATE_WINDOWED_FUNC
|
|
456
|
+
// | analytic_windowed_function # ANALYTIC_WINDOWED_FUNC
|
|
457
|
+
// | built_in_functions # BUILT_IN_FUNC
|
|
458
|
+
// | scalar_function_name '(' expression_list_? ')' # SCALAR_FUNCTION
|
|
459
|
+
// | freetext_function # FREE_TEXT
|
|
460
|
+
// | partition_function # PARTITION_FUNC
|
|
461
|
+
// | hierarchyid_static_method # HIERARCHYID_METHOD
|
|
462
|
+
// ;
|
|
463
|
+
|
|
464
|
+
// See packages/dbml-core/src/parse/ANTLR/parsers/mssql/TSqlParser.g4 at line 4338
|
|
465
|
+
}, {
|
|
466
|
+
key: "visitBUILT_IN_FUNC",
|
|
467
|
+
value: function visitBUILT_IN_FUNC(ctx) {
|
|
468
|
+
return {
|
|
469
|
+
value: (0, _helpers.getOriginalText)(ctx),
|
|
470
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
}, {
|
|
474
|
+
key: "visitSCALAR_FUNCTION",
|
|
475
|
+
value: function visitSCALAR_FUNCTION(ctx) {
|
|
476
|
+
return {
|
|
477
|
+
value: (0, _helpers.getOriginalText)(ctx),
|
|
478
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// unary_operator_expression
|
|
483
|
+
// : '~' expression
|
|
484
|
+
// | op = ('+' | '-') expression
|
|
485
|
+
// ;
|
|
486
|
+
}, {
|
|
487
|
+
key: "visitUnary_operator_expression",
|
|
488
|
+
value: function visitUnary_operator_expression(ctx) {
|
|
489
|
+
var operator = ctx.children[0].getText();
|
|
490
|
+
var expression = ctx.expression().accept(this);
|
|
491
|
+
return {
|
|
492
|
+
value: "".concat(operator).concat(expression.value),
|
|
493
|
+
type: expression.type
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// data_type
|
|
498
|
+
// : scaled = (VARCHAR | NVARCHAR | BINARY_KEYWORD | VARBINARY_KEYWORD | SQUARE_BRACKET_ID) '(' MAX ')'
|
|
499
|
+
// | ext_type = id_ '(' scale = DECIMAL ',' prec = DECIMAL ')'
|
|
500
|
+
// | ext_type = id_ '(' scale = DECIMAL ')'
|
|
501
|
+
// | ext_type = id_ IDENTITY ('(' seed = DECIMAL ',' inc = DECIMAL ')')?
|
|
502
|
+
// | double_prec = DOUBLE PRECISION?
|
|
503
|
+
// | unscaled_type = id_
|
|
504
|
+
// ;
|
|
505
|
+
}, {
|
|
506
|
+
key: "visitData_type",
|
|
507
|
+
value: function visitData_type(ctx) {
|
|
508
|
+
var id = ctx.id_().accept(this);
|
|
509
|
+
if (ctx.MAX()) {
|
|
510
|
+
return "".concat(id, "(MAX)");
|
|
511
|
+
}
|
|
512
|
+
if (ctx.IDENTITY()) {
|
|
513
|
+
if (ctx.DECIMAL().length) {
|
|
514
|
+
var seedAndInc = ctx.DECIMAL().map(function (decimal) {
|
|
515
|
+
return decimal.getText();
|
|
516
|
+
});
|
|
517
|
+
return "".concat(id, " IDENTITY(").concat(seedAndInc, ")");
|
|
518
|
+
}
|
|
519
|
+
return "".concat(id, " IDENTITY");
|
|
520
|
+
}
|
|
521
|
+
if (ctx.DOUBLE()) {
|
|
522
|
+
if (ctx.PRECISION()) {
|
|
523
|
+
return "".concat(id, "(").concat(ctx.PRECISION().getText(), ")");
|
|
524
|
+
}
|
|
525
|
+
return id;
|
|
526
|
+
}
|
|
527
|
+
if (ctx.DECIMAL().length) {
|
|
528
|
+
var scaleAndPrec = ctx.DECIMAL().map(function (decimal) {
|
|
529
|
+
return decimal.getText();
|
|
530
|
+
});
|
|
531
|
+
return "".concat(id, "(").concat(scaleAndPrec.join(','), ")");
|
|
532
|
+
}
|
|
533
|
+
return id;
|
|
534
|
+
}
|
|
535
|
+
}, {
|
|
536
|
+
key: "visitPrimitive_expression",
|
|
537
|
+
value: function visitPrimitive_expression(ctx) {
|
|
538
|
+
if (ctx.NULL_()) {
|
|
539
|
+
return {
|
|
540
|
+
value: ctx.getText(),
|
|
541
|
+
type: _constants.DATA_TYPE.BOOLEAN
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
if (ctx.primitive_constant()) {
|
|
545
|
+
return ctx.primitive_constant().accept(this);
|
|
546
|
+
}
|
|
547
|
+
return {
|
|
548
|
+
value: ctx.getText(),
|
|
549
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// ddl_clause
|
|
554
|
+
// | alter_table
|
|
555
|
+
// | create_index
|
|
556
|
+
// | create_table
|
|
557
|
+
// ;
|
|
558
|
+
// more details at: packages/dbml-core/src/parse/ANTLR/parsers/mssql/TSqlParser.g4 line 73
|
|
559
|
+
}, {
|
|
560
|
+
key: "visitDdl_clause",
|
|
561
|
+
value: function visitDdl_clause(ctx) {
|
|
562
|
+
if (ctx.create_table()) {
|
|
563
|
+
ctx.create_table().accept(this);
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
if (ctx.alter_table()) {
|
|
567
|
+
ctx.alter_table().accept(this);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
if (ctx.create_index()) {
|
|
571
|
+
ctx.create_index().accept(this);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// create_table
|
|
576
|
+
// : CREATE TABLE table_name '(' column_def_table_constraints (','? table_indices)* ','? ')' (
|
|
577
|
+
// LOCK simple_id
|
|
578
|
+
// )? table_options* (ON id_ | DEFAULT | on_partition_or_filegroup)? (TEXTIMAGE_ON id_ | DEFAULT)? ';'?
|
|
579
|
+
// ;
|
|
580
|
+
}, {
|
|
581
|
+
key: "visitCreate_table",
|
|
582
|
+
value: function visitCreate_table(ctx) {
|
|
583
|
+
var _this8 = this,
|
|
584
|
+
_this$data$refs,
|
|
585
|
+
_this$data$refs2;
|
|
586
|
+
var _getSchemaAndTableNam = getSchemaAndTableName(ctx.table_name().accept(this)),
|
|
587
|
+
schemaName = _getSchemaAndTableNam.schemaName,
|
|
588
|
+
tableName = _getSchemaAndTableNam.tableName;
|
|
589
|
+
var columnDefTableConstraints = ctx.column_def_table_constraints().accept(this);
|
|
590
|
+
var tableIndices = ctx.table_indices().map(function (tableIndex) {
|
|
591
|
+
return tableIndex.accept(_this8);
|
|
592
|
+
});
|
|
593
|
+
var _splitColumnDefTableC = splitColumnDefTableConstraints(columnDefTableConstraints),
|
|
594
|
+
fieldsData = _splitColumnDefTableC.fieldsData,
|
|
595
|
+
indexes = _splitColumnDefTableC.indexes,
|
|
596
|
+
tableRefs = _splitColumnDefTableC.tableRefs,
|
|
597
|
+
tableCheckConstraints = _splitColumnDefTableC.checkConstraints;
|
|
598
|
+
var _parseFieldsAndInline = parseFieldsAndInlineRefsFromFieldsData(fieldsData, tableName, schemaName),
|
|
599
|
+
inlineRefs = _parseFieldsAndInline.inlineRefs,
|
|
600
|
+
fields = _parseFieldsAndInline.fields,
|
|
601
|
+
columnCheckConstraints = _parseFieldsAndInline.checkConstraints;
|
|
602
|
+
(_this$data$refs = this.data.refs).push.apply(_this$data$refs, _toConsumableArray((0, _lodash.flatten)(inlineRefs)));
|
|
603
|
+
(_this$data$refs2 = this.data.refs).push.apply(_this$data$refs2, _toConsumableArray(tableRefs.map(function (tableRef) {
|
|
604
|
+
tableRef.endpoints[0].tableName = tableName;
|
|
605
|
+
tableRef.endpoints[0].schemaName = schemaName;
|
|
606
|
+
return tableRef;
|
|
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
|
+
});
|
|
631
|
+
var table = new _AST.Table({
|
|
632
|
+
name: tableName,
|
|
633
|
+
schemaName: schemaName,
|
|
634
|
+
fields: fields,
|
|
635
|
+
indexes: tableIndices.concat(indexes)
|
|
636
|
+
});
|
|
637
|
+
this.data.tables.push(table);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// table_name
|
|
641
|
+
// : (database = id_ '.' schema = id_? '.' | schema = id_ '.')? (
|
|
642
|
+
// table = id_
|
|
643
|
+
// | blocking_hierarchy = BLOCKING_HIERARCHY
|
|
644
|
+
// )
|
|
645
|
+
// ;
|
|
646
|
+
}, {
|
|
647
|
+
key: "visitTable_name",
|
|
648
|
+
value: function visitTable_name(ctx) {
|
|
649
|
+
var _this9 = this;
|
|
650
|
+
return ctx.id_().map(function (id) {
|
|
651
|
+
return id.accept(_this9);
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// column_def_table_constraints
|
|
656
|
+
// : column_def_table_constraint (','? column_def_table_constraint)*
|
|
657
|
+
// ;
|
|
658
|
+
}, {
|
|
659
|
+
key: "visitColumn_def_table_constraints",
|
|
660
|
+
value: function visitColumn_def_table_constraints(ctx) {
|
|
661
|
+
var _this10 = this;
|
|
662
|
+
return ctx.column_def_table_constraint().map(function (columnDef) {
|
|
663
|
+
return columnDef.accept(_this10);
|
|
664
|
+
}).filter(function (columnDef) {
|
|
665
|
+
return columnDef;
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// column_def_table_constraint
|
|
670
|
+
// : column_definition
|
|
671
|
+
// | materialized_column_definition
|
|
672
|
+
// | table_constraint
|
|
673
|
+
// ;
|
|
674
|
+
}, {
|
|
675
|
+
key: "visitColumn_def_table_constraint",
|
|
676
|
+
value: function visitColumn_def_table_constraint(ctx) {
|
|
677
|
+
if (ctx.column_definition()) {
|
|
678
|
+
return ctx.column_definition().accept(this);
|
|
679
|
+
}
|
|
680
|
+
if (ctx.table_constraint()) {
|
|
681
|
+
return ctx.table_constraint().accept(this);
|
|
682
|
+
}
|
|
683
|
+
return null;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// column_definition
|
|
687
|
+
// : id_ (data_type | AS expression PERSISTED?) column_definition_element* column_index?
|
|
688
|
+
// ;
|
|
689
|
+
}, {
|
|
690
|
+
key: "visitColumn_definition",
|
|
691
|
+
value: function visitColumn_definition(ctx) {
|
|
692
|
+
var _this11 = this;
|
|
693
|
+
var columnName = ctx.id_().accept(this);
|
|
694
|
+
var type = '';
|
|
695
|
+
if (ctx.data_type()) {
|
|
696
|
+
type = ctx.data_type().accept(this);
|
|
697
|
+
} else if (ctx.expression()) {
|
|
698
|
+
// { value: "(first_name + ' ' + last_name)", type: 'expression' }
|
|
699
|
+
var expression = ctx.expression().accept(this);
|
|
700
|
+
var as = ctx.AS().getText();
|
|
701
|
+
var persisted = ctx.PERSISTED() ? " ".concat(ctx.PERSISTED().getText()) : '';
|
|
702
|
+
type = "".concat(as, " ").concat(expression.value).concat(persisted);
|
|
703
|
+
}
|
|
704
|
+
var field = new _AST.Field({
|
|
705
|
+
name: columnName,
|
|
706
|
+
type: {
|
|
707
|
+
type_name: type,
|
|
708
|
+
schemaName: null
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
var definition = {
|
|
712
|
+
kind: _constants.TABLE_CONSTRAINT_KIND.FIELD,
|
|
713
|
+
value: {
|
|
714
|
+
field: field,
|
|
715
|
+
inline_refs: [],
|
|
716
|
+
checkConstraints: []
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
var columnDefinitions = ctx.column_definition_element().map(function (columnDef) {
|
|
720
|
+
return columnDef.accept(_this11);
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
// e.g.
|
|
724
|
+
// [
|
|
725
|
+
// { kind: 'not_null', value: true },
|
|
726
|
+
// { kind: 'dbdefault', value: { value: 'GETDATE()', type: 'expression' } }
|
|
727
|
+
// ]
|
|
728
|
+
columnDefinitions.filter(function (columnDef) {
|
|
729
|
+
return columnDef;
|
|
730
|
+
}).forEach(function (columnDef) {
|
|
731
|
+
switch (columnDef.kind) {
|
|
732
|
+
case _constants.COLUMN_CONSTRAINT_KIND.DEFAULT:
|
|
733
|
+
field.dbdefault = columnDef.value;
|
|
734
|
+
break;
|
|
735
|
+
case _constants.COLUMN_CONSTRAINT_KIND.INCREMENT:
|
|
736
|
+
field.increment = columnDef.value;
|
|
737
|
+
break;
|
|
738
|
+
case _constants.COLUMN_CONSTRAINT_KIND.NOT_NULL:
|
|
739
|
+
field.not_null = columnDef.value;
|
|
740
|
+
break;
|
|
741
|
+
case _constants.COLUMN_CONSTRAINT_KIND.PK:
|
|
742
|
+
field.pk = columnDef.value;
|
|
743
|
+
break;
|
|
744
|
+
case _constants.COLUMN_CONSTRAINT_KIND.UNIQUE:
|
|
745
|
+
field.unique = columnDef.value;
|
|
746
|
+
break;
|
|
747
|
+
case _constants.COLUMN_CONSTRAINT_KIND.INLINE_REF:
|
|
748
|
+
definition.value.inline_refs.push(columnDef.value);
|
|
749
|
+
break;
|
|
750
|
+
case _constants.COLUMN_CONSTRAINT_KIND.CHECK:
|
|
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
|
+
}
|
|
761
|
+
default:
|
|
762
|
+
break;
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
// skip column index since it is just the name of the index that a column belongs to
|
|
767
|
+
|
|
768
|
+
return definition;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// column_definition_element
|
|
772
|
+
// : FILESTREAM
|
|
773
|
+
// | COLLATE collation_name = id_
|
|
774
|
+
// | SPARSE
|
|
775
|
+
// | MASKED WITH '(' FUNCTION '=' mask_function = STRING ')'
|
|
776
|
+
// | (CONSTRAINT constraint = id_)? DEFAULT constant_expr = expression
|
|
777
|
+
// | IDENTITY ('(' seed = DECIMAL ',' increment = DECIMAL ')')?
|
|
778
|
+
// | NOT FOR REPLICATION
|
|
779
|
+
// | GENERATED ALWAYS AS (ROW | TRANSACTION_ID | SEQUENCE_NUMBER) (START | END) HIDDEN_KEYWORD?
|
|
780
|
+
// // NULL / NOT NULL is a constraint
|
|
781
|
+
// | ROWGUIDCOL
|
|
782
|
+
// | ENCRYPTED WITH '(' COLUMN_ENCRYPTION_KEY '=' key_name = STRING ',' ENCRYPTION_TYPE '=' (
|
|
783
|
+
// DETERMINISTIC
|
|
784
|
+
// | RANDOMIZED
|
|
785
|
+
// ) ',' ALGORITHM '=' algo = STRING ')'
|
|
786
|
+
// | column_constraint
|
|
787
|
+
// ;
|
|
788
|
+
}, {
|
|
789
|
+
key: "visitColumn_definition_element",
|
|
790
|
+
value: function visitColumn_definition_element(ctx) {
|
|
791
|
+
if (ctx.DEFAULT()) {
|
|
792
|
+
return {
|
|
793
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.DEFAULT,
|
|
794
|
+
value: ctx.expression().accept(this)
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
if (ctx.IDENTITY()) {
|
|
798
|
+
return {
|
|
799
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.INCREMENT,
|
|
800
|
+
value: true
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
if (ctx.column_constraint()) {
|
|
804
|
+
return ctx.column_constraint().accept(this);
|
|
805
|
+
}
|
|
806
|
+
return null;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// column_constraint
|
|
810
|
+
// : (CONSTRAINT constraint = id_)? (
|
|
811
|
+
// null_notnull
|
|
812
|
+
// | ( (PRIMARY KEY | UNIQUE) clustered? primary_key_options)
|
|
813
|
+
// | ( (FOREIGN KEY)? foreign_key_options)
|
|
814
|
+
// | check_constraint
|
|
815
|
+
// )
|
|
816
|
+
// ;
|
|
817
|
+
}, {
|
|
818
|
+
key: "visitColumn_constraint",
|
|
819
|
+
value: function visitColumn_constraint(ctx) {
|
|
820
|
+
if (ctx.null_notnull()) {
|
|
821
|
+
var notNull = false;
|
|
822
|
+
var nullNotnull = ctx.null_notnull().accept(this);
|
|
823
|
+
if (nullNotnull.includes('NOT')) notNull = true;
|
|
824
|
+
return {
|
|
825
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.NOT_NULL,
|
|
826
|
+
value: notNull
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
if (ctx.UNIQUE()) {
|
|
830
|
+
return {
|
|
831
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.UNIQUE,
|
|
832
|
+
value: true
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
if (ctx.PRIMARY()) {
|
|
836
|
+
return {
|
|
837
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.PK,
|
|
838
|
+
value: true
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
if (ctx.foreign_key_options()) {
|
|
842
|
+
var _ctx$foreign_key_opti = ctx.foreign_key_options().accept(this),
|
|
843
|
+
refTableName = _ctx$foreign_key_opti.refTableName,
|
|
844
|
+
refSchemaName = _ctx$foreign_key_opti.refSchemaName,
|
|
845
|
+
fieldNames = _ctx$foreign_key_opti.fieldNames,
|
|
846
|
+
onDelete = _ctx$foreign_key_opti.onDelete,
|
|
847
|
+
onUpdate = _ctx$foreign_key_opti.onUpdate;
|
|
848
|
+
return {
|
|
849
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.INLINE_REF,
|
|
850
|
+
value: {
|
|
851
|
+
endpoints: [{
|
|
852
|
+
tableName: null,
|
|
853
|
+
schemaName: null,
|
|
854
|
+
fieldNames: null,
|
|
855
|
+
relation: '*'
|
|
856
|
+
}, {
|
|
857
|
+
tableName: refTableName,
|
|
858
|
+
schemaName: refSchemaName,
|
|
859
|
+
fieldNames: fieldNames,
|
|
860
|
+
relation: '1'
|
|
861
|
+
}],
|
|
862
|
+
onDelete: onDelete,
|
|
863
|
+
onUpdate: onUpdate
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// we do not handle check constraint since it is complicated and hard to extract enum from it
|
|
869
|
+
if (ctx.check_constraint()) {
|
|
870
|
+
return {
|
|
871
|
+
kind: _constants.COLUMN_CONSTRAINT_KIND.CHECK,
|
|
872
|
+
value: ctx.check_constraint().accept(this)
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// check_constraint
|
|
879
|
+
// : CHECK (NOT FOR REPLICATION)? '(' search_condition ')'
|
|
880
|
+
// ;
|
|
881
|
+
}, {
|
|
882
|
+
key: "visitCheck_constraint",
|
|
883
|
+
value: function visitCheck_constraint(ctx) {
|
|
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;
|
|
954
|
+
}
|
|
955
|
+
}, {
|
|
956
|
+
key: "visitNull_notnull",
|
|
957
|
+
value: function visitNull_notnull(ctx) {
|
|
958
|
+
return (0, _helpers.getOriginalText)(ctx);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// foreign_key_options
|
|
962
|
+
// : REFERENCES table_name '(' pk = column_name_list ')' (on_delete | on_update)* (
|
|
963
|
+
// NOT FOR REPLICATION
|
|
964
|
+
// )?
|
|
965
|
+
// ;
|
|
966
|
+
}, {
|
|
967
|
+
key: "visitForeign_key_options",
|
|
968
|
+
value: function visitForeign_key_options(ctx) {
|
|
969
|
+
var _this13 = this;
|
|
970
|
+
var names = ctx.table_name().accept(this);
|
|
971
|
+
var _getSchemaAndTableNam2 = getSchemaAndTableName(names),
|
|
972
|
+
refSchemaName = _getSchemaAndTableNam2.schemaName,
|
|
973
|
+
refTableName = _getSchemaAndTableNam2.tableName;
|
|
974
|
+
var fieldNames = ctx.column_name_list().accept(this);
|
|
975
|
+
var onDelete = ctx.on_delete() ? ctx.on_delete().map(function (action) {
|
|
976
|
+
return action.accept(_this13);
|
|
977
|
+
})[0] : null;
|
|
978
|
+
var onUpdate = ctx.on_update() ? ctx.on_update().map(function (action) {
|
|
979
|
+
return action.accept(_this13);
|
|
980
|
+
})[0] : null;
|
|
981
|
+
return {
|
|
982
|
+
refTableName: refTableName,
|
|
983
|
+
refSchemaName: refSchemaName,
|
|
984
|
+
onDelete: onDelete,
|
|
985
|
+
onUpdate: onUpdate,
|
|
986
|
+
fieldNames: fieldNames
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// column_name_list
|
|
991
|
+
// : col += id_ (',' col += id_)*
|
|
992
|
+
// ;
|
|
993
|
+
}, {
|
|
994
|
+
key: "visitColumn_name_list",
|
|
995
|
+
value: function visitColumn_name_list(ctx) {
|
|
996
|
+
var _this14 = this;
|
|
997
|
+
return ctx.id_().map(function (id) {
|
|
998
|
+
return id.accept(_this14);
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
// on_delete
|
|
1003
|
+
// : ON DELETE (NO ACTION | CASCADE | SET NULL_ | SET DEFAULT)
|
|
1004
|
+
// ;
|
|
1005
|
+
}, {
|
|
1006
|
+
key: "visitOn_delete",
|
|
1007
|
+
value: function visitOn_delete(ctx) {
|
|
1008
|
+
if (ctx.NO()) {
|
|
1009
|
+
return 'NO ACTION';
|
|
1010
|
+
}
|
|
1011
|
+
if (ctx.CASCADE()) {
|
|
1012
|
+
return 'CASCADE';
|
|
1013
|
+
}
|
|
1014
|
+
if (ctx.NULL_()) {
|
|
1015
|
+
return 'SET NULL';
|
|
1016
|
+
}
|
|
1017
|
+
return 'SET DEFAULT';
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
// on_update
|
|
1021
|
+
// : ON UPDATE (NO ACTION | CASCADE | SET NULL_ | SET DEFAULT)
|
|
1022
|
+
// ;
|
|
1023
|
+
}, {
|
|
1024
|
+
key: "visitOn_update",
|
|
1025
|
+
value: function visitOn_update(ctx) {
|
|
1026
|
+
if (ctx.NO()) {
|
|
1027
|
+
return 'NO ACTION';
|
|
1028
|
+
}
|
|
1029
|
+
if (ctx.CASCADE()) {
|
|
1030
|
+
return 'CASCADE';
|
|
1031
|
+
}
|
|
1032
|
+
if (ctx.NULL_()) {
|
|
1033
|
+
return 'SET NULL';
|
|
1034
|
+
}
|
|
1035
|
+
return 'SET DEFAULT';
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// table_constraint
|
|
1039
|
+
// : (CONSTRAINT constraint = id_)? (
|
|
1040
|
+
// ((PRIMARY KEY | UNIQUE) clustered? '(' column_name_list_with_order ')' primary_key_options)
|
|
1041
|
+
// | ( FOREIGN KEY '(' fk = column_name_list ')' foreign_key_options)
|
|
1042
|
+
// | ( CONNECTION '(' connection_node ( ',' connection_node)* ')')
|
|
1043
|
+
// | ( DEFAULT constant_expr = expression FOR column = id_ (WITH VALUES)?)
|
|
1044
|
+
// | check_constraint
|
|
1045
|
+
// )
|
|
1046
|
+
// ;
|
|
1047
|
+
}, {
|
|
1048
|
+
key: "visitTable_constraint",
|
|
1049
|
+
value: function visitTable_constraint(ctx) {
|
|
1050
|
+
var _this15 = this;
|
|
1051
|
+
var name = ctx.id_() ? ctx.id_().map(function (id) {
|
|
1052
|
+
return id.accept(_this15);
|
|
1053
|
+
})[0] : '';
|
|
1054
|
+
if (ctx.PRIMARY() || ctx.UNIQUE()) {
|
|
1055
|
+
var columns = ctx.column_name_list_with_order().accept(this);
|
|
1056
|
+
var index = new _AST.Index({
|
|
1057
|
+
name: name,
|
|
1058
|
+
columns: columns
|
|
1059
|
+
});
|
|
1060
|
+
if (ctx.PRIMARY()) {
|
|
1061
|
+
index.pk = true;
|
|
1062
|
+
}
|
|
1063
|
+
if (ctx.UNIQUE()) {
|
|
1064
|
+
index.unique = true;
|
|
1065
|
+
}
|
|
1066
|
+
return {
|
|
1067
|
+
kind: ctx.PRIMARY() ? _constants.TABLE_CONSTRAINT_KIND.PK : _constants.TABLE_CONSTRAINT_KIND.UNIQUE,
|
|
1068
|
+
value: index
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
if (ctx.FOREIGN()) {
|
|
1072
|
+
var _columns = ctx.column_name_list().accept(this);
|
|
1073
|
+
var _ctx$foreign_key_opti2 = ctx.foreign_key_options().accept(this),
|
|
1074
|
+
refTableName = _ctx$foreign_key_opti2.refTableName,
|
|
1075
|
+
refSchemaName = _ctx$foreign_key_opti2.refSchemaName,
|
|
1076
|
+
fieldNames = _ctx$foreign_key_opti2.fieldNames,
|
|
1077
|
+
onDelete = _ctx$foreign_key_opti2.onDelete,
|
|
1078
|
+
onUpdate = _ctx$foreign_key_opti2.onUpdate;
|
|
1079
|
+
return {
|
|
1080
|
+
kind: _constants.TABLE_CONSTRAINT_KIND.FK,
|
|
1081
|
+
value: {
|
|
1082
|
+
name: name,
|
|
1083
|
+
endpoints: [{
|
|
1084
|
+
tableName: null,
|
|
1085
|
+
schemaName: null,
|
|
1086
|
+
fieldNames: _columns,
|
|
1087
|
+
relation: '*'
|
|
1088
|
+
}, {
|
|
1089
|
+
tableName: refTableName,
|
|
1090
|
+
schemaName: refSchemaName,
|
|
1091
|
+
fieldNames: fieldNames,
|
|
1092
|
+
relation: '1'
|
|
1093
|
+
}],
|
|
1094
|
+
onDelete: onDelete,
|
|
1095
|
+
onUpdate: onUpdate
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
if (ctx.DEFAULT()) {
|
|
1100
|
+
var column = ctx.column.accept(this);
|
|
1101
|
+
var expression = ctx.expression().accept(this);
|
|
1102
|
+
return {
|
|
1103
|
+
kind: _constants.TABLE_CONSTRAINT_KIND.DEFAULT,
|
|
1104
|
+
value: {
|
|
1105
|
+
column: column,
|
|
1106
|
+
defaultValue: expression
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
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
|
+
}
|
|
1118
|
+
return null;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// column_name_list_with_order
|
|
1122
|
+
// : id_ (ASC | DESC)? (',' id_ (ASC | DESC)?)*
|
|
1123
|
+
// ;
|
|
1124
|
+
}, {
|
|
1125
|
+
key: "visitColumn_name_list_with_order",
|
|
1126
|
+
value: function visitColumn_name_list_with_order(ctx) {
|
|
1127
|
+
var _this16 = this;
|
|
1128
|
+
return ctx.id_().map(function (id) {
|
|
1129
|
+
return {
|
|
1130
|
+
value: id.accept(_this16),
|
|
1131
|
+
type: 'column'
|
|
1132
|
+
};
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
// table_indices
|
|
1137
|
+
// : INDEX id_ UNIQUE? clustered? '(' column_name_list_with_order ')'
|
|
1138
|
+
// | INDEX id_ CLUSTERED COLUMNSTORE
|
|
1139
|
+
// | INDEX id_ NONCLUSTERED? COLUMNSTORE '(' column_name_list ')' create_table_index_options? (
|
|
1140
|
+
// ON id_
|
|
1141
|
+
// )?
|
|
1142
|
+
// ;
|
|
1143
|
+
}, {
|
|
1144
|
+
key: "visitTable_indices",
|
|
1145
|
+
value: function visitTable_indices(ctx) {
|
|
1146
|
+
var _this17 = this;
|
|
1147
|
+
var index = new _AST.Index({
|
|
1148
|
+
name: ctx.id_().map(function (id) {
|
|
1149
|
+
return id.accept(_this17);
|
|
1150
|
+
})[0],
|
|
1151
|
+
unique: !!ctx.UNIQUE(),
|
|
1152
|
+
columns: ctx.column_name_list_with_order().accept(this)
|
|
1153
|
+
});
|
|
1154
|
+
return index;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
// alter_table
|
|
1158
|
+
// : ALTER TABLE table_name (
|
|
1159
|
+
// SET '(' LOCK_ESCALATION '=' (AUTO | TABLE | DISABLE) ')'
|
|
1160
|
+
// | ADD column_def_table_constraints
|
|
1161
|
+
// | ALTER COLUMN (column_definition | column_modifier)
|
|
1162
|
+
// | DROP COLUMN id_ (',' id_)*
|
|
1163
|
+
// | DROP CONSTRAINT constraint = id_
|
|
1164
|
+
// | WITH (CHECK | NOCHECK) ADD (CONSTRAINT constraint = id_)? (
|
|
1165
|
+
// FOREIGN KEY '(' fk = column_name_list ')' REFERENCES table_name (
|
|
1166
|
+
// '(' pk = column_name_list ')'
|
|
1167
|
+
// )? (on_delete | on_update)*
|
|
1168
|
+
// | CHECK '(' search_condition ')'
|
|
1169
|
+
// )
|
|
1170
|
+
// | (NOCHECK | CHECK) CONSTRAINT constraint = id_
|
|
1171
|
+
// | (ENABLE | DISABLE) TRIGGER id_?
|
|
1172
|
+
// | REBUILD table_options
|
|
1173
|
+
// | SWITCH switch_partition
|
|
1174
|
+
// ) ';'?
|
|
1175
|
+
// ;
|
|
1176
|
+
}, {
|
|
1177
|
+
key: "visitAlter_table",
|
|
1178
|
+
value: function visitAlter_table(ctx) {
|
|
1179
|
+
var _this$data$refs3,
|
|
1180
|
+
_this$data$refs4,
|
|
1181
|
+
_table$fields,
|
|
1182
|
+
_table$indexes,
|
|
1183
|
+
_this18 = this;
|
|
1184
|
+
// table_name() returns an array because there are multiple table_name in the clause (REFERENCES table_name ...)
|
|
1185
|
+
var names = ctx.table_name()[0].accept(this);
|
|
1186
|
+
var _getSchemaAndTableNam3 = getSchemaAndTableName(names),
|
|
1187
|
+
schemaName = _getSchemaAndTableNam3.schemaName,
|
|
1188
|
+
tableName = _getSchemaAndTableNam3.tableName;
|
|
1189
|
+
var table = this.data.tables.find(function (t) {
|
|
1190
|
+
return t.name === tableName && t.schemaName === schemaName;
|
|
1191
|
+
});
|
|
1192
|
+
if (!table) return; // ALTER TABLE should appear after CREATE TABLE, so skip if table is not created yet
|
|
1193
|
+
|
|
1194
|
+
var columnDefTableConstraints = ctx.column_def_table_constraints() ? ctx.column_def_table_constraints().accept(this) : [];
|
|
1195
|
+
var _splitColumnDefTableC2 = splitColumnDefTableConstraints(columnDefTableConstraints),
|
|
1196
|
+
fieldsData = _splitColumnDefTableC2.fieldsData,
|
|
1197
|
+
indexes = _splitColumnDefTableC2.indexes,
|
|
1198
|
+
tableRefs = _splitColumnDefTableC2.tableRefs,
|
|
1199
|
+
columnDefaults = _splitColumnDefTableC2.columnDefaults,
|
|
1200
|
+
checkConstraints = _splitColumnDefTableC2.checkConstraints;
|
|
1201
|
+
var _parseFieldsAndInline2 = parseFieldsAndInlineRefsFromFieldsData(fieldsData, tableName, schemaName),
|
|
1202
|
+
inlineRefs = _parseFieldsAndInline2.inlineRefs,
|
|
1203
|
+
fields = _parseFieldsAndInline2.fields;
|
|
1204
|
+
(_this$data$refs3 = this.data.refs).push.apply(_this$data$refs3, _toConsumableArray((0, _lodash.flatten)(inlineRefs)));
|
|
1205
|
+
(_this$data$refs4 = this.data.refs).push.apply(_this$data$refs4, _toConsumableArray(tableRefs.map(function (tableRef) {
|
|
1206
|
+
tableRef.endpoints[0].tableName = tableName;
|
|
1207
|
+
tableRef.endpoints[0].schemaName = schemaName;
|
|
1208
|
+
return tableRef;
|
|
1209
|
+
})));
|
|
1210
|
+
(_table$fields = table.fields).push.apply(_table$fields, _toConsumableArray(fields));
|
|
1211
|
+
(_table$indexes = table.indexes).push.apply(_table$indexes, _toConsumableArray(indexes));
|
|
1212
|
+
columnDefaults.forEach(function (columnDefault) {
|
|
1213
|
+
var field = table.fields.find(function (f) {
|
|
1214
|
+
return f.name === columnDefault.column;
|
|
1215
|
+
});
|
|
1216
|
+
if (!field) return;
|
|
1217
|
+
field.dbdefault = columnDefault.defaultValue;
|
|
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
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// create_index
|
|
1241
|
+
// : CREATE UNIQUE? clustered? INDEX id_ ON table_name '(' column_name_list_with_order ')' (
|
|
1242
|
+
// INCLUDE '(' column_name_list ')'
|
|
1243
|
+
// )? (WHERE where = search_condition)? (create_index_options)? (ON id_)? ';'?
|
|
1244
|
+
// ;
|
|
1245
|
+
}, {
|
|
1246
|
+
key: "visitCreate_index",
|
|
1247
|
+
value: function visitCreate_index(ctx) {
|
|
1248
|
+
var _getSchemaAndTableNam4 = getSchemaAndTableName(ctx.table_name().accept(this)),
|
|
1249
|
+
schemaName = _getSchemaAndTableNam4.schemaName,
|
|
1250
|
+
tableName = _getSchemaAndTableNam4.tableName;
|
|
1251
|
+
var table = this.data.tables.find(function (t) {
|
|
1252
|
+
return t.name === tableName && t.schemaName === schemaName;
|
|
1253
|
+
});
|
|
1254
|
+
if (!table) return; // ALTER TABLE should appear after CREATE TABLE, so skip if table is not created yet
|
|
1255
|
+
|
|
1256
|
+
var index = new _AST.Index({
|
|
1257
|
+
name: ctx.id_()[0].accept(this),
|
|
1258
|
+
unique: !!ctx.UNIQUE(),
|
|
1259
|
+
columns: ctx.column_name_list_with_order().accept(this)
|
|
1260
|
+
});
|
|
1261
|
+
table.indexes.push(index);
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
// another_statement
|
|
1265
|
+
// : alter_queue
|
|
1266
|
+
// | checkpoint_statement
|
|
1267
|
+
// | conversation_statement
|
|
1268
|
+
// | create_contract
|
|
1269
|
+
// | create_queue
|
|
1270
|
+
// | cursor_statement
|
|
1271
|
+
// | declare_statement
|
|
1272
|
+
// | execute_statement
|
|
1273
|
+
// | kill_statement
|
|
1274
|
+
// | message_statement
|
|
1275
|
+
// | reconfigure_statement
|
|
1276
|
+
// | security_statement
|
|
1277
|
+
// | set_statement
|
|
1278
|
+
// | setuser_statement
|
|
1279
|
+
// | shutdown_statement
|
|
1280
|
+
// | transaction_statement
|
|
1281
|
+
// | use_statement
|
|
1282
|
+
// ;
|
|
1283
|
+
}, {
|
|
1284
|
+
key: "visitAnother_statement",
|
|
1285
|
+
value: function visitAnother_statement(ctx) {
|
|
1286
|
+
if (ctx.execute_statement()) {
|
|
1287
|
+
ctx.execute_statement().accept(this);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
// execute_statement
|
|
1292
|
+
// : EXECUTE execute_body ';'?
|
|
1293
|
+
// ;
|
|
1294
|
+
}, {
|
|
1295
|
+
key: "visitExecute_statement",
|
|
1296
|
+
value: function visitExecute_statement(ctx) {
|
|
1297
|
+
ctx.execute_body().accept(this);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
// execute_body
|
|
1301
|
+
// : (return_status = LOCAL_ID '=')? (func_proc_name_server_database_schema | execute_var_string) execute_statement_arg?
|
|
1302
|
+
// | '(' execute_var_string (',' execute_var_string)* ')' (AS (LOGIN | USER) '=' STRING)? (
|
|
1303
|
+
// AT_KEYWORD linkedServer = id_
|
|
1304
|
+
// )?
|
|
1305
|
+
// | AS ( (LOGIN | USER) '=' STRING | CALLER)
|
|
1306
|
+
// ;
|
|
1307
|
+
}, {
|
|
1308
|
+
key: "visitExecute_body",
|
|
1309
|
+
value: function visitExecute_body(ctx) {
|
|
1310
|
+
var funcNames = ctx.func_proc_name_server_database_schema() ? ctx.func_proc_name_server_database_schema().accept(this) : [];
|
|
1311
|
+
var funcName = (0, _lodash.last)(funcNames);
|
|
1312
|
+
if (funcName !== ADD_DESCRIPTION_FUNCTION_NAME) {
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
if (ctx.execute_statement_arg()) {
|
|
1316
|
+
// [
|
|
1317
|
+
// { name: '@name', value: "N'Column_Description'", type: 'expression' },
|
|
1318
|
+
// { name: '@value', value: '$-1', type: 'string' },
|
|
1319
|
+
// { name: '@level0type', value: "N'Schema'", type: 'expression' },
|
|
1320
|
+
// { name: '@level0name', value: 'dbo', type: 'string' },
|
|
1321
|
+
// { name: '@level1type', value: "N'Table'", type: 'expression' },
|
|
1322
|
+
// { name: '@level1name', value: 'orders', type: 'string' },
|
|
1323
|
+
// { name: '@level2type', value: "N'Column'", type: 'expression' },
|
|
1324
|
+
// { name: '@level2name', value: 'status', type: 'string' }
|
|
1325
|
+
// ]
|
|
1326
|
+
var args = ctx.execute_statement_arg().accept(this);
|
|
1327
|
+
|
|
1328
|
+
// {
|
|
1329
|
+
// name: "N'Table_Description'",
|
|
1330
|
+
// value: 'This is a note in table "orders"',
|
|
1331
|
+
// level0type: "N'Schema'",
|
|
1332
|
+
// level0name: 'dbo',
|
|
1333
|
+
// level1type: "N'Table'",
|
|
1334
|
+
// level1name: 'orders'
|
|
1335
|
+
// }
|
|
1336
|
+
var argsObj = args.reduce(function (acc, arg) {
|
|
1337
|
+
var name = arg.name.slice(1);
|
|
1338
|
+
acc[name] = arg.value;
|
|
1339
|
+
return acc;
|
|
1340
|
+
}, {});
|
|
1341
|
+
if (!argsObj['name'].includes('Description')) {
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-addextendedproperty-transact-sql?view=sql-server-ver16#----level0type
|
|
1346
|
+
var level0Type = argsObj['level0type'].toLowerCase();
|
|
1347
|
+
if (!level0Type.includes('schema')) return;
|
|
1348
|
+
var schemaName = argsObj['level0name'] !== 'dbo' ? argsObj['level0name'] : undefined;
|
|
1349
|
+
var level1Type = argsObj['level1type'].toLowerCase();
|
|
1350
|
+
var tableName = level1Type.includes('table') ? argsObj['level1name'] : null;
|
|
1351
|
+
var table = this.data.tables.find(function (t) {
|
|
1352
|
+
return t.name === tableName && t.schemaName === schemaName;
|
|
1353
|
+
});
|
|
1354
|
+
if (!table) return;
|
|
1355
|
+
if (!argsObj['level2type']) {
|
|
1356
|
+
table.note = {
|
|
1357
|
+
value: argsObj.value
|
|
1358
|
+
};
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
var level2Type = argsObj['level2type'].toLowerCase();
|
|
1362
|
+
var columnName = level2Type.includes('column') ? argsObj['level2name'] : null;
|
|
1363
|
+
var field = table.fields.find(function (f) {
|
|
1364
|
+
return f.name === columnName;
|
|
1365
|
+
});
|
|
1366
|
+
if (!field) return;
|
|
1367
|
+
field.note = {
|
|
1368
|
+
value: argsObj.value
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
// func_proc_name_server_database_schema
|
|
1374
|
+
// : server = id_? '.' database = id_? '.' schema = id_? '.' procedure = id_
|
|
1375
|
+
// | func_proc_name_database_schema
|
|
1376
|
+
// ;
|
|
1377
|
+
}, {
|
|
1378
|
+
key: "visitFunc_proc_name_server_database_schema",
|
|
1379
|
+
value: function visitFunc_proc_name_server_database_schema(ctx) {
|
|
1380
|
+
var _this19 = this;
|
|
1381
|
+
if (ctx.func_proc_name_database_schema()) {
|
|
1382
|
+
return ctx.func_proc_name_database_schema().accept(this);
|
|
1383
|
+
} else {
|
|
1384
|
+
return ctx.id_().map(function (id) {
|
|
1385
|
+
return id.accept(_this19);
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
// func_proc_name_database_schema
|
|
1391
|
+
// : database = id_? '.' schema = id_? '.' procedure = id_
|
|
1392
|
+
// | func_proc_name_schema
|
|
1393
|
+
// ;
|
|
1394
|
+
}, {
|
|
1395
|
+
key: "visitFunc_proc_name_database_schema",
|
|
1396
|
+
value: function visitFunc_proc_name_database_schema(ctx) {
|
|
1397
|
+
var _this20 = this;
|
|
1398
|
+
if (ctx.func_proc_name_schema()) {
|
|
1399
|
+
return ctx.func_proc_name_schema().accept(this);
|
|
1400
|
+
} else {
|
|
1401
|
+
return ctx.id_().map(function (id) {
|
|
1402
|
+
return id.accept(_this20);
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
// func_proc_name_schema
|
|
1408
|
+
// : ((schema = id_) '.')? procedure = id_
|
|
1409
|
+
// ;
|
|
1410
|
+
}, {
|
|
1411
|
+
key: "visitFunc_proc_name_schema",
|
|
1412
|
+
value: function visitFunc_proc_name_schema(ctx) {
|
|
1413
|
+
var _this21 = this;
|
|
1414
|
+
return ctx.id_().map(function (id) {
|
|
1415
|
+
return id.accept(_this21);
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
// execute_statement_arg
|
|
1420
|
+
// : execute_statement_arg_unnamed (',' execute_statement_arg)* //Unnamed params can continue unnamed
|
|
1421
|
+
// | execute_statement_arg_named (',' execute_statement_arg_named)* //Named can only be continued by unnamed
|
|
1422
|
+
// ;
|
|
1423
|
+
}, {
|
|
1424
|
+
key: "visitExecute_statement_arg",
|
|
1425
|
+
value: function visitExecute_statement_arg(ctx) {
|
|
1426
|
+
var _this22 = this;
|
|
1427
|
+
if (ctx.execute_statement_arg_unnamed()) {
|
|
1428
|
+
return ctx.execute_statement_arg_unnamed().map(function (item) {
|
|
1429
|
+
return item.accept(_this22);
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
return ctx.execute_statement_arg_named().map(function (item) {
|
|
1433
|
+
return item.accept(_this22);
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
// execute_statement_arg_named
|
|
1438
|
+
// : name = LOCAL_ID '=' value = execute_parameter
|
|
1439
|
+
// ;
|
|
1440
|
+
}, {
|
|
1441
|
+
key: "visitExecute_statement_arg_named",
|
|
1442
|
+
value: function visitExecute_statement_arg_named(ctx) {
|
|
1443
|
+
var _ctx$execute_paramete = ctx.execute_parameter().accept(this),
|
|
1444
|
+
value = _ctx$execute_paramete.value,
|
|
1445
|
+
type = _ctx$execute_paramete.type;
|
|
1446
|
+
return {
|
|
1447
|
+
name: ctx.LOCAL_ID().getText(),
|
|
1448
|
+
value: value,
|
|
1449
|
+
type: type
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
// execute_parameter
|
|
1454
|
+
// : (constant | LOCAL_ID (OUTPUT | OUT)? | id_ | DEFAULT | NULL_)
|
|
1455
|
+
// ;
|
|
1456
|
+
}, {
|
|
1457
|
+
key: "visitExecute_parameter",
|
|
1458
|
+
value: function visitExecute_parameter(ctx) {
|
|
1459
|
+
if (ctx.constant()) {
|
|
1460
|
+
return ctx.constant().accept(this);
|
|
1461
|
+
}
|
|
1462
|
+
return ctx.getText();
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// constant
|
|
1466
|
+
// : STRING // string, datetime or uniqueidentifier
|
|
1467
|
+
// | BINARY
|
|
1468
|
+
// | '-'? (DECIMAL | REAL | FLOAT) // float or decimal
|
|
1469
|
+
// | '-'? dollar = '$' ('-' | '+')? (DECIMAL | FLOAT) // money
|
|
1470
|
+
// | parameter
|
|
1471
|
+
// ;
|
|
1472
|
+
}, {
|
|
1473
|
+
key: "visitConstant",
|
|
1474
|
+
value: function visitConstant(ctx) {
|
|
1475
|
+
if (ctx.STRING() || ctx.BINARY()) {
|
|
1476
|
+
var value = getStringFromRawString(ctx.getText());
|
|
1477
|
+
return {
|
|
1478
|
+
value: value,
|
|
1479
|
+
type: value.startsWith("N'") ? _constants.DATA_TYPE.EXPRESSION : _constants.DATA_TYPE.STRING
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
if (ctx.DOLLAR()) {
|
|
1483
|
+
var _value2 = ctx.getText();
|
|
1484
|
+
return {
|
|
1485
|
+
value: _value2,
|
|
1486
|
+
type: _constants.DATA_TYPE.STRING
|
|
1487
|
+
};
|
|
1488
|
+
}
|
|
1489
|
+
if (ctx.REAL() || ctx.DECIMAL() || ctx.FLOAT()) {
|
|
1490
|
+
return {
|
|
1491
|
+
value: ctx.getText(),
|
|
1492
|
+
type: _constants.DATA_TYPE.NUMBER
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
return {
|
|
1496
|
+
value: (0, _helpers.getOriginalText)(ctx),
|
|
1497
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
}]);
|
|
1501
|
+
return MssqlASTGen;
|
|
1502
|
+
}(_TSqlParserVisitor2["default"]);
|
|
1503
|
+
exports["default"] = MssqlASTGen;
|