@dbml/core 2.3.1 → 2.4.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.
Files changed (31) hide show
  1. package/lib/export/DbmlExporter.js +9 -1
  2. package/lib/export/MysqlExporter.js +41 -35
  3. package/lib/export/PostgresExporter.js +55 -42
  4. package/lib/export/SqlServerExporter.js +43 -39
  5. package/lib/model_structure/database.js +53 -12
  6. package/lib/model_structure/endpoint.js +2 -2
  7. package/lib/model_structure/field.js +31 -1
  8. package/lib/model_structure/ref.js +1 -2
  9. package/lib/model_structure/schema.js +3 -19
  10. package/lib/model_structure/tableGroup.js +1 -1
  11. package/lib/model_structure/utils.js +5 -0
  12. package/lib/parse/dbml/parser.pegjs +61 -19
  13. package/lib/parse/dbmlParser.js +1219 -883
  14. package/lib/parse/mssql/fk_definition/actions.js +10 -3
  15. package/lib/parse/mssql/statements/actions.js +9 -6
  16. package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +11 -5
  17. package/lib/parse/mssql/statements/statement_types/create_index/actions.js +6 -1
  18. package/lib/parse/mssql/statements/statement_types/create_table/actions.js +11 -9
  19. package/lib/parse/mssql/utils.js +15 -0
  20. package/lib/parse/mysql/parser.pegjs +46 -14
  21. package/lib/parse/mysqlParser.js +215 -167
  22. package/lib/parse/postgresParser.js +11 -10
  23. package/lib/parse/postgresql/Base_rules.pegjs +24 -3
  24. package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +2 -1
  25. package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +5 -3
  26. package/lib/parse/postgresql/Commands/Create_table/Create_table_of.pegjs +1 -1
  27. package/lib/parse/postgresql/Commands/Create_table/Create_table_partition_of.pegjs +1 -1
  28. package/lib/parse/postgresql/Commands/Create_type/Create_type_enum.pegjs +2 -2
  29. package/lib/parse/postgresql/InitializerUtils.pegjs +10 -0
  30. package/lib/parse/postgresql/parser.pegjs +2 -1
  31. package/package.json +2 -2
@@ -17,6 +17,12 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
17
17
 
18
18
  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; }
19
19
 
20
+ 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; }
21
+
22
+ 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; }
23
+
24
+ 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; }
25
+
20
26
  var _ = require("lodash"),
21
27
  pluralize = require("pluralize");
22
28
 
@@ -156,7 +162,7 @@ function peg$parse(input, options) {
156
162
  peg$c3 = peg$literalExpectation("(", false),
157
163
  peg$c4 = ")",
158
164
  peg$c5 = peg$literalExpectation(")", false),
159
- peg$c6 = function peg$c6(name, body) {
165
+ peg$c6 = function peg$c6(table_name, body) {
160
166
  var fields = body.fields;
161
167
  var indexes = body.indexes;
162
168
  var bodyRefs = body.refs;
@@ -173,7 +179,7 @@ function peg$parse(input, options) {
173
179
  values.push(enumValue);
174
180
  });
175
181
  var _enum = {
176
- name: "".concat(name, "_").concat(field.name, "_enum"),
182
+ name: "".concat(table_name.schemaName ? "".concat(table_name.schemaName, "_") : '').concat(table_name.name, "_").concat(field.name, "_enum"),
177
183
  values: values
178
184
  };
179
185
  enums.push(_enum);
@@ -181,19 +187,18 @@ function peg$parse(input, options) {
181
187
  }
182
188
  });
183
189
  bodyRefs.forEach(function (ref) {
184
- ref.endpoints[0].tableName = name;
190
+ ref.endpoints[0].tableName = table_name.name;
191
+ ref.endpoints[0].schemaName = table_name.schemaName;
185
192
  ref.endpoints[0].relation = '*';
186
193
  refs.push(ref);
187
194
  }); // return statement
188
195
 
189
- return indexes ? {
190
- name: name,
196
+ return indexes ? _objectSpread(_objectSpread({}, table_name), {}, {
191
197
  fields: fields,
192
198
  indexes: indexes
193
- } : {
194
- name: name,
199
+ }) : _objectSpread(_objectSpread({}, table_name), {}, {
195
200
  fields: fields
196
- };
201
+ });
197
202
  },
198
203
  peg$c7 = function peg$c7(lines) {
199
204
  // classify lines into pk, fk, unique, index and fields
@@ -302,7 +307,8 @@ function peg$parse(input, options) {
302
307
  fieldNames: fields,
303
308
  relation: "*"
304
309
  }, {
305
- tableName: table2,
310
+ tableName: table2.name,
311
+ schemaName: table2.schemaName,
306
312
  fieldNames: fields2,
307
313
  relation: "1"
308
314
  }]
@@ -624,7 +630,8 @@ function peg$parse(input, options) {
624
630
  }));
625
631
 
626
632
  fks.forEach(function (fk) {
627
- fk.endpoints[0].tableName = table;
633
+ fk.endpoints[0].tableName = table.name;
634
+ fk.endpoints[0].schemaName = table.schemaName;
628
635
  });
629
636
  refs.push.apply(refs, _toConsumableArray(fks));
630
637
 
@@ -634,9 +641,7 @@ function peg$parse(input, options) {
634
641
  return o.pks;
635
642
  }));
636
643
 
