@dbml/core 2.3.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/lib/export/DbmlExporter.js +17 -9
  2. package/lib/export/JsonExporter.js +1 -3
  3. package/lib/export/ModelExporter.js +1 -3
  4. package/lib/export/MysqlExporter.js +50 -42
  5. package/lib/export/PostgresExporter.js +64 -49
  6. package/lib/export/SqlServerExporter.js +52 -46
  7. package/lib/model_structure/database.js +73 -28
  8. package/lib/model_structure/dbState.js +1 -3
  9. package/lib/model_structure/element.js +13 -13
  10. package/lib/model_structure/endpoint.js +18 -14
  11. package/lib/model_structure/enum.js +18 -14
  12. package/lib/model_structure/enumValue.js +16 -12
  13. package/lib/model_structure/field.js +47 -13
  14. package/lib/model_structure/indexColumn.js +16 -12
  15. package/lib/model_structure/indexes.js +18 -14
  16. package/lib/model_structure/ref.js +19 -16
  17. package/lib/model_structure/schema.js +24 -36
  18. package/lib/model_structure/table.js +19 -15
  19. package/lib/model_structure/tableGroup.js +18 -14
  20. package/lib/model_structure/utils.js +5 -0
  21. package/lib/parse/Parser.js +2 -4
  22. package/lib/parse/buildParser.js +1 -3
  23. package/lib/parse/dbml/parser.pegjs +64 -20
  24. package/lib/parse/dbmlParser.js +1401 -899
  25. package/lib/parse/mssql/constraint_definition/actions.js +2 -2
  26. package/lib/parse/mssql/fk_definition/actions.js +10 -3
  27. package/lib/parse/mssql/keyword_parsers.js +12 -2
  28. package/lib/parse/mssql/statements/actions.js +37 -6
  29. package/lib/parse/mssql/statements/index.js +1 -1
  30. package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +11 -5
  31. package/lib/parse/mssql/statements/statement_types/comments/actions.js +57 -0
  32. package/lib/parse/mssql/statements/statement_types/comments/index.js +97 -0
  33. package/lib/parse/mssql/statements/statement_types/create_index/actions.js +6 -1
  34. package/lib/parse/mssql/statements/statement_types/create_table/actions.js +12 -10
  35. package/lib/parse/mssql/statements/statement_types/index.js +4 -1
  36. package/lib/parse/mssql/utils.js +16 -1
  37. package/lib/parse/mysql/parser.pegjs +66 -40
  38. package/lib/parse/mysqlParser.js +534 -359
  39. package/lib/parse/postgresParser.js +15 -13
  40. package/lib/parse/postgresql/Base_rules.pegjs +45 -10
  41. package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +49 -4
  42. package/lib/parse/postgresql/Commands/Comment.pegjs +18 -6
  43. package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +5 -3
  44. package/lib/parse/postgresql/Commands/Create_table/Create_table_of.pegjs +1 -1
  45. package/lib/parse/postgresql/Commands/Create_table/Create_table_partition_of.pegjs +1 -1
  46. package/lib/parse/postgresql/Commands/Create_type/Create_type_enum.pegjs +2 -2
  47. package/lib/parse/postgresql/Commands/Ignore_syntax.pegjs +10 -1
  48. package/lib/parse/postgresql/InitializerUtils.pegjs +14 -2
  49. package/lib/parse/postgresql/Keywords.pegjs +5 -1
  50. package/lib/parse/postgresql/parser.pegjs +22 -8
  51. package/lib/parse/schemarbParser.js +3 -3
  52. package/package.json +2 -2
@@ -17,11 +17,11 @@ var _utils = require("./utils");
17
17
 
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
19
 
20
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
20
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
21
21
 
22
22
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
23
23
 
24
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
24
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
25
25
 
26
26
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
27
 
@@ -31,21 +31,25 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
31
31
 
32
32
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
33
33
 
34
+ 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
35
+
36
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
37
+
38
+ 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); }; }
39
+
34
40
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
35
41
 
36
42
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
37
43
 
38
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
44
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
39
45
 
40
- 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
41
-
42
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
46
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
43
47
 