637
- var tableAlter = tables.find(function (t) {
638
- return t.name === table;
639
- });
644
+ var tableAlter = findTable(table.schemaName, table.name);
640
645
  var index = {
641
646
  columns: pks.map(function (field) {
642
647
  return {
@@ -708,9 +713,7 @@ function peg$parse(input, options) {
708
713
  if (constraint.toLowerCase() === "unique") index.unique = true;
709
714
  var type = typeInOption || indexType;
710
715
  if (type) index.type = type;
711
- var table = tables.find(function (table) {
712
- return table.name === tableName;
713
- });
716
+ var table = findTable(tableName.schemaName, tableName.name);
714
717
 
715
718
  if (table.indexes) {
716
719
  table.indexes.push(index);
@@ -860,19 +863,40 @@ function peg$parse(input, options) {
860
863
  },
861
864
  peg$c268 = /^[^`]/,
862
865
  peg$c269 = peg$classExpectation(["`"], true, false),
863
- peg$c270 = peg$otherExpectation("valid table name"),
864
- peg$c271 = ".",
865
- peg$c272 = peg$literalExpectation(".", false),
866
- peg$c273 = peg$otherExpectation("type"),
867
- peg$c274 = function peg$c274(c) {
866
+ peg$c270 = ".",
867
+ peg$c271 = peg$literalExpectation(".", false),
868
+ peg$c272 = function peg$c272(names) {
869
+ var dbName = null;
870
+ var schemaName = null;
871
+
872
+ if (names && names.length > 0) {
873
+ if (names.length === 1) schemaName = names[0][0];else {
874
+ dbName = names[0][0];
875
+ schemaName = names[1][0];
876
+ }
877
+ }
878
+
879
+ return {
880
+ dbName: dbName,
881
+ schemaName: schemaName
882
+ };
883
+ },
884
+ peg$c273 = peg$otherExpectation("valid table name"),
885
+ peg$c274 = function peg$c274(pathName, name) {
886
+ return _objectSpread(_objectSpread({}, pathName), {}, {
887
+ name: name
888
+ });
889
+ },
890
+ peg$c275 = peg$otherExpectation("type"),
891
+ peg$c276 = function peg$c276(c) {
868
892
  return c;
869
893
  },
870
- peg$c275 = function peg$c275(c) {
894
+ peg$c277 = function peg$c277(c) {
871
895
  return {
872
896
  type_name: c
873
897
  };
874
898
  },
875
- peg$c276 = function peg$c276(type_name, args) {
899
+ peg$c278 = function peg$c278(type_name, args) {
876
900
  args = args ? args[2] : null;
877
901
 
878
902
  if (type_name.toLowerCase() !== 'enum') {
@@ -884,67 +908,67 @@ function peg$parse(input, options) {
884
908
  args: args
885
909
  };
886
910
  },
887
- peg$c277 = peg$otherExpectation("expression"),
888
- peg$c278 = function peg$c278(factors) {
911
+ peg$c279 = peg$otherExpectation("expression"),
912
+ peg$c280 = function peg$c280(factors) {
889
913
  return removeReduntdantSpNewline(_.flattenDeep(factors).join(""));
890
914
  },
891
- peg$c279 = ",",
892
- peg$c280 = peg$literalExpectation(",", false),
893
- peg$c281 = ");",
894
- peg$c282 = peg$literalExpectation(");", false),
895
- peg$c283 = function peg$c283(factors) {
915
+ peg$c281 = ",",
916
+ peg$c282 = peg$literalExpectation(",", false),
917
+ peg$c283 = ");",
918
+ peg$c284 = peg$literalExpectation(");", false),
919
+ peg$c285 = function peg$c285(factors) {
896
920
  return _.flattenDeep(factors).join("");
897
921
  },
898
- peg$c284 = /^[',.a-z0-9_+-`%]/i,
899
- peg$c285 = peg$classExpectation(["'", ",", ".", ["a", "z"], ["0", "9"], "_", ["+", "`"], "%"], false, true),
900
- peg$c286 = /^['.a-z0-9_+\-]/i,
901
- peg$c287 = peg$classExpectation(["'", ".", ["a", "z"], ["0", "9"], "_", "+", "-"], false, true),
902
- peg$c288 = peg$otherExpectation("letter, number or underscore"),
903
- peg$c289 = /^[a-z0-9_]/i,
904
- peg$c290 = peg$classExpectation([["a", "z"], ["0", "9"], "_"], false, true),
905
- peg$c291 = " ",
906
- peg$c292 = peg$literalExpectation(" ", false),
907
- peg$c293 = "`",
908
- peg$c294 = peg$literalExpectation("`", false),
909
- peg$c295 = "\t",
910
- peg$c296 = peg$literalExpectation("\t", false),
911
- peg$c297 = peg$otherExpectation("endline"),
912
- peg$c298 = peg$otherExpectation("newline"),
913
- peg$c299 = "\r\n",
914
- peg$c300 = peg$literalExpectation("\r\n", false),
915
- peg$c301 = "\n",
916
- peg$c302 = peg$literalExpectation("\n", false),
917
- peg$c303 = peg$otherExpectation("space"),
918
- peg$c304 = peg$otherExpectation("comment"),
919
- peg$c305 = "--",
920
- peg$c306 = peg$literalExpectation("--", false),
921
- peg$c307 = /^[^\n]/,
922
- peg$c308 = peg$classExpectation(["\n"], true, false),
923
- peg$c309 = "/*",
924
- peg$c310 = peg$literalExpectation("/*", false),
925
- peg$c311 = "*/",
926
- peg$c312 = peg$literalExpectation("*/", false),
927
- peg$c313 = peg$otherExpectation("string"),
928
- peg$c314 = function peg$c314(chars) {
922
+ peg$c286 = /^[',.a-z0-9_+-`%]/i,
923
+ peg$c287 = peg$classExpectation(["'", ",", ".", ["a", "z"], ["0", "9"], "_", ["+", "`"], "%"], false, true),
924
+ peg$c288 = /^['.a-z0-9_+\-]/i,
925
+ peg$c289 = peg$classExpectation(["'", ".", ["a", "z"], ["0", "9"], "_", "+", "-"], false, true),
926
+ peg$c290 = peg$otherExpectation("letter, number or underscore"),
927
+ peg$c291 = /^[a-z0-9_]/i,
928
+ peg$c292 = peg$classExpectation([["a", "z"], ["0", "9"], "_"], false, true),
929
+ peg$c293 = " ",
930
+ peg$c294 = peg$literalExpectation(" ", false),
931
+ peg$c295 = "`",
932
+ peg$c296 = peg$literalExpectation("`", false),
933
+ peg$c297 = "\t",
934
+ peg$c298 = peg$literalExpectation("\t", false),
935
+ peg$c299 = peg$otherExpectation("endline"),
936
+ peg$c300 = peg$otherExpectation("newline"),
937
+ peg$c301 = "\r\n",
938
+ peg$c302 = peg$literalExpectation("\r\n", false),
939
+ peg$c303 = "\n",
940
+ peg$c304 = peg$literalExpectation("\n", false),
941
+ peg$c305 = peg$otherExpectation("space"),
942
+ peg$c306 = peg$otherExpectation("comment"),
943
+ peg$c307 = "--",
944
+ peg$c308 = peg$literalExpectation("--", false),
945
+ peg$c309 = /^[^\n]/,
946
+ peg$c310 = peg$classExpectation(["\n"], true, false),
947
+ peg$c311 = "/*",
948
+ peg$c312 = peg$literalExpectation("/*", false),
949
+ peg$c313 = "*/",
950
+ peg$c314 = peg$literalExpectation("*/", false),
951
+ peg$c315 = peg$otherExpectation("string"),
952
+ peg$c316 = function peg$c316(chars) {
929
953
  return chars.join('');
930
954
  },
931
- peg$c315 = "\\",
932
- peg$c316 = peg$literalExpectation("\\", false),
933
- peg$c317 = function peg$c317() {
955
+ peg$c317 = "\\",
956
+ peg$c318 = peg$literalExpectation("\\", false),
957
+ peg$c319 = function peg$c319() {
934
958
  return '"';
935
959
  },
936
- peg$c318 = function peg$c318() {
960
+ peg$c320 = function peg$c320() {
937
961
  return text();
938
962
  },
939
- peg$c319 = function peg$c319() {
963
+ peg$c321 = function peg$c321() {
940
964
  return "'";
941
965
  },
942
- peg$c320 = /^[0-9]/,
943
- peg$c321 = peg$classExpectation([["0", "9"]], false, false),
944
- peg$c322 = function peg$c322(left, right) {
966
+ peg$c322 = /^[0-9]/,
967
+ peg$c323 = peg$classExpectation([["0", "9"]], false, false),
968
+ peg$c324 = function peg$c324(left, right) {
945
969
  return parseFloat(left.join("") + "." + right.join(""));
946
970
  },
947
- peg$c323 = function peg$c323(digits) {
971
+ peg$c325 = function peg$c325(digits) {
948
972
  return parseInt(digits.join(""), 10);
949
973
  },
950
974
  peg$currPos = 0,
@@ -5234,7 +5258,7 @@ function peg$parse(input, options) {
5234
5258
  s2 = peg$parse_();
5235
5259
 
5236
5260
  if (s2 !== peg$FAILED) {
5237
- s3 = peg$parsename();
5261
+ s3 = peg$parsetable_name();
5238
5262
 
5239
5263
  if (s3 !== peg$FAILED) {
5240
5264
  s4 = peg$parse_();
@@ -5788,7 +5812,7 @@ function peg$parse(input, options) {
5788
5812
  s6 = peg$parse_();
5789
5813
 
5790
5814
  if (s6 !== peg$FAILED) {
5791
- s7 = peg$parsename();
5815
+ s7 = peg$parsetable_name();
5792
5816
 
5793
5817
  if (s7 !== peg$FAILED) {
5794
5818
  s8 = peg$parse_();
@@ -8499,9 +8523,8 @@ function peg$parse(input, options) {
8499
8523
  return s0;
8500
8524
  }
8501
8525
 
8502
- function peg$parsetable_name() {
8526
+ function peg$parsepath_name() {
8503
8527
  var s0, s1, s2, s3, s4, s5, s6;
8504
- peg$silentFails++;
8505
8528
  s0 = peg$currPos;
8506
8529
  s1 = [];
8507
8530
  s2 = peg$currPos;
@@ -8512,13 +8535,13 @@ function peg$parse(input, options) {
8512
8535
 
8513
8536
  if (s4 !== peg$FAILED) {
8514
8537
  if (input.charCodeAt(peg$currPos) === 46) {
8515
- s5 = peg$c271;
8538
+ s5 = peg$c270;
8516
8539
  peg$currPos++;
8517
8540
  } else {
8518
8541
  s5 = peg$FAILED;
8519
8542
 
8520
8543
  if (peg$silentFails === 0) {
8521
- peg$fail(peg$c272);
8544
+ peg$fail(peg$c271);
8522
8545
  }
8523
8546
  }
8524
8547
 
@@ -8555,13 +8578,13 @@ function peg$parse(input, options) {
8555
8578
 
8556
8579
  if (s4 !== peg$FAILED) {
8557
8580
  if (input.charCodeAt(peg$currPos) === 46) {
8558
- s5 = peg$c271;
8581
+ s5 = peg$c270;
8559
8582
  peg$currPos++;
8560
8583
  } else {
8561
8584
  s5 = peg$FAILED;
8562
8585
 
8563
8586
  if (peg$silentFails === 0) {
8564
- peg$fail(peg$c272);
8587
+ peg$fail(peg$c271);
8565
8588
  }
8566
8589
  }
8567
8590
 
@@ -8589,12 +8612,27 @@ function peg$parse(input, options) {
8589
8612
  }
8590
8613
  }
8591
8614
 
8615
+ if (s1 !== peg$FAILED) {
8616
+ peg$savedPos = s0;
8617
+ s1 = peg$c272(s1);
8618
+ }
8619
+
8620
+ s0 = s1;
8621
+ return s0;
8622
+ }
8623
+
8624
+ function peg$parsetable_name() {
8625
+ var s0, s1, s2;
8626
+ peg$silentFails++;
8627
+ s0 = peg$currPos;
8628
+ s1 = peg$parsepath_name();
8629
+
8592
8630
  if (s1 !== peg$FAILED) {
8593
8631
  s2 = peg$parsename();
8594
8632
 
8595
8633
  if (s2 !== peg$FAILED) {
8596
8634
  peg$savedPos = s0;
8597
- s1 = peg$c28(s2);
8635
+ s1 = peg$c274(s1, s2);
8598
8636
  s0 = s1;
8599
8637
  } else {
8600
8638
  peg$currPos = s0;
@@ -8611,7 +8649,7 @@ function peg$parse(input, options) {
8611
8649
  s1 = peg$FAILED;
8612
8650
 
8613
8651
  if (peg$silentFails === 0) {
8614
- peg$fail(peg$c270);
8652
+ peg$fail(peg$c273);
8615
8653
  }
8616
8654
  }
8617
8655
 
@@ -8626,7 +8664,7 @@ function peg$parse(input, options) {
8626
8664
 
8627
8665
  if (s1 !== peg$FAILED) {
8628
8666
  peg$savedPos = s0;
8629
- s1 = peg$c274(s1);
8667
+ s1 = peg$c276(s1);
8630
8668
  }
8631
8669
 
8632
8670
  s0 = s1;
@@ -8637,7 +8675,7 @@ function peg$parse(input, options) {
8637
8675
 
8638
8676
  if (s1 !== peg$FAILED) {
8639
8677
  peg$savedPos = s0;
8640
- s1 = peg$c275(s1);
8678
+ s1 = peg$c277(s1);
8641
8679
  }
8642
8680
 
8643
8681
  s0 = s1;
@@ -8649,7 +8687,7 @@ function peg$parse(input, options) {
8649
8687
  s1 = peg$FAILED;
8650
8688
 
8651
8689
  if (peg$silentFails === 0) {
8652
- peg$fail(peg$c273);
8690
+ peg$fail(peg$c275);
8653
8691
  }
8654
8692
  }
8655
8693
 
@@ -8729,7 +8767,7 @@ function peg$parse(input, options) {
8729
8767
 
8730
8768
  if (s3 !== peg$FAILED) {
8731
8769
  peg$savedPos = s0;
8732
- s1 = peg$c276(s1, s3);
8770
+ s1 = peg$c278(s1, s3);
8733
8771
  s0 = s1;
8734
8772
  } else {
8735
8773
  peg$currPos = s0;
@@ -8761,7 +8799,7 @@ function peg$parse(input, options) {
8761
8799
 
8762
8800
  if (s1 !== peg$FAILED) {
8763
8801
  peg$savedPos = s0;
8764
- s1 = peg$c278(s1);
8802
+ s1 = peg$c280(s1);
8765
8803
  }
8766
8804
 
8767
8805
  s0 = s1;
@@ -8771,7 +8809,7 @@ function peg$parse(input, options) {
8771
8809
  s1 = peg$FAILED;
8772
8810
 
8773
8811
  if (peg$silentFails === 0) {
8774
- peg$fail(peg$c277);
8812
+ peg$fail(peg$c279);
8775
8813
  }
8776
8814
  }
8777
8815
 
@@ -8914,25 +8952,25 @@ function peg$parse(input, options) {
8914
8952
 
8915
8953
  if (s4 === peg$FAILED) {
8916
8954
  if (input.charCodeAt(peg$currPos) === 44) {
8917
- s4 = peg$c279;
8955
+ s4 = peg$c281;
8918
8956
  peg$currPos++;
8919
8957
  } else {
8920
8958
  s4 = peg$FAILED;
8921
8959
 
8922
8960
  if (peg$silentFails === 0) {
8923
- peg$fail(peg$c280);
8961
+ peg$fail(peg$c282);
8924
8962
  }
8925
8963
  }
8926
8964
 
8927
8965
  if (s4 === peg$FAILED) {
8928
- if (input.substr(peg$currPos, 2) === peg$c281) {
8929
- s4 = peg$c281;
8966
+ if (input.substr(peg$currPos, 2) === peg$c283) {
8967
+ s4 = peg$c283;
8930
8968
  peg$currPos += 2;
8931
8969
  } else {
8932
8970
  s4 = peg$FAILED;
8933
8971
 
8934
8972
  if (peg$silentFails === 0) {
8935
- peg$fail(peg$c282);
8973
+ peg$fail(peg$c284);
8936
8974
  }
8937
8975
  }
8938
8976
 
@@ -8941,14 +8979,14 @@ function peg$parse(input, options) {
8941
8979
  s5 = peg$parseendline();
8942
8980
 
8943
8981
  if (s5 !== peg$FAILED) {
8944
- if (input.substr(peg$currPos, 2) === peg$c281) {
8945
- s6 = peg$c281;
8982
+ if (input.substr(peg$currPos, 2) === peg$c283) {
8983
+ s6 = peg$c283;
8946
8984
  peg$currPos += 2;
8947
8985
  } else {
8948
8986
  s6 = peg$FAILED;
8949
8987
 
8950
8988
  if (peg$silentFails === 0) {
8951
- peg$fail(peg$c282);
8989
+ peg$fail(peg$c284);
8952
8990
  }
8953
8991
  }
8954
8992
 
@@ -9043,7 +9081,7 @@ function peg$parse(input, options) {
9043
9081
 
9044
9082
  if (s1 !== peg$FAILED) {
9045
9083
  peg$savedPos = s0;
9046
- s1 = peg$c283(s1);
9084
+ s1 = peg$c285(s1);
9047
9085
  }
9048
9086
 
9049
9087
  s0 = s1;
@@ -9053,14 +9091,14 @@ function peg$parse(input, options) {
9053
9091
  function peg$parseexprChar() {
9054
9092
  var s0;
9055
9093
 
9056
- if (peg$c284.test(input.charAt(peg$currPos))) {
9094
+ if (peg$c286.test(input.charAt(peg$currPos))) {
9057
9095
  s0 = input.charAt(peg$currPos);
9058
9096
  peg$currPos++;
9059
9097
  } else {
9060
9098
  s0 = peg$FAILED;
9061
9099
 
9062
9100
  if (peg$silentFails === 0) {
9063
- peg$fail(peg$c285);
9101
+ peg$fail(peg$c287);
9064
9102
  }
9065
9103
  }
9066
9104
 
@@ -9082,14 +9120,14 @@ function peg$parse(input, options) {
9082
9120
  function peg$parseexprCharNoCommaSpace() {
9083
9121
  var s0;
9084
9122
 
9085
- if (peg$c286.test(input.charAt(peg$currPos))) {
9123
+ if (peg$c288.test(input.charAt(peg$currPos))) {
9086
9124
  s0 = input.charAt(peg$currPos);
9087
9125
  peg$currPos++;
9088
9126
  } else {
9089
9127
  s0 = peg$FAILED;
9090
9128
 
9091
9129
  if (peg$silentFails === 0) {
9092
- peg$fail(peg$c287);
9130
+ peg$fail(peg$c289);
9093
9131
  }
9094
9132
  }
9095
9133
 
@@ -9100,14 +9138,14 @@ function peg$parse(input, options) {
9100
9138
  var s0, s1;
9101
9139
  peg$silentFails++;
9102
9140
 
9103
- if (peg$c289.test(input.charAt(peg$currPos))) {
9141
+ if (peg$c291.test(input.charAt(peg$currPos))) {
9104
9142
  s0 = input.charAt(peg$currPos);
9105
9143
  peg$currPos++;
9106
9144
  } else {
9107
9145
  s0 = peg$FAILED;
9108
9146
 
9109
9147
  if (peg$silentFails === 0) {
9110
- peg$fail(peg$c290);
9148
+ peg$fail(peg$c292);
9111
9149
  }
9112
9150
  }
9113
9151
 
@@ -9117,7 +9155,7 @@ function peg$parse(input, options) {
9117
9155
  s1 = peg$FAILED;
9118
9156
 
9119
9157
  if (peg$silentFails === 0) {
9120
- peg$fail(peg$c288);
9158
+ peg$fail(peg$c290);
9121
9159
  }
9122
9160
  }
9123
9161
 
@@ -9128,13 +9166,13 @@ function peg$parse(input, options) {
9128
9166
  var s0;
9129
9167
 
9130
9168
  if (input.charCodeAt(peg$currPos) === 32) {
9131
- s0 = peg$c291;
9169
+ s0 = peg$c293;
9132
9170
  peg$currPos++;
9133
9171
  } else {
9134
9172
  s0 = peg$FAILED;
9135
9173
 
9136
9174
  if (peg$silentFails === 0) {
9137
- peg$fail(peg$c292);
9175
+ peg$fail(peg$c294);
9138
9176
  }
9139
9177
  }
9140
9178
 
@@ -9145,13 +9183,13 @@ function peg$parse(input, options) {
9145
9183
  var s0;
9146
9184
 
9147
9185
  if (input.charCodeAt(peg$currPos) === 96) {
9148
- s0 = peg$c293;
9186
+ s0 = peg$c295;
9149
9187
  peg$currPos++;
9150
9188
  } else {
9151
9189
  s0 = peg$FAILED;
9152
9190
 
9153
9191
  if (peg$silentFails === 0) {
9154
- peg$fail(peg$c294);
9192
+ peg$fail(peg$c296);
9155
9193
  }
9156
9194
  }
9157
9195
 
@@ -9175,13 +9213,13 @@ function peg$parse(input, options) {
9175
9213
  var s0;
9176
9214
 
9177
9215
  if (input.charCodeAt(peg$currPos) === 44) {
9178
- s0 = peg$c279;
9216
+ s0 = peg$c281;
9179
9217
  peg$currPos++;
9180
9218
  } else {
9181
9219
  s0 = peg$FAILED;
9182
9220
 
9183
9221
  if (peg$silentFails === 0) {
9184
- peg$fail(peg$c280);
9222
+ peg$fail(peg$c282);
9185
9223
  }
9186
9224
  }
9187
9225
 
@@ -9192,13 +9230,13 @@ function peg$parse(input, options) {
9192
9230
  var s0;
9193
9231
 
9194
9232
  if (input.charCodeAt(peg$currPos) === 9) {
9195
- s0 = peg$c295;
9233
+ s0 = peg$c297;
9196
9234
  peg$currPos++;
9197
9235
  } else {
9198
9236
  s0 = peg$FAILED;
9199
9237
 
9200
9238
  if (peg$silentFails === 0) {
9201
- peg$fail(peg$c296);
9239
+ peg$fail(peg$c298);
9202
9240
  }
9203
9241
  }
9204
9242
 
@@ -9255,7 +9293,7 @@ function peg$parse(input, options) {
9255
9293
  s1 = peg$FAILED;
9256
9294
 
9257
9295
  if (peg$silentFails === 0) {
9258
- peg$fail(peg$c297);
9296
+ peg$fail(peg$c299);
9259
9297
  }
9260
9298
  }
9261
9299
 
@@ -9266,26 +9304,26 @@ function peg$parse(input, options) {
9266
9304
  var s0, s1;
9267
9305
  peg$silentFails++;
9268
9306
 
9269
- if (input.substr(peg$currPos, 2) === peg$c299) {
9270
- s0 = peg$c299;
9307
+ if (input.substr(peg$currPos, 2) === peg$c301) {
9308
+ s0 = peg$c301;
9271
9309
  peg$currPos += 2;
9272
9310
  } else {
9273
9311
  s0 = peg$FAILED;
9274
9312
 
9275
9313
  if (peg$silentFails === 0) {
9276
- peg$fail(peg$c300);
9314
+ peg$fail(peg$c302);
9277
9315
  }
9278
9316
  }
9279
9317
 
9280
9318
  if (s0 === peg$FAILED) {
9281
9319
  if (input.charCodeAt(peg$currPos) === 10) {
9282
- s0 = peg$c301;
9320
+ s0 = peg$c303;
9283
9321
  peg$currPos++;
9284
9322
  } else {
9285
9323
  s0 = peg$FAILED;
9286
9324
 
9287
9325
  if (peg$silentFails === 0) {
9288
- peg$fail(peg$c302);
9326
+ peg$fail(peg$c304);
9289
9327
  }
9290
9328
  }
9291
9329
  }
@@ -9296,7 +9334,7 @@ function peg$parse(input, options) {
9296
9334
  s1 = peg$FAILED;
9297
9335
 
9298
9336
  if (peg$silentFails === 0) {
9299
- peg$fail(peg$c298);
9337
+ peg$fail(peg$c300);
9300
9338
  }
9301
9339
  }
9302
9340
 
@@ -9344,7 +9382,7 @@ function peg$parse(input, options) {
9344
9382
  s1 = peg$FAILED;
9345
9383
 
9346
9384
  if (peg$silentFails === 0) {
9347
- peg$fail(peg$c303);
9385
+ peg$fail(peg$c305);
9348
9386
  }
9349
9387
  }
9350
9388
 
@@ -9396,7 +9434,7 @@ function peg$parse(input, options) {
9396
9434
  s1 = peg$FAILED;
9397
9435
 
9398
9436
  if (peg$silentFails === 0) {
9399
- peg$fail(peg$c303);
9437
+ peg$fail(peg$c305);
9400
9438
  }
9401
9439
  }
9402
9440
 
@@ -9408,42 +9446,42 @@ function peg$parse(input, options) {
9408
9446
  peg$silentFails++;
9409
9447
  s0 = peg$currPos;
9410
9448
 
9411
- if (input.substr(peg$currPos, 2) === peg$c305) {
9412
- s1 = peg$c305;
9449
+ if (input.substr(peg$currPos, 2) === peg$c307) {
9450
+ s1 = peg$c307;
9413
9451
  peg$currPos += 2;
9414
9452
  } else {
9415
9453
  s1 = peg$FAILED;
9416
9454
 
9417
9455
  if (peg$silentFails === 0) {
9418
- peg$fail(peg$c306);
9456
+ peg$fail(peg$c308);
9419
9457
  }
9420
9458
  }
9421
9459
 
9422
9460
  if (s1 !== peg$FAILED) {
9423
9461
  s2 = [];
9424
9462
 
9425
- if (peg$c307.test(input.charAt(peg$currPos))) {
9463
+ if (peg$c309.test(input.charAt(peg$currPos))) {
9426
9464
  s3 = input.charAt(peg$currPos);
9427
9465
  peg$currPos++;
9428
9466
  } else {
9429
9467
  s3 = peg$FAILED;
9430
9468
 
9431
9469
  if (peg$silentFails === 0) {
9432
- peg$fail(peg$c308);
9470
+ peg$fail(peg$c310);
9433
9471
  }
9434
9472
  }
9435
9473
 
9436
9474
  while (s3 !== peg$FAILED) {
9437
9475
  s2.push(s3);
9438
9476
 
9439
- if (peg$c307.test(input.charAt(peg$currPos))) {
9477
+ if (peg$c309.test(input.charAt(peg$currPos))) {
9440
9478
  s3 = input.charAt(peg$currPos);
9441
9479
  peg$currPos++;
9442
9480
  } else {
9443
9481
  s3 = peg$FAILED;
9444
9482
 
9445
9483
  if (peg$silentFails === 0) {
9446
- peg$fail(peg$c308);
9484
+ peg$fail(peg$c310);
9447
9485
  }
9448
9486
  }
9449
9487
  }
@@ -9463,14 +9501,14 @@ function peg$parse(input, options) {
9463
9501
  if (s0 === peg$FAILED) {
9464
9502
  s0 = peg$currPos;
9465
9503
 
9466
- if (input.substr(peg$currPos, 2) === peg$c309) {
9467
- s1 = peg$c309;
9504
+ if (input.substr(peg$currPos, 2) === peg$c311) {
9505
+ s1 = peg$c311;
9468
9506
  peg$currPos += 2;
9469
9507
  } else {
9470
9508
  s1 = peg$FAILED;
9471
9509
 
9472
9510
  if (peg$silentFails === 0) {
9473
- peg$fail(peg$c310);
9511
+ peg$fail(peg$c312);
9474
9512
  }
9475
9513
  }
9476
9514
 
@@ -9480,14 +9518,14 @@ function peg$parse(input, options) {
9480
9518
  s4 = peg$currPos;
9481
9519
  peg$silentFails++;
9482
9520
 
9483
- if (input.substr(peg$currPos, 2) === peg$c311) {
9484
- s5 = peg$c311;
9521
+ if (input.substr(peg$currPos, 2) === peg$c313) {
9522
+ s5 = peg$c313;
9485
9523
  peg$currPos += 2;
9486
9524
  } else {
9487
9525
  s5 = peg$FAILED;
9488
9526
 
9489
9527
  if (peg$silentFails === 0) {
9490
- peg$fail(peg$c312);
9528
+ peg$fail(peg$c314);
9491
9529
  }
9492
9530
  }
9493
9531
 
@@ -9530,14 +9568,14 @@ function peg$parse(input, options) {
9530
9568
  s4 = peg$currPos;
9531
9569
  peg$silentFails++;
9532
9570
 
9533
- if (input.substr(peg$currPos, 2) === peg$c311) {
9534
- s5 = peg$c311;
9571
+ if (input.substr(peg$currPos, 2) === peg$c313) {
9572
+ s5 = peg$c313;
9535
9573
  peg$currPos += 2;
9536
9574
  } else {
9537
9575
  s5 = peg$FAILED;
9538
9576
 
9539
9577
  if (peg$silentFails === 0) {
9540
- peg$fail(peg$c312);
9578
+ peg$fail(peg$c314);
9541
9579
  }
9542
9580
  }
9543
9581
 
@@ -9576,14 +9614,14 @@ function peg$parse(input, options) {
9576
9614
  }
9577
9615
 
9578
9616
  if (s2 !== peg$FAILED) {
9579
- if (input.substr(peg$currPos, 2) === peg$c311) {
9580
- s3 = peg$c311;
9617
+ if (input.substr(peg$currPos, 2) === peg$c313) {
9618
+ s3 = peg$c313;
9581
9619
  peg$currPos += 2;
9582
9620
  } else {
9583
9621
  s3 = peg$FAILED;
9584
9622
 
9585
9623
  if (peg$silentFails === 0) {
9586
- peg$fail(peg$c312);
9624
+ peg$fail(peg$c314);
9587
9625
  }
9588
9626
  }
9589
9627
 
@@ -9621,7 +9659,7 @@ function peg$parse(input, options) {
9621
9659
  s1 = peg$FAILED;
9622
9660
 
9623
9661
  if (peg$silentFails === 0) {
9624
- peg$fail(peg$c304);
9662
+ peg$fail(peg$c306);
9625
9663
  }
9626
9664
  }
9627
9665
 
@@ -9667,7 +9705,7 @@ function peg$parse(input, options) {
9667
9705
 
9668
9706
  if (s3 !== peg$FAILED) {
9669
9707
  peg$savedPos = s0;
9670
- s1 = peg$c314(s2);
9708
+ s1 = peg$c316(s2);
9671
9709
  s0 = s1;
9672
9710
  } else {
9673
9711
  peg$currPos = s0;
@@ -9719,7 +9757,7 @@ function peg$parse(input, options) {
9719
9757
 
9720
9758
  if (s3 !== peg$FAILED) {
9721
9759
  peg$savedPos = s0;
9722
- s1 = peg$c314(s2);
9760
+ s1 = peg$c316(s2);
9723
9761
  s0 = s1;
9724
9762
  } else {
9725
9763
  peg$currPos = s0;
@@ -9741,7 +9779,7 @@ function peg$parse(input, options) {
9741
9779
  s1 = peg$FAILED;
9742
9780
 
9743
9781
  if (peg$silentFails === 0) {
9744
- peg$fail(peg$c313);
9782
+ peg$fail(peg$c315);
9745
9783
  }
9746
9784
  }
9747
9785
 
@@ -9753,13 +9791,13 @@ function peg$parse(input, options) {
9753
9791
  s0 = peg$currPos;
9754
9792
 
9755
9793
  if (input.charCodeAt(peg$currPos) === 92) {
9756
- s1 = peg$c315;
9794
+ s1 = peg$c317;
9757
9795
  peg$currPos++;
9758
9796
  } else {
9759
9797
  s1 = peg$FAILED;
9760
9798
 
9761
9799
  if (peg$silentFails === 0) {
9762
- peg$fail(peg$c316);
9800
+ peg$fail(peg$c318);
9763
9801
  }
9764
9802
  }
9765
9803
 
@@ -9777,7 +9815,7 @@ function peg$parse(input, options) {
9777
9815
 
9778
9816
  if (s2 !== peg$FAILED) {
9779
9817
  peg$savedPos = s0;
9780
- s1 = peg$c317();
9818
+ s1 = peg$c319();
9781
9819
  s0 = s1;
9782
9820
  } else {
9783
9821
  peg$currPos = s0;
@@ -9818,7 +9856,7 @@ function peg$parse(input, options) {
9818
9856
 
9819
9857
  if (s2 !== peg$FAILED) {
9820
9858
  peg$savedPos = s0;
9821
- s1 = peg$c318();
9859
+ s1 = peg$c320();
9822
9860
  s0 = s1;
9823
9861
  } else {
9824
9862
  peg$currPos = s0;
@@ -9838,13 +9876,13 @@ function peg$parse(input, options) {
9838
9876
  s0 = peg$currPos;
9839
9877
 
9840
9878
  if (input.charCodeAt(peg$currPos) === 92) {
9841
- s1 = peg$c315;
9879
+ s1 = peg$c317;
9842
9880
  peg$currPos++;
9843
9881
  } else {
9844
9882
  s1 = peg$FAILED;
9845
9883
 
9846
9884
  if (peg$silentFails === 0) {
9847
- peg$fail(peg$c316);
9885
+ peg$fail(peg$c318);
9848
9886
  }
9849
9887
  }
9850
9888
 
@@ -9862,7 +9900,7 @@ function peg$parse(input, options) {
9862
9900
 
9863
9901
  if (s2 !== peg$FAILED) {
9864
9902
  peg$savedPos = s0;
9865
- s1 = peg$c319();
9903
+ s1 = peg$c321();
9866
9904
  s0 = s1;
9867
9905
  } else {
9868
9906
  peg$currPos = s0;
@@ -9903,7 +9941,7 @@ function peg$parse(input, options) {
9903
9941
 
9904
9942
  if (s2 !== peg$FAILED) {
9905
9943
  peg$savedPos = s0;
9906
- s1 = peg$c318();
9944
+ s1 = peg$c320();
9907
9945
  s0 = s1;
9908
9946
  } else {
9909
9947
  peg$currPos = s0;
@@ -9951,14 +9989,14 @@ function peg$parse(input, options) {
9951
9989
  s0 = peg$currPos;
9952
9990
  s1 = [];
9953
9991
 
9954
- if (peg$c320.test(input.charAt(peg$currPos))) {
9992
+ if (peg$c322.test(input.charAt(peg$currPos))) {
9955
9993
  s2 = input.charAt(peg$currPos);
9956
9994
  peg$currPos++;
9957
9995
  } else {
9958
9996
  s2 = peg$FAILED;
9959
9997
 
9960
9998
  if (peg$silentFails === 0) {
9961
- peg$fail(peg$c321);
9999
+ peg$fail(peg$c323);
9962
10000
  }
9963
10001
  }
9964
10002
 
@@ -9966,14 +10004,14 @@ function peg$parse(input, options) {
9966
10004
  while (s2 !== peg$FAILED) {
9967
10005
  s1.push(s2);
9968
10006
 
9969
- if (peg$c320.test(input.charAt(peg$currPos))) {
10007
+ if (peg$c322.test(input.charAt(peg$currPos))) {
9970
10008
  s2 = input.charAt(peg$currPos);
9971
10009
  peg$currPos++;
9972
10010
  } else {
9973
10011
  s2 = peg$FAILED;
9974
10012
 
9975
10013
  if (peg$silentFails === 0) {
9976
- peg$fail(peg$c321);
10014
+ peg$fail(peg$c323);
9977
10015
  }
9978
10016
  }
9979
10017
  }
@@ -9983,27 +10021,27 @@ function peg$parse(input, options) {
9983
10021
 
9984
10022
  if (s1 !== peg$FAILED) {
9985
10023
  if (input.charCodeAt(peg$currPos) === 46) {
9986
- s2 = peg$c271;
10024
+ s2 = peg$c270;
9987
10025
  peg$currPos++;
9988
10026
  } else {
9989
10027
  s2 = peg$FAILED;
9990
10028
 
9991
10029
  if (peg$silentFails === 0) {
9992
- peg$fail(peg$c272);
10030
+ peg$fail(peg$c271);
9993
10031
  }
9994
10032
  }
9995
10033
 
9996
10034
  if (s2 !== peg$FAILED) {
9997
10035
  s3 = [];
9998
10036
 
9999
- if (peg$c320.test(input.charAt(peg$currPos))) {
10037
+ if (peg$c322.test(input.charAt(peg$currPos))) {
10000
10038
  s4 = input.charAt(peg$currPos);
10001
10039
  peg$currPos++;
10002
10040
  } else {
10003
10041
  s4 = peg$FAILED;
10004
10042
 
10005
10043
  if (peg$silentFails === 0) {
10006
- peg$fail(peg$c321);
10044
+ peg$fail(peg$c323);
10007
10045
  }
10008
10046
  }
10009
10047
 
@@ -10011,14 +10049,14 @@ function peg$parse(input, options) {
10011
10049
  while (s4 !== peg$FAILED) {
10012
10050
  s3.push(s4);
10013
10051
 
10014
- if (peg$c320.test(input.charAt(peg$currPos))) {
10052
+ if (peg$c322.test(input.charAt(peg$currPos))) {
10015
10053
  s4 = input.charAt(peg$currPos);
10016
10054
  peg$currPos++;
10017
10055
  } else {
10018
10056
  s4 = peg$FAILED;
10019
10057
 
10020
10058
  if (peg$silentFails === 0) {
10021
- peg$fail(peg$c321);
10059
+ peg$fail(peg$c323);
10022
10060
  }
10023
10061
  }
10024
10062
  }
@@ -10028,7 +10066,7 @@ function peg$parse(input, options) {
10028
10066
 
10029
10067
  if (s3 !== peg$FAILED) {
10030
10068
  peg$savedPos = s0;
10031
- s1 = peg$c322(s1, s3);
10069
+ s1 = peg$c324(s1, s3);
10032
10070
  s0 = s1;
10033
10071
  } else {
10034
10072
  peg$currPos = s0;
@@ -10051,14 +10089,14 @@ function peg$parse(input, options) {
10051
10089
  s0 = peg$currPos;
10052
10090
  s1 = [];
10053
10091
 
10054
- if (peg$c320.test(input.charAt(peg$currPos))) {
10092
+ if (peg$c322.test(input.charAt(peg$currPos))) {
10055
10093
  s2 = input.charAt(peg$currPos);
10056
10094
  peg$currPos++;
10057
10095
  } else {
10058
10096
  s2 = peg$FAILED;
10059
10097
 
10060
10098
  if (peg$silentFails === 0) {
10061
- peg$fail(peg$c321);
10099
+ peg$fail(peg$c323);
10062
10100
  }
10063
10101
  }
10064
10102
 
@@ -10066,14 +10104,14 @@ function peg$parse(input, options) {
10066
10104
  while (s2 !== peg$FAILED) {
10067
10105
  s1.push(s2);
10068
10106
 
10069
- if (peg$c320.test(input.charAt(peg$currPos))) {
10107
+ if (peg$c322.test(input.charAt(peg$currPos))) {
10070
10108
  s2 = input.charAt(peg$currPos);
10071
10109
  peg$currPos++;
10072
10110
  } else {
10073
10111
  s2 = peg$FAILED;
10074
10112
 
10075
10113
  if (peg$silentFails === 0) {
10076
- peg$fail(peg$c321);
10114
+ peg$fail(peg$c323);
10077
10115
  }
10078
10116
  }
10079
10117
  }
@@ -10083,7 +10121,7 @@ function peg$parse(input, options) {
10083
10121
 
10084
10122
  if (s1 !== peg$FAILED) {
10085
10123
  peg$savedPos = s0;
10086
- s1 = peg$c323(s1);
10124
+ s1 = peg$c325(s1);
10087
10125
  }
10088
10126
 
10089
10127
  s0 = s1;
@@ -10094,7 +10132,16 @@ function peg$parse(input, options) {
10094
10132
 
10095
10133
  var tables = [];
10096
10134
  var refs = [];
10097
- var enums = []; // intput:
10135
+ var enums = []; // TODO: support configurable default schema name other than 'public'
10136
+
10137
+ var findTable = function findTable(schemaName, tableName) {
10138
+ var realSchemaName = schemaName || 'public';
10139
+ var table = tables.find(function (table) {
10140
+ var targetSchemaName = table.schemaName || 'public';
10141
+ return targetSchemaName === realSchemaName && table.name === tableName;
10142
+ });
10143
+ return table;
10144
+ }; // intput:
10098
10145
  // `
10099
10146
  // 'created'
10100
10147
  // ,
@@ -10102,6 +10149,7 @@ function peg$parse(input, options) {
10102
10149
  // `
10103
10150
  // => `'created', 'pending', 'done'`
10104
10151
 
10152
+
10105
10153
  var removeReduntdantSpNewline = function removeReduntdantSpNewline(str) {
10106
10154
  var arr = str.split(/[\s\r\n]*,[\s\r\n]*/); // need to trim spaces and newlines of the first and last element
10107
10155