44
- var Table =
45
- /*#__PURE__*/
46
- function (_Element) {
48
+ var Table = /*#__PURE__*/function (_Element) {
47
49
  _inherits(Table, _Element);
48
50
 
51
+ var _super = _createSuper(Table);
52
+
49
53
  function Table() {
50
54
  var _this;
51
55
 
@@ -64,7 +68,7 @@ function (_Element) {
64
68
 
65
69
  _classCallCheck(this, Table);
66
70
 
67
- _this = _possibleConstructorReturn(this, _getPrototypeOf(Table).call(this, token));
71
+ _this = _super.call(this, token);
68
72
  _this.name = name;
69
73
  _this.alias = alias;
70
74
  _this.note = note;
@@ -98,7 +102,7 @@ function (_Element) {
98
102
  }
99
103
 
100
104
  rawFields.forEach(function (field) {
101
- _this2.pushField(new _field["default"](_objectSpread({}, field, {
105
+ _this2.pushField(new _field["default"](_objectSpread(_objectSpread({}, field), {}, {
102
106
  table: _this2
103
107
  })));
104
108
  });
@@ -124,7 +128,7 @@ function (_Element) {
124
128
  var _this3 = this;
125
129
 
126
130
  rawIndexes.forEach(function (index) {
127
- _this3.pushIndex(new _indexes["default"](_objectSpread({}, index, {
131
+ _this3.pushIndex(new _indexes["default"](_objectSpread(_objectSpread({}, index), {}, {
128
132
  table: _this3
129
133
  })));
130
134
  });
@@ -161,7 +165,7 @@ function (_Element) {
161
165
  }, {
162
166
  key: "export",
163
167
  value: function _export() {
164
- return _objectSpread({}, this.shallowExport(), {}, this.exportChild());
168
+ return _objectSpread(_objectSpread({}, this.shallowExport()), this.exportChild());
165
169
  }
166
170
  }, {
167
171
  key: "exportChild",
@@ -208,9 +212,9 @@ function (_Element) {
208
212
  }, {
209
213
  key: "normalize",
210
214
  value: function normalize(model) {
211
- model.tables = _objectSpread({}, model.tables, _defineProperty({}, this.id, _objectSpread({
215
+ model.tables = _objectSpread(_objectSpread({}, model.tables), {}, _defineProperty({}, this.id, _objectSpread(_objectSpread(_objectSpread({
212
216
  id: this.id
213
- }, this.shallowExport(), {}, this.exportChildIds(), {}, this.exportParentIds())));
217
+ }, this.shallowExport()), this.exportChildIds()), this.exportParentIds())));
214
218
  this.fields.forEach(function (field) {
215
219
  return field.normalize(model);
216
220
  });
@@ -11,11 +11,11 @@ var _utils = require("./utils");
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
13
 
14
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
14
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
15
15
 
16
16
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
17
17
 
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
19
 
20
20
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
21
 
@@ -25,21 +25,25 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
25
25
 
26
26
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
27
27
 
28
+ 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
29
+
30
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31
+
32
+ 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); }; }
33
+
28
34
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
29
35
 
30
36
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
31
37
 
32
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
38
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
33
39
 
34
- 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
35
-
36
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
40
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
37
41
 
38
- var TableGroup =
39
- /*#__PURE__*/
40
- function (_Element) {
42
+ var TableGroup = /*#__PURE__*/function (_Element) {
41
43
  _inherits(TableGroup, _Element);
42
44
 
45
+ var _super = _createSuper(TableGroup);
46
+
43
47
  function TableGroup(_ref) {
44
48
  var _this;
45
49
 
@@ -52,7 +56,7 @@ function (_Element) {
52
56
 
53
57
  _classCallCheck(this, TableGroup);
54
58
 
55
- _this = _possibleConstructorReturn(this, _getPrototypeOf(TableGroup).call(this, token));
59
+ _this = _super.call(this, token);
56
60
  _this.name = name;
57
61
  _this.tables = [];
58
62
  _this.schema = schema;
@@ -76,7 +80,7 @@ function (_Element) {
76
80
  var _this2 = this;
77
81
 
78
82
  rawTables.forEach(function (rawTable) {
79
- var table = _this2.schema.database.findTable(rawTable);
83
+ var table = _this2.schema.database.findTable(rawTable.schemaName, rawTable.name);
80
84
 
81
85
  if (!table) {
82
86
  _this2.error("Table ".concat(rawTable.schemaName ? "\"".concat(rawTable.schemaName, "\".") : '').concat(rawTable.name, " don't exist"));
@@ -108,7 +112,7 @@ function (_Element) {
108
112
  }, {
109
113
  key: "export",
110
114
  value: function _export() {
111
- return _objectSpread({}, this.shallowExport(), {}, this.exportChild());
115
+ return _objectSpread(_objectSpread({}, this.shallowExport()), this.exportChild());
112
116
  }
113
117
  }, {
114
118
  key: "exportChild",
@@ -148,9 +152,9 @@ function (_Element) {
148
152
  }, {
149
153
  key: "normalize",
150
154
  value: function normalize(model) {
151
- model.tableGroups = _objectSpread({}, model.tableGroups, _defineProperty({}, this.id, _objectSpread({
155
+ model.tableGroups = _objectSpread(_objectSpread({}, model.tableGroups), {}, _defineProperty({}, this.id, _objectSpread(_objectSpread(_objectSpread({
152
156
  id: this.id
153
- }, this.shallowExport(), {}, this.exportChildIds(), {}, this.exportParentIds())));
157
+ }, this.shallowExport()), this.exportChildIds()), this.exportParentIds())));
154
158
  }
155
159
  }]);
156
160
 
@@ -4,9 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.shouldPrintSchema = shouldPrintSchema;
7
+ exports.shouldPrintSchemaName = shouldPrintSchemaName;
7
8
 
8
9
  var _config = require("./config");
9
10
 
10
11
  function shouldPrintSchema(schema) {
11
12
  return schema.name !== _config.DEFAULT_SCHEMA_NAME || schema.name === _config.DEFAULT_SCHEMA_NAME && schema.database.hasDefaultSchema;
13
+ }
14
+
15
+ function shouldPrintSchemaName(schemaName) {
16
+ return schemaName !== _config.DEFAULT_SCHEMA_NAME;
12
17
  }
@@ -19,7 +19,7 @@ var _mssqlParser = _interopRequireDefault(require("./mssqlParser"));
19
19
 
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
21
 
22
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
22
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
23
23
 
24
24
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25
25
 
@@ -27,9 +27,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
27
27
 
28
28
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
29
29
 
30
- var Parser =
31
- /*#__PURE__*/
32
- function () {
30
+ var Parser = /*#__PURE__*/function () {
33
31
  function Parser() {
34
32
  _classCallCheck(this, Parser);
35
33
  }
@@ -21,9 +21,7 @@ function buildParserFile(_x, _x2) {
21
21
  }
22
22
 
23
23
  function _buildParserFile() {
24
- _buildParserFile = _asyncToGenerator(
25
- /*#__PURE__*/
26
- regeneratorRuntime.mark(function _callee(source, fileName) {
24
+ _buildParserFile = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(source, fileName) {
27
25
  return regeneratorRuntime.wrap(function _callee$(_context) {
28
26
  while (1) {
29
27
  switch (_context.prev = _context.next) {
@@ -5,6 +5,7 @@
5
5
  refs: [],
6
6
  enums: [],
7
7
  tableGroups: [],
8
+ aliases: [],
8
9
  project: {},
9
10
  };
10
11
  let projectCnt = 0;
@@ -122,23 +123,31 @@ ProjectField
122
123
  }
123
124
  }
124
125
 
125
- TableGroupSyntax = table_group sp+ name:name _ "{" _ body:table_group_body _ "}" {
126
+ TableGroupSyntax = table_group sp+ schemaName:schema_name? name:name _ "{" _ body:table_group_body _ "}" {
126
127
  return {
127
128
  name: name,
129
+ schemaName,
128
130
  tables: body,
129
131
  token: location()
130
132
  }
131
133
  }
132
134
 
133
- table_group_body = tables:(name __)* {
135
+ table_group_body = tables:(schema_name? name __)* {
134
136
  return tables.map(t => ({
135
- name: t[0]
137
+ name: t[1],
138
+ schemaName: t[0]
136
139
  }));
137
140
  }
138
141
 
139
142
  // References
140
143
  RefSyntax
141
- = r: (ref_long / ref_short) { return r; }
144
+ = r: (ref_long / ref_short) {
145
+ const schemaName = r.endpoints[0].schemaName;
146
+ return {
147
+ ...r,
148
+ schemaName,
149
+ };
150
+ }
142
151
 
143
152
  ref_long
144
153
  = ref name:(__ name)? _ "{" _ body:ref_body _ "}" {
@@ -163,17 +172,19 @@ ref_short
163
172
  }
164
173
 
165
174
  ref_body
166
- = table1:name "." field1:RefField sp+ relation:relation sp+ table2:name "." field2:RefField sp* ref_settings:RefSettings? {
175
+ = field1:field_identifier sp+ relation:relation sp+ field2:field_identifier sp* ref_settings:RefSettings? {
167
176
  const endpoints = [
168
177
  {
169
- tableName: table1,
170
- fieldNames: field1,
178
+ schemaName: field1.schemaName,
179
+ tableName: field1.tableName,
180
+ fieldNames: field1.fieldNames,
171
181
  relation: relation === ">" ? "*" : "1",
172
182
  token: location()
173
183
  },
174
184
  {
175
- tableName: table2,
176
- fieldNames: field2,
185
+ schemaName: field2.schemaName,
186
+ tableName: field2.tableName,
187
+ fieldNames: field2.fieldNames,
177
188
  relation: relation === "<" ? "*" : "1",
178
189
  token: location()
179
190
  }
@@ -224,7 +235,7 @@ OnDelete
224
235
 
225
236
  // Tables
226
237
  TableSyntax
227
- = table sp+ name:name alias:alias_def? sp* table_settings:TableSettings? _ "{" body:TableBody "}" {
238
+ = table sp+ schemaName:schema_name? name:name alias:alias_def? sp* table_settings:TableSettings? _ "{" body:TableBody "}" {
228
239
  let fields = body.fields || [];
229
240
  let indexes = body.indexes || [];
230
241
  // Handle list of partial inline_refs
@@ -234,12 +245,14 @@ TableSyntax
234
245
  (field.inline_refs || []).forEach((iref) => {
235
246
  const endpoints = [
236
247
  {
248
+ schemaName: iref.schemaName,
237
249
  tableName: iref.tableName,
238
250
  fieldNames: iref.fieldNames,
239
251
  relation: iref.relation === "<" ? "*" : "1",
240
252
  token: iref.token
241
253
  },
242
254
  {
255
+ schemaName: schemaName,
243
256
  tableName: name,
244
257
  fieldNames: [field.name],
245
258
  relation: iref.relation === ">" ? "*" : "1",
@@ -247,6 +260,7 @@ TableSyntax
247
260
  }];
248
261
 
249
262
  let ref = {
263
+ schemaName,
250
264
  name: null, // no name
251
265
  endpoints: endpoints,
252
266
  token: iref.token
@@ -255,8 +269,21 @@ TableSyntax
255
269
  })
256
270
  });
257
271
 
272
+ if (alias) {
273
+ if (data.aliases.find(a => a.name === alias)) error(`Alias "${alias}" is already defined`);
274
+ data.aliases.push({
275
+ name: alias,
276
+ kind: 'table',
277
+ value: {
278
+ tableName: name,
279
+ schemaName: schemaName,
280
+ }
281
+ })
282
+ }
283
+
258
284
  let res = {
259
285
  name: name,
286
+ schemaName,
260
287
  alias: alias,
261
288
  fields: fields,
262
289
  token: location(),
@@ -323,10 +350,13 @@ TableElement
323
350
  }
324
351
 
325
352
  Field
326
- = _ name:name sp+ type:type constrains:(sp+ constrain)* field_settings:(sp+ FieldSettings)? sp* comment? newline {
353
+ = _ name:name sp+ typeSchemaName:schema_name? type:type constrains:(sp+ constrain)* field_settings:(sp+ FieldSettings)? sp* comment? newline {
327
354
  const field = {
328
355
  name: name,
329
- type: type,
356
+ type: {
357
+ schemaName: typeSchemaName,
358
+ ...type,
359
+ },
330
360
  token: location(),
331
361
  inline_refs: []
332
362
  }
@@ -338,9 +368,10 @@ Field
338
368
  }
339
369
 
340
370
  EnumSyntax
341
- = enum sp+ name:name _ "{" body: EnumBody "}" {
371
+ = enum sp+ schemaName:schema_name? name:name _ "{" body: EnumBody "}" {
342
372
  return {
343
373
  name: name,
374
+ schemaName,
344
375
  token: location(),
345
376
  values: body.enum_values
346
377
  };
@@ -437,7 +468,7 @@ FieldSetting
437
468
  / _ a:"unique"i _ { return a }
438
469
  / _ a:"increment" _ { return a }
439
470
  / _ v:ObjectNote _ { return { type: 'note', value: v } }
440
- / _ v:RefInline { return { type: 'ref_inline', value: v } }
471
+ / _ v:RefInline _ { return { type: 'ref_inline', value: v } }
441
472
  / _ v:Default _ {return {type: 'default', value: v} }
442
473
 
443
474
  Indexes
@@ -523,10 +554,11 @@ ObjectNote
523
554
  IndexType
524
555
  = "type:"i _ val:(btree/hash) { return val }
525
556
  RefInline
526
- = "ref:" sp* relation:relation sp+ table2:name "." field2:name {
557
+ = "ref:" sp* relation:relation sp+ field:inline_field_identifier{
527
558
  return {
528
- tableName: table2,
529
- fieldNames: [field2],
559
+ schemaName: field.schemaName,
560
+ tableName: field.tableName,
561
+ fieldNames: [field.fieldName],
530
562
  relation: relation,
531
563
  token: location(),
532
564
  }
@@ -584,6 +616,16 @@ name "valid name"
584
616
  = c:(character+) { return c.join("") }
585
617
  / quote c:[^\"\n]+ quote { return c.join("") }
586
618
 
619
+ schema_name "schema name" = name:name "." { return name }
620
+
621
+ field_identifier =
622
+ schemaName:name "." tableName:name "." fieldNames:RefField { return { schemaName, tableName, fieldNames } } /
623
+ tableName:name "." fieldNames:RefField { return { schemaName: null, tableName, fieldNames } }
624
+
625
+ inline_field_identifier =
626
+ schemaName:name "." tableName:name "." fieldName:name { return { schemaName, tableName, fieldName } } /
627
+ tableName:name "." fieldName:name { return { schemaName: null, tableName, fieldName } }
628
+
587
629
  type_name "valid name"
588
630
  = c:(type_character+) { return c.join("") }
589
631
  / quote c:[^\"\n]+ quote { return c.join("") }
@@ -626,7 +668,9 @@ __ = (comment/whitespace)+
626
668
 
627
669
  endline "endline" = sp* newline
628
670
  tab = "\t"
629
- comment "comment" = "//" [^\n]*
671
+ single_line_comment = "//" [^\n]*
672
+ multi_lime_comment = "/*" (!"*/" .)* "*/"
673
+ comment "comment" = single_line_comment / multi_lime_comment
630
674
  newline "newline" = "\r\n" / "\n"
631
675
  whitespace "whitespace" = [ \t\r\n\r]
632
676
  whitespace_quote "whitespace" = [ \t\r\n\r\"]
@@ -705,10 +749,10 @@ BooleanLiteral = boolean: ('true'i/'false'i/'null'i) {
705
749
  value: boolean
706
750
  };
707
751
  }
708
- NumberLiteral = number:(float / integer) {
752
+ NumberLiteral = minus:"-"? number:(float / integer) {
709
753
  return {
710
754
  type: 'number',
711
- value: number
755
+ value: minus ? -number : number
712
756
  };
713
757
  }
714
758
  float