@dbml/core 3.14.1 → 4.0.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 (30) hide show
  1. package/lib/export/DbmlExporter.js +38 -1
  2. package/lib/export/MysqlExporter.js +36 -1
  3. package/lib/export/OracleExporter.js +36 -1
  4. package/lib/export/PostgresExporter.js +36 -1
  5. package/lib/export/SqlServerExporter.js +36 -1
  6. package/lib/index.js +1 -1
  7. package/lib/model_structure/constraint.js +86 -0
  8. package/lib/model_structure/database.js +1 -0
  9. package/lib/model_structure/dbState.js +1 -0
  10. package/lib/model_structure/field.js +23 -1
  11. package/lib/model_structure/table.js +51 -17
  12. package/lib/model_structure/tablePartial.js +3 -0
  13. package/lib/parse/ANTLR/ASTGeneration/AST.js +18 -6
  14. package/lib/parse/ANTLR/ASTGeneration/constants.js +2 -1
  15. package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +53 -101
  16. package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +73 -19
  17. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +50 -16
  18. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +1 -1
  19. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +1 -1
  20. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +2 -2
  21. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +1314 -1314
  22. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +1 -1
  23. package/lib/parse/schemarb/parser.pegjs +41 -0
  24. package/lib/parse/schemarbParser.js +568 -226
  25. package/package.json +3 -3
  26. package/types/model_structure/constraint.d.ts +52 -0
  27. package/types/model_structure/database.d.ts +2 -0
  28. package/types/model_structure/field.d.ts +7 -1
  29. package/types/model_structure/table.d.ts +8 -1
  30. package/types/model_structure/tablePartial.d.ts +4 -1
@@ -127,23 +127,30 @@ function peg$parse(input, options) {
127
127
  },
128
128
  peg$c3 = ",",
129
129
  peg$c4 = peg$literalExpectation(",", false),
130
- peg$c5 = function peg$c5(fromTable, toTable, props) {
130
+ peg$c5 = function peg$c5(tableName, expression, props) {
131
+ var _props$find;
132
+ var constraintName = (_props$find = props.find(function (p) {
133
+ return p.name;
134
+ })) === null || _props$find === void 0 ? void 0 : _props$find.name;
135
+ addCheckConstraintToTable(tableName, expression, constraintName);
136
+ },
137
+ peg$c6 = function peg$c6(fromTable, toTable, props) {
131
138
  var foreign = refactorForeign(createForeign(fromTable, toTable, props));
132
139
  return foreign;
133
140
  },
134
- peg$c6 = ":",
135
- peg$c7 = peg$literalExpectation(":", false),
136
- peg$c8 = function peg$c8(columnName) {
141
+ peg$c7 = ":",
142
+ peg$c8 = peg$literalExpectation(":", false),
143
+ peg$c9 = function peg$c9(columnName) {
137
144
  return {
138
145
  columnName: columnName
139
146
  };
140
147
  },
141
- peg$c9 = function peg$c9(primaryKey) {
148
+ peg$c10 = function peg$c10(primaryKey) {
142
149
  return {
143
150
  primaryKey: primaryKey
144
151
  };
145
152
  },
146
- peg$c10 = function peg$c10(r, value) {
153
+ peg$c11 = function peg$c11(r, value) {
147
154
  switch (r.toLowerCase()) {
148
155
  case 'on_delete':
149
156
  return {
@@ -155,18 +162,21 @@ function peg$parse(input, options) {
155
162
  };
156
163
  }
157
164
  },
158
- peg$c11 = function peg$c11(name, body) {
165
+ peg$c12 = function peg$c12(name, body) {
159
166
  var table = {
160
167
  name: name,
161
168
  fields: addPrimaryKey(body.fields)
162
169
  // index: _.union(...body.index)
163
170
  };
171
+ if (body.constraints && body.constraints.length > 0) {
172
+ table.constraints = body.constraints;
173
+ }
164
174
  return {
165
175
  table: table,
166
176
  refs: createRefFromTableWithReference(table, body.references)
167
177
  };
168
178
  },
169
- peg$c12 = function peg$c12(fields) {
179
+ peg$c13 = function peg$c13(fields) {
170
180
  return {
171
181
  fields: fields.filter(function (field) {
172
182
  return field.isField;
@@ -182,28 +192,50 @@ function peg$parse(input, options) {
182
192
  return field.isReferences;
183
193
  }).map(function (field) {
184
194
  return field.reference;
195
+ }),
196
+ constraints: fields.filter(function (field) {
197
+ return field.isConstraint;
198
+ }).map(function (field) {
199
+ return field.constraint;
185
200
  })
186
201
  };
187
202
  },
188
- peg$c13 = function peg$c13(field) {
203
+ peg$c14 = function peg$c14(field) {
189
204
  return field;
190
205
  },
191
- peg$c14 = function peg$c14(reference) {
206
+ peg$c15 = function peg$c15(reference) {
192
207
  return {
193
208
  reference: reference,
194
209
  isReferences: true
195
210
  };
196
211
  },
197
- peg$c15 = function peg$c15(field) {
212
+ peg$c16 = function peg$c16(constraint) {
213
+ return {
214
+ constraint: constraint,
215
+ isConstraint: true
216
+ };
217
+ },
218
+ peg$c17 = function peg$c17(field) {
198
219
  return {
199
220
  field: field,
200
221
  isField: true
201
222
  };
202
223
  },
203
- peg$c16 = function peg$c16(reference) {
224
+ peg$c18 = function peg$c18(reference) {
204
225
  return reference;
205
226
  },
206
- peg$c17 = function peg$c17(type, name) {
227
+ peg$c19 = function peg$c19(expression, props) {
228
+ var constraint = {
229
+ expression: expression
230
+ };
231
+ for (var i = 0; i < props.length; i++) {
232
+ if (props[i].name) {
233
+ constraint.name = props[i].name;
234
+ }
235
+ }
236
+ return constraint;
237
+ },
238
+ peg$c20 = function peg$c20(type, name) {
207
239
  return {
208
240
  name: name,
209
241
  type: {
@@ -211,94 +243,107 @@ function peg$parse(input, options) {
211
243
  }
212
244
  };
213
245
  },
214
- peg$c18 = function peg$c18(reference) {
246
+ peg$c21 = function peg$c21(reference) {
215
247
  return reference;
216
248
  },
217
- peg$c19 = "on_delete",
218
- peg$c20 = peg$literalExpectation("on_delete", true),
219
- peg$c21 = "on_update",
220
- peg$c22 = peg$literalExpectation("on_update", true),
221
- peg$c23 = peg$otherExpectation("add index"),
222
- peg$c24 = "add_index",
223
- peg$c25 = peg$literalExpectation("add_index", false),
224
- peg$c26 = peg$otherExpectation("schema define"),
225
- peg$c27 = "ActiveRecord::Schema.define",
226
- peg$c28 = peg$literalExpectation("ActiveRecord::Schema.define", false),
227
- peg$c29 = peg$otherExpectation("create table"),
228
- peg$c30 = "create_table",
229
- peg$c31 = peg$literalExpectation("create_table", true),
230
- peg$c32 = peg$otherExpectation("do |t|"),
231
- peg$c33 = peg$otherExpectation("index"),
232
- peg$c34 = ".index",
233
- peg$c35 = peg$literalExpectation(".index", false),
234
- peg$c36 = peg$otherExpectation("references"),
235
- peg$c37 = ".references",
236
- peg$c38 = peg$literalExpectation(".references", false),
237
- peg$c39 = peg$otherExpectation("add foreign key"),
238
- peg$c40 = "add_foreign_key",
239
- peg$c41 = peg$literalExpectation("add_foreign_key", true),
240
- peg$c42 = peg$otherExpectation("column"),
241
- peg$c43 = "column",
242
- peg$c44 = peg$literalExpectation("column", false),
243
- peg$c45 = peg$otherExpectation("primary key"),
244
- peg$c46 = "primary_key",
245
- peg$c47 = peg$literalExpectation("primary_key", false),
246
- peg$c48 = "version",
247
- peg$c49 = peg$literalExpectation("version", false),
248
- peg$c50 = "do",
249
- peg$c51 = peg$literalExpectation("do", false),
250
- peg$c52 = "end",
251
- peg$c53 = peg$literalExpectation("end", false),
252
- peg$c54 = peg$otherExpectation("lambda function"),
253
- peg$c55 = "=>",
254
- peg$c56 = peg$literalExpectation("=>", false),
255
- peg$c57 = "->",
256
- peg$c58 = peg$literalExpectation("->", false),
257
- peg$c59 = /^[^"\n]/,
258
- peg$c60 = peg$classExpectation(["\"", "\n"], true, false),
259
- peg$c61 = function peg$c61(c) {
249
+ peg$c22 = "name",
250
+ peg$c23 = peg$literalExpectation("name", true),
251
+ peg$c24 = function peg$c24(constraintName) {
252
+ return {
253
+ name: constraintName
254
+ };
255
+ },
256
+ peg$c25 = "on_delete",
257
+ peg$c26 = peg$literalExpectation("on_delete", true),
258
+ peg$c27 = "on_update",
259
+ peg$c28 = peg$literalExpectation("on_update", true),
260
+ peg$c29 = peg$otherExpectation("add index"),
261
+ peg$c30 = "add_index",
262
+ peg$c31 = peg$literalExpectation("add_index", false),
263
+ peg$c32 = peg$otherExpectation("schema define"),
264
+ peg$c33 = "ActiveRecord::Schema.define",
265
+ peg$c34 = peg$literalExpectation("ActiveRecord::Schema.define", false),
266
+ peg$c35 = peg$otherExpectation("create table"),
267
+ peg$c36 = "create_table",
268
+ peg$c37 = peg$literalExpectation("create_table", true),
269
+ peg$c38 = peg$otherExpectation("do |t|"),
270
+ peg$c39 = peg$otherExpectation("index"),
271
+ peg$c40 = ".index",
272
+ peg$c41 = peg$literalExpectation(".index", false),
273
+ peg$c42 = peg$otherExpectation("references"),
274
+ peg$c43 = ".references",
275
+ peg$c44 = peg$literalExpectation(".references", false),
276
+ peg$c45 = peg$otherExpectation("check constraint"),
277
+ peg$c46 = ".check_constraint",
278
+ peg$c47 = peg$literalExpectation(".check_constraint", false),
279
+ peg$c48 = peg$otherExpectation("add check constraint"),
280
+ peg$c49 = "add_check_constraint",
281
+ peg$c50 = peg$literalExpectation("add_check_constraint", true),
282
+ peg$c51 = peg$otherExpectation("add foreign key"),
283
+ peg$c52 = "add_foreign_key",
284
+ peg$c53 = peg$literalExpectation("add_foreign_key", true),
285
+ peg$c54 = peg$otherExpectation("column"),
286
+ peg$c55 = "column",
287
+ peg$c56 = peg$literalExpectation("column", false),
288
+ peg$c57 = peg$otherExpectation("primary key"),
289
+ peg$c58 = "primary_key",
290
+ peg$c59 = peg$literalExpectation("primary_key", false),
291
+ peg$c60 = "version",
292
+ peg$c61 = peg$literalExpectation("version", false),
293
+ peg$c62 = "do",
294
+ peg$c63 = peg$literalExpectation("do", false),
295
+ peg$c64 = "end",
296
+ peg$c65 = peg$literalExpectation("end", false),
297
+ peg$c66 = peg$otherExpectation("lambda function"),
298
+ peg$c67 = "=>",
299
+ peg$c68 = peg$literalExpectation("=>", false),
300
+ peg$c69 = "->",
301
+ peg$c70 = peg$literalExpectation("->", false),
302
+ peg$c71 = /^[^"\n]/,
303
+ peg$c72 = peg$classExpectation(["\"", "\n"], true, false),
304
+ peg$c73 = function peg$c73(c) {
260
305
  return c.join("");
261
306
  },
262
- peg$c62 = /^[^'\n]/,
263
- peg$c63 = peg$classExpectation(["'", "\n"], true, false),
264
- peg$c64 = ".",
265
- peg$c65 = peg$literalExpectation(".", false),
266
- peg$c66 = peg$anyExpectation(),
267
- peg$c67 = function peg$c67() {
307
+ peg$c74 = /^[^'\n]/,
308
+ peg$c75 = peg$classExpectation(["'", "\n"], true, false),
309
+ peg$c76 = ".",
310
+ peg$c77 = peg$literalExpectation(".", false),
311
+ peg$c78 = peg$anyExpectation(),
312
+ peg$c79 = function peg$c79() {
268
313
  return text();
269
314
  },
270
- peg$c68 = /^[0-9]/i,
271
- peg$c69 = peg$classExpectation([["0", "9"]], false, true),
272
- peg$c70 = peg$otherExpectation("letter, number or underscore"),
273
- peg$c71 = /^[a-z0-9_.]/i,
274
- peg$c72 = peg$classExpectation([["a", "z"], ["0", "9"], "_", "."], false, true),
275
- peg$c73 = peg$otherExpectation("comment line"),
276
- peg$c74 = "#",
277
- peg$c75 = peg$literalExpectation("#", false),
278
- peg$c76 = peg$otherExpectation("whatever"),
279
- peg$c77 = /^[^\t\r\n]/,
280
- peg$c78 = peg$classExpectation(["\t", "\r", "\n"], true, false),
281
- peg$c79 = "'",
282
- peg$c80 = peg$literalExpectation("'", false),
283
- peg$c81 = "\"",
284
- peg$c82 = peg$literalExpectation("\"", false),
285
- peg$c83 = "|",
286
- peg$c84 = peg$literalExpectation("|", false),
287
- peg$c85 = peg$otherExpectation("comment"),
288
- peg$c86 = "//",
289
- peg$c87 = peg$literalExpectation("//", false),
290
- peg$c88 = /^[^\n]/,
291
- peg$c89 = peg$classExpectation(["\n"], true, false),
292
- peg$c90 = peg$otherExpectation("newline"),
293
- peg$c91 = "\r\n",
294
- peg$c92 = peg$literalExpectation("\r\n", false),
295
- peg$c93 = "\n",
296
- peg$c94 = peg$literalExpectation("\n", false),
297
- peg$c95 = peg$otherExpectation("whitespace"),
298
- peg$c96 = /^[ \t\r\n\r]/,
299
- peg$c97 = peg$classExpectation([" ", "\t", "\r", "\n", "\r"], false, false),
300
- peg$c98 = " ",
301
- peg$c99 = peg$literalExpectation(" ", false),
315
+ peg$c80 = /^[0-9]/i,
316
+ peg$c81 = peg$classExpectation([["0", "9"]], false, true),
317
+ peg$c82 = peg$otherExpectation("letter, number or underscore"),
318
+ peg$c83 = /^[a-z0-9_.]/i,
319
+ peg$c84 = peg$classExpectation([["a", "z"], ["0", "9"], "_", "."], false, true),
320
+ peg$c85 = peg$otherExpectation("comment line"),
321
+ peg$c86 = "#",
322
+ peg$c87 = peg$literalExpectation("#", false),
323
+ peg$c88 = peg$otherExpectation("whatever"),
324
+ peg$c89 = /^[^\t\r\n]/,
325
+ peg$c90 = peg$classExpectation(["\t", "\r", "\n"], true, false),
326
+ peg$c91 = "'",
327
+ peg$c92 = peg$literalExpectation("'", false),
328
+ peg$c93 = "\"",
329
+ peg$c94 = peg$literalExpectation("\"", false),
330
+ peg$c95 = "|",
331
+ peg$c96 = peg$literalExpectation("|", false),
332
+ peg$c97 = peg$otherExpectation("comment"),
333
+ peg$c98 = "//",
334
+ peg$c99 = peg$literalExpectation("//", false),
335
+ peg$c100 = /^[^\n]/,
336
+ peg$c101 = peg$classExpectation(["\n"], true, false),
337
+ peg$c102 = peg$otherExpectation("newline"),
338
+ peg$c103 = "\r\n",
339
+ peg$c104 = peg$literalExpectation("\r\n", false),
340
+ peg$c105 = "\n",
341
+ peg$c106 = peg$literalExpectation("\n", false),
342
+ peg$c107 = peg$otherExpectation("whitespace"),
343
+ peg$c108 = /^[ \t\r\n\r]/,
344
+ peg$c109 = peg$classExpectation([" ", "\t", "\r", "\n", "\r"], false, false),
345
+ peg$c110 = " ",
346
+ peg$c111 = peg$literalExpectation(" ", false),
302
347
  peg$currPos = 0,
303
348
  peg$savedPos = 0,
304
349
  peg$posDetailsCache = [{
@@ -487,11 +532,101 @@ function peg$parse(input, options) {
487
532
  }
488
533
  s0 = s1;
489
534
  if (s0 === peg$FAILED) {
490
- s0 = peg$parseother_class_prop();
535
+ s0 = peg$parseadd_check_constraint_syntax();
536
+ if (s0 === peg$FAILED) {
537
+ s0 = peg$parseother_class_prop();
538
+ }
491
539
  }
492
540
  }
493
541
  return s0;
494
542
  }
543
+ function peg$parseadd_check_constraint_syntax() {
544
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
545
+ s0 = peg$currPos;
546
+ s1 = [];
547
+ s2 = peg$parsesp();
548
+ while (s2 !== peg$FAILED) {
549
+ s1.push(s2);
550
+ s2 = peg$parsesp();
551
+ }
552
+ if (s1 !== peg$FAILED) {
553
+ s2 = peg$parseadd_check_constraint();
554
+ if (s2 !== peg$FAILED) {
555
+ s3 = [];
556
+ s4 = peg$parsesp();
557
+ while (s4 !== peg$FAILED) {
558
+ s3.push(s4);
559
+ s4 = peg$parsesp();
560
+ }
561
+ if (s3 !== peg$FAILED) {
562
+ s4 = peg$parsesymbol();
563
+ if (s4 === peg$FAILED) {
564
+ s4 = peg$parsename();
565
+ }
566
+ if (s4 !== peg$FAILED) {
567
+ if (input.charCodeAt(peg$currPos) === 44) {
568
+ s5 = peg$c3;
569
+ peg$currPos++;
570
+ } else {
571
+ s5 = peg$FAILED;
572
+ if (peg$silentFails === 0) {
573
+ peg$fail(peg$c4);
574
+ }
575
+ }
576
+ if (s5 !== peg$FAILED) {
577
+ s6 = [];
578
+ s7 = peg$parsesp();
579
+ while (s7 !== peg$FAILED) {
580
+ s6.push(s7);
581
+ s7 = peg$parsesp();
582
+ }
583
+ if (s6 !== peg$FAILED) {
584
+ s7 = peg$parsename();
585
+ if (s7 !== peg$FAILED) {
586
+ s8 = [];
587
+ s9 = peg$parsecheck_constraint_props();
588
+ while (s9 !== peg$FAILED) {
589
+ s8.push(s9);
590
+ s9 = peg$parsecheck_constraint_props();
591
+ }
592
+ if (s8 !== peg$FAILED) {
593
+ peg$savedPos = s0;
594
+ s1 = peg$c5(s4, s7, s8);
595
+ s0 = s1;
596
+ } else {
597
+ peg$currPos = s0;
598
+ s0 = peg$FAILED;
599
+ }
600
+ } else {
601
+ peg$currPos = s0;
602
+ s0 = peg$FAILED;
603
+ }
604
+ } else {
605
+ peg$currPos = s0;
606
+ s0 = peg$FAILED;
607
+ }
608
+ } else {
609
+ peg$currPos = s0;
610
+ s0 = peg$FAILED;
611
+ }
612
+ } else {
613
+ peg$currPos = s0;
614
+ s0 = peg$FAILED;
615
+ }
616
+ } else {
617
+ peg$currPos = s0;
618
+ s0 = peg$FAILED;
619
+ }
620
+ } else {
621
+ peg$currPos = s0;
622
+ s0 = peg$FAILED;
623
+ }
624
+ } else {
625
+ peg$currPos = s0;
626
+ s0 = peg$FAILED;
627
+ }
628
+ return s0;
629
+ }
495
630
  function peg$parseadd_foreign_key_syntax() {
496
631
  var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
497
632
  s0 = peg$currPos;
@@ -540,7 +675,7 @@ function peg$parse(input, options) {
540
675
  }
541
676
  if (s8 !== peg$FAILED) {
542
677
  peg$savedPos = s0;
543
- s1 = peg$c5(s4, s7, s8);
678
+ s1 = peg$c6(s4, s7, s8);
544
679
  s0 = s1;
545
680
  } else {
546
681
  peg$currPos = s0;
@@ -599,12 +734,12 @@ function peg$parse(input, options) {
599
734
  s3 = peg$parsecolumn();
600
735
  if (s3 !== peg$FAILED) {
601
736
  if (input.charCodeAt(peg$currPos) === 58) {
602
- s4 = peg$c6;
737
+ s4 = peg$c7;
603
738
  peg$currPos++;
604
739
  } else {
605
740
  s4 = peg$FAILED;
606
741
  if (peg$silentFails === 0) {
607
- peg$fail(peg$c7);
742
+ peg$fail(peg$c8);
608
743
  }
609
744
  }
610
745
  if (s4 !== peg$FAILED) {
@@ -618,7 +753,7 @@ function peg$parse(input, options) {
618
753
  s6 = peg$parsename();
619
754
  if (s6 !== peg$FAILED) {
620
755
  peg$savedPos = s0;
621
- s1 = peg$c8(s6);
756
+ s1 = peg$c9(s6);
622
757
  s0 = s1;
623
758
  } else {
624
759
  peg$currPos = s0;
@@ -666,12 +801,12 @@ function peg$parse(input, options) {
666
801
  s3 = peg$parseprimary_key();
667
802
  if (s3 !== peg$FAILED) {
668
803
  if (input.charCodeAt(peg$currPos) === 58) {
669
- s4 = peg$c6;
804
+ s4 = peg$c7;
670
805
  peg$currPos++;
671
806
  } else {
672
807
  s4 = peg$FAILED;
673
808
  if (peg$silentFails === 0) {
674
- peg$fail(peg$c7);
809
+ peg$fail(peg$c8);
675
810
  }
676
811
  }
677
812
  if (s4 !== peg$FAILED) {
@@ -685,7 +820,7 @@ function peg$parse(input, options) {
685
820
  s6 = peg$parsename();
686
821
  if (s6 !== peg$FAILED) {
687
822
  peg$savedPos = s0;
688
- s1 = peg$c9(s6);
823
+ s1 = peg$c10(s6);
689
824
  s0 = s1;
690
825
  } else {
691
826
  peg$currPos = s0;
@@ -733,12 +868,12 @@ function peg$parse(input, options) {
733
868
  s3 = peg$parsereferential_actions();
734
869
  if (s3 !== peg$FAILED) {
735
870
  if (input.charCodeAt(peg$currPos) === 58) {
736
- s4 = peg$c6;
871
+ s4 = peg$c7;
737
872
  peg$currPos++;
738
873
  } else {
739
874
  s4 = peg$FAILED;
740
875
  if (peg$silentFails === 0) {
741
- peg$fail(peg$c7);
876
+ peg$fail(peg$c8);
742
877
  }
743
878
  }
744
879
  if (s4 !== peg$FAILED) {
@@ -752,7 +887,7 @@ function peg$parse(input, options) {
752
887
  s6 = peg$parsesymbol();
753
888
  if (s6 !== peg$FAILED) {
754
889
  peg$savedPos = s0;
755
- s1 = peg$c10(s3, s6);
890
+ s1 = peg$c11(s3, s6);
756
891
  s0 = s1;
757
892
  } else {
758
893
  peg$currPos = s0;
@@ -805,7 +940,7 @@ function peg$parse(input, options) {
805
940
  s7 = peg$parseend_line();
806
941
  if (s7 !== peg$FAILED) {
807
942
  peg$savedPos = s0;
808
- s1 = peg$c11(s3, s6);
943
+ s1 = peg$c12(s3, s6);
809
944
  s0 = s1;
810
945
  } else {
811
946
  peg$currPos = s0;
@@ -848,7 +983,7 @@ function peg$parse(input, options) {
848
983
  }
849
984
  if (s1 !== peg$FAILED) {
850
985
  peg$savedPos = s0;
851
- s1 = peg$c12(s1);
986
+ s1 = peg$c13(s1);
852
987
  }
853
988
  s0 = s1;
854
989
  return s0;
@@ -875,7 +1010,7 @@ function peg$parse(input, options) {
875
1010
  s4 = peg$parseendline();
876
1011
  if (s4 !== peg$FAILED) {
877
1012
  peg$savedPos = s0;
878
- s1 = peg$c13(s2);
1013
+ s1 = peg$c14(s2);
879
1014
  s0 = s1;
880
1015
  } else {
881
1016
  peg$currPos = s0;
@@ -903,17 +1038,26 @@ function peg$parse(input, options) {
903
1038
  s1 = peg$parsefield_reference_syntax();
904
1039
  if (s1 !== peg$FAILED) {
905
1040
  peg$savedPos = s0;
906
- s1 = peg$c14(s1);
1041
+ s1 = peg$c15(s1);
907
1042
  }
908
1043
  s0 = s1;
909
1044
  if (s0 === peg$FAILED) {
910
1045
  s0 = peg$currPos;
911
- s1 = peg$parsefield_type_syntax();
1046
+ s1 = peg$parsefield_check_constraint_syntax();
912
1047
  if (s1 !== peg$FAILED) {
913
1048
  peg$savedPos = s0;
914
- s1 = peg$c15(s1);
1049
+ s1 = peg$c16(s1);
915
1050
  }
916
1051
  s0 = s1;
1052
+ if (s0 === peg$FAILED) {
1053
+ s0 = peg$currPos;
1054
+ s1 = peg$parsefield_type_syntax();
1055
+ if (s1 !== peg$FAILED) {
1056
+ peg$savedPos = s0;
1057
+ s1 = peg$c17(s1);
1058
+ }
1059
+ s0 = s1;
1060
+ }
917
1061
  }
918
1062
  }
919
1063
  return s0;
@@ -971,7 +1115,7 @@ function peg$parse(input, options) {
971
1115
  s3 = peg$parsereference_value();
972
1116
  if (s3 !== peg$FAILED) {
973
1117
  peg$savedPos = s0;
974
- s1 = peg$c16(s3);
1118
+ s1 = peg$c18(s3);
975
1119
  s0 = s1;
976
1120
  } else {
977
1121
  peg$currPos = s0;
@@ -987,6 +1131,52 @@ function peg$parse(input, options) {
987
1131
  }
988
1132
  return s0;
989
1133
  }
1134
+ function peg$parsefield_check_constraint_syntax() {
1135
+ var s0, s1, s2, s3, s4, s5;
1136
+ s0 = peg$currPos;
1137
+ s1 = peg$parsecheck_constraint();
1138
+ if (s1 !== peg$FAILED) {
1139
+ s2 = [];
1140
+ s3 = peg$parsesp();
1141
+ if (s3 !== peg$FAILED) {
1142
+ while (s3 !== peg$FAILED) {
1143
+ s2.push(s3);
1144
+ s3 = peg$parsesp();
1145
+ }
1146
+ } else {
1147
+ s2 = peg$FAILED;
1148
+ }
1149
+ if (s2 !== peg$FAILED) {
1150
+ s3 = peg$parsename();
1151
+ if (s3 !== peg$FAILED) {
1152
+ s4 = [];
1153
+ s5 = peg$parsecheck_constraint_props();
1154
+ while (s5 !== peg$FAILED) {
1155
+ s4.push(s5);
1156
+ s5 = peg$parsecheck_constraint_props();
1157
+ }
1158
+ if (s4 !== peg$FAILED) {
1159
+ peg$savedPos = s0;
1160
+ s1 = peg$c19(s3, s4);
1161
+ s0 = s1;
1162
+ } else {
1163
+ peg$currPos = s0;
1164
+ s0 = peg$FAILED;
1165
+ }
1166
+ } else {
1167
+ peg$currPos = s0;
1168
+ s0 = peg$FAILED;
1169
+ }
1170
+ } else {
1171
+ peg$currPos = s0;
1172
+ s0 = peg$FAILED;
1173
+ }
1174
+ } else {
1175
+ peg$currPos = s0;
1176
+ s0 = peg$FAILED;
1177
+ }
1178
+ return s0;
1179
+ }
990
1180
  function peg$parsefield_type_syntax() {
991
1181
  var s0, s1, s2, s3;
992
1182
  s0 = peg$currPos;
@@ -1006,7 +1196,7 @@ function peg$parse(input, options) {
1006
1196
  s3 = peg$parsename();
1007
1197
  if (s3 !== peg$FAILED) {
1008
1198
  peg$savedPos = s0;
1009
- s1 = peg$c17(s1, s3);
1199
+ s1 = peg$c20(s1, s3);
1010
1200
  s0 = s1;
1011
1201
  } else {
1012
1202
  peg$currPos = s0;
@@ -1026,19 +1216,19 @@ function peg$parse(input, options) {
1026
1216
  var s0, s1, s2;
1027
1217
  s0 = peg$currPos;
1028
1218
  if (input.charCodeAt(peg$currPos) === 58) {
1029
- s1 = peg$c6;
1219
+ s1 = peg$c7;
1030
1220
  peg$currPos++;
1031
1221
  } else {
1032
1222
  s1 = peg$FAILED;
1033
1223
  if (peg$silentFails === 0) {
1034
- peg$fail(peg$c7);
1224
+ peg$fail(peg$c8);
1035
1225
  }
1036
1226
  }
1037
1227
  if (s1 !== peg$FAILED) {
1038
1228
  s2 = peg$parsevariable();
1039
1229
  if (s2 !== peg$FAILED) {
1040
1230
  peg$savedPos = s0;
1041
- s1 = peg$c18(s2);
1231
+ s1 = peg$c21(s2);
1042
1232
  s0 = s1;
1043
1233
  } else {
1044
1234
  peg$currPos = s0;
@@ -1053,31 +1243,109 @@ function peg$parse(input, options) {
1053
1243
  s1 = peg$parsename();
1054
1244
  if (s1 !== peg$FAILED) {
1055
1245
  peg$savedPos = s0;
1056
- s1 = peg$c18(s1);
1246
+ s1 = peg$c21(s1);
1057
1247
  }
1058
1248
  s0 = s1;
1059
1249
  }
1060
1250
  return s0;
1061
1251
  }
1252
+ function peg$parsecheck_constraint_props() {
1253
+ var s0, s1, s2, s3, s4, s5, s6;
1254
+ s0 = peg$currPos;
1255
+ if (input.charCodeAt(peg$currPos) === 44) {
1256
+ s1 = peg$c3;
1257
+ peg$currPos++;
1258
+ } else {
1259
+ s1 = peg$FAILED;
1260
+ if (peg$silentFails === 0) {
1261
+ peg$fail(peg$c4);
1262
+ }
1263
+ }
1264
+ if (s1 !== peg$FAILED) {
1265
+ s2 = [];
1266
+ s3 = peg$parsesp();
1267
+ while (s3 !== peg$FAILED) {
1268
+ s2.push(s3);
1269
+ s3 = peg$parsesp();
1270
+ }
1271
+ if (s2 !== peg$FAILED) {
1272
+ if (input.substr(peg$currPos, 4).toLowerCase() === peg$c22) {
1273
+ s3 = input.substr(peg$currPos, 4);
1274
+ peg$currPos += 4;
1275
+ } else {
1276
+ s3 = peg$FAILED;
1277
+ if (peg$silentFails === 0) {
1278
+ peg$fail(peg$c23);
1279
+ }
1280
+ }
1281
+ if (s3 !== peg$FAILED) {
1282
+ if (input.charCodeAt(peg$currPos) === 58) {
1283
+ s4 = peg$c7;
1284
+ peg$currPos++;
1285
+ } else {
1286
+ s4 = peg$FAILED;
1287
+ if (peg$silentFails === 0) {
1288
+ peg$fail(peg$c8);
1289
+ }
1290
+ }
1291
+ if (s4 !== peg$FAILED) {
1292
+ s5 = [];
1293
+ s6 = peg$parsesp();
1294
+ while (s6 !== peg$FAILED) {
1295
+ s5.push(s6);
1296
+ s6 = peg$parsesp();
1297
+ }
1298
+ if (s5 !== peg$FAILED) {
1299
+ s6 = peg$parsename();
1300
+ if (s6 !== peg$FAILED) {
1301
+ peg$savedPos = s0;
1302
+ s1 = peg$c24(s6);
1303
+ s0 = s1;
1304
+ } else {
1305
+ peg$currPos = s0;
1306
+ s0 = peg$FAILED;
1307
+ }
1308
+ } else {
1309
+ peg$currPos = s0;
1310
+ s0 = peg$FAILED;
1311
+ }
1312
+ } else {
1313
+ peg$currPos = s0;
1314
+ s0 = peg$FAILED;
1315
+ }
1316
+ } else {
1317
+ peg$currPos = s0;
1318
+ s0 = peg$FAILED;
1319
+ }
1320
+ } else {
1321
+ peg$currPos = s0;
1322
+ s0 = peg$FAILED;
1323
+ }
1324
+ } else {
1325
+ peg$currPos = s0;
1326
+ s0 = peg$FAILED;
1327
+ }
1328
+ return s0;
1329
+ }
1062
1330
  function peg$parsereferential_actions() {
1063
1331
  var s0;
1064
- if (input.substr(peg$currPos, 9).toLowerCase() === peg$c19) {
1332
+ if (input.substr(peg$currPos, 9).toLowerCase() === peg$c25) {
1065
1333
  s0 = input.substr(peg$currPos, 9);
1066
1334
  peg$currPos += 9;
1067
1335
  } else {
1068
1336
  s0 = peg$FAILED;
1069
1337
  if (peg$silentFails === 0) {
1070
- peg$fail(peg$c20);
1338
+ peg$fail(peg$c26);
1071
1339
  }
1072
1340
  }
1073
1341
  if (s0 === peg$FAILED) {
1074
- if (input.substr(peg$currPos, 9).toLowerCase() === peg$c21) {
1342
+ if (input.substr(peg$currPos, 9).toLowerCase() === peg$c27) {
1075
1343
  s0 = input.substr(peg$currPos, 9);
1076
1344
  peg$currPos += 9;
1077
1345
  } else {
1078
1346
  s0 = peg$FAILED;
1079
1347
  if (peg$silentFails === 0) {
1080
- peg$fail(peg$c22);
1348
+ peg$fail(peg$c28);
1081
1349
  }
1082
1350
  }
1083
1351
  }
@@ -1086,20 +1354,20 @@ function peg$parse(input, options) {
1086
1354
  function peg$parseadd_index() {
1087
1355
  var s0, s1;
1088
1356
  peg$silentFails++;
1089
- if (input.substr(peg$currPos, 9) === peg$c24) {
1090
- s0 = peg$c24;
1357
+ if (input.substr(peg$currPos, 9) === peg$c30) {
1358
+ s0 = peg$c30;
1091
1359
  peg$currPos += 9;
1092
1360
  } else {
1093
1361
  s0 = peg$FAILED;
1094
1362
  if (peg$silentFails === 0) {
1095
- peg$fail(peg$c25);
1363
+ peg$fail(peg$c31);
1096
1364
  }
1097
1365
  }
1098
1366
  peg$silentFails--;
1099
1367
  if (s0 === peg$FAILED) {
1100
1368
  s1 = peg$FAILED;
1101
1369
  if (peg$silentFails === 0) {
1102
- peg$fail(peg$c23);
1370
+ peg$fail(peg$c29);
1103
1371
  }
1104
1372
  }
1105
1373
  return s0;
@@ -1107,20 +1375,20 @@ function peg$parse(input, options) {
1107
1375
  function peg$parseschema_define() {
1108
1376
  var s0, s1;
1109
1377
  peg$silentFails++;
1110
- if (input.substr(peg$currPos, 27) === peg$c27) {
1111
- s0 = peg$c27;
1378
+ if (input.substr(peg$currPos, 27) === peg$c33) {
1379
+ s0 = peg$c33;
1112
1380
  peg$currPos += 27;
1113
1381
  } else {
1114
1382
  s0 = peg$FAILED;
1115
1383
  if (peg$silentFails === 0) {
1116
- peg$fail(peg$c28);
1384
+ peg$fail(peg$c34);
1117
1385
  }
1118
1386
  }
1119
1387
  peg$silentFails--;
1120
1388
  if (s0 === peg$FAILED) {
1121
1389
  s1 = peg$FAILED;
1122
1390
  if (peg$silentFails === 0) {
1123
- peg$fail(peg$c26);
1391
+ peg$fail(peg$c32);
1124
1392
  }
1125
1393
  }
1126
1394
  return s0;
@@ -1128,20 +1396,20 @@ function peg$parse(input, options) {
1128
1396
  function peg$parsecreate_table() {
1129
1397
  var s0, s1;
1130
1398
  peg$silentFails++;
1131
- if (input.substr(peg$currPos, 12).toLowerCase() === peg$c30) {
1399
+ if (input.substr(peg$currPos, 12).toLowerCase() === peg$c36) {
1132
1400
  s0 = input.substr(peg$currPos, 12);
1133
1401
  peg$currPos += 12;
1134
1402
  } else {
1135
1403
  s0 = peg$FAILED;
1136
1404
  if (peg$silentFails === 0) {
1137
- peg$fail(peg$c31);
1405
+ peg$fail(peg$c37);
1138
1406
  }
1139
1407
  }
1140
1408
  peg$silentFails--;
1141
1409
  if (s0 === peg$FAILED) {
1142
1410
  s1 = peg$FAILED;
1143
1411
  if (peg$silentFails === 0) {
1144
- peg$fail(peg$c29);
1412
+ peg$fail(peg$c35);
1145
1413
  }
1146
1414
  }
1147
1415
  return s0;
@@ -1201,7 +1469,7 @@ function peg$parse(input, options) {
1201
1469
  if (s0 === peg$FAILED) {
1202
1470
  s1 = peg$FAILED;
1203
1471
  if (peg$silentFails === 0) {
1204
- peg$fail(peg$c32);
1472
+ peg$fail(peg$c38);
1205
1473
  }
1206
1474
  }
1207
1475
  return s0;
@@ -1212,13 +1480,13 @@ function peg$parse(input, options) {
1212
1480
  s0 = peg$currPos;
1213
1481
  s1 = peg$parsecharacter();
1214
1482
  if (s1 !== peg$FAILED) {
1215
- if (input.substr(peg$currPos, 6) === peg$c34) {
1216
- s2 = peg$c34;
1483
+ if (input.substr(peg$currPos, 6) === peg$c40) {
1484
+ s2 = peg$c40;
1217
1485
  peg$currPos += 6;
1218
1486
  } else {
1219
1487
  s2 = peg$FAILED;
1220
1488
  if (peg$silentFails === 0) {
1221
- peg$fail(peg$c35);
1489
+ peg$fail(peg$c41);
1222
1490
  }
1223
1491
  }
1224
1492
  if (s2 !== peg$FAILED) {
@@ -1236,7 +1504,7 @@ function peg$parse(input, options) {
1236
1504
  if (s0 === peg$FAILED) {
1237
1505
  s1 = peg$FAILED;
1238
1506
  if (peg$silentFails === 0) {
1239
- peg$fail(peg$c33);
1507
+ peg$fail(peg$c39);
1240
1508
  }
1241
1509
  }
1242
1510
  return s0;
@@ -1247,13 +1515,48 @@ function peg$parse(input, options) {
1247
1515
  s0 = peg$currPos;
1248
1516
  s1 = peg$parsecharacter();
1249
1517
  if (s1 !== peg$FAILED) {
1250
- if (input.substr(peg$currPos, 11) === peg$c37) {
1251
- s2 = peg$c37;
1518
+ if (input.substr(peg$currPos, 11) === peg$c43) {
1519
+ s2 = peg$c43;
1252
1520
  peg$currPos += 11;
1253
1521
  } else {
1254
1522
  s2 = peg$FAILED;
1255
1523
  if (peg$silentFails === 0) {
1256
- peg$fail(peg$c38);
1524
+ peg$fail(peg$c44);
1525
+ }
1526
+ }
1527
+ if (s2 !== peg$FAILED) {
1528
+ s1 = [s1, s2];
1529
+ s0 = s1;
1530
+ } else {
1531
+ peg$currPos = s0;
1532
+ s0 = peg$FAILED;
1533
+ }
1534
+ } else {
1535
+ peg$currPos = s0;
1536
+ s0 = peg$FAILED;
1537
+ }
1538
+ peg$silentFails--;
1539
+ if (s0 === peg$FAILED) {
1540
+ s1 = peg$FAILED;
1541
+ if (peg$silentFails === 0) {
1542
+ peg$fail(peg$c42);
1543
+ }
1544
+ }
1545
+ return s0;
1546
+ }
1547
+ function peg$parsecheck_constraint() {
1548
+ var s0, s1, s2;
1549
+ peg$silentFails++;
1550
+ s0 = peg$currPos;
1551
+ s1 = peg$parsecharacter();
1552
+ if (s1 !== peg$FAILED) {
1553
+ if (input.substr(peg$currPos, 17) === peg$c46) {
1554
+ s2 = peg$c46;
1555
+ peg$currPos += 17;
1556
+ } else {
1557
+ s2 = peg$FAILED;
1558
+ if (peg$silentFails === 0) {
1559
+ peg$fail(peg$c47);
1257
1560
  }
1258
1561
  }
1259
1562
  if (s2 !== peg$FAILED) {
@@ -1271,7 +1574,28 @@ function peg$parse(input, options) {
1271
1574
  if (s0 === peg$FAILED) {
1272
1575
  s1 = peg$FAILED;
1273
1576
  if (peg$silentFails === 0) {
1274
- peg$fail(peg$c36);
1577
+ peg$fail(peg$c45);
1578
+ }
1579
+ }
1580
+ return s0;
1581
+ }
1582
+ function peg$parseadd_check_constraint() {
1583
+ var s0, s1;
1584
+ peg$silentFails++;
1585
+ if (input.substr(peg$currPos, 20).toLowerCase() === peg$c49) {
1586
+ s0 = input.substr(peg$currPos, 20);
1587
+ peg$currPos += 20;
1588
+ } else {
1589
+ s0 = peg$FAILED;
1590
+ if (peg$silentFails === 0) {
1591
+ peg$fail(peg$c50);
1592
+ }
1593
+ }
1594
+ peg$silentFails--;
1595
+ if (s0 === peg$FAILED) {
1596
+ s1 = peg$FAILED;
1597
+ if (peg$silentFails === 0) {
1598
+ peg$fail(peg$c48);
1275
1599
  }
1276
1600
  }
1277
1601
  return s0;
@@ -1279,20 +1603,20 @@ function peg$parse(input, options) {
1279
1603
  function peg$parseadd_foreign_key() {
1280
1604
  var s0, s1;
1281
1605
  peg$silentFails++;
1282
- if (input.substr(peg$currPos, 15).toLowerCase() === peg$c40) {
1606
+ if (input.substr(peg$currPos, 15).toLowerCase() === peg$c52) {
1283
1607
  s0 = input.substr(peg$currPos, 15);
1284
1608
  peg$currPos += 15;
1285
1609
  } else {
1286
1610
  s0 = peg$FAILED;
1287
1611
  if (peg$silentFails === 0) {
1288
- peg$fail(peg$c41);
1612
+ peg$fail(peg$c53);
1289
1613
  }
1290
1614
  }
1291
1615
  peg$silentFails--;
1292
1616
  if (s0 === peg$FAILED) {
1293
1617
  s1 = peg$FAILED;
1294
1618
  if (peg$silentFails === 0) {
1295
- peg$fail(peg$c39);
1619
+ peg$fail(peg$c51);
1296
1620
  }
1297
1621
  }
1298
1622
  return s0;
@@ -1300,20 +1624,20 @@ function peg$parse(input, options) {
1300
1624
  function peg$parsecolumn() {
1301
1625
  var s0, s1;
1302
1626
  peg$silentFails++;
1303
- if (input.substr(peg$currPos, 6) === peg$c43) {
1304
- s0 = peg$c43;
1627
+ if (input.substr(peg$currPos, 6) === peg$c55) {
1628
+ s0 = peg$c55;
1305
1629
  peg$currPos += 6;
1306
1630
  } else {
1307
1631
  s0 = peg$FAILED;
1308
1632
  if (peg$silentFails === 0) {
1309
- peg$fail(peg$c44);
1633
+ peg$fail(peg$c56);
1310
1634
  }
1311
1635
  }
1312
1636
  peg$silentFails--;
1313
1637
  if (s0 === peg$FAILED) {
1314
1638
  s1 = peg$FAILED;
1315
1639
  if (peg$silentFails === 0) {
1316
- peg$fail(peg$c42);
1640
+ peg$fail(peg$c54);
1317
1641
  }
1318
1642
  }
1319
1643
  return s0;
@@ -1321,59 +1645,59 @@ function peg$parse(input, options) {
1321
1645
  function peg$parseprimary_key() {
1322
1646
  var s0, s1;
1323
1647
  peg$silentFails++;
1324
- if (input.substr(peg$currPos, 11) === peg$c46) {
1325
- s0 = peg$c46;
1648
+ if (input.substr(peg$currPos, 11) === peg$c58) {
1649
+ s0 = peg$c58;
1326
1650
  peg$currPos += 11;
1327
1651
  } else {
1328
1652
  s0 = peg$FAILED;
1329
1653
  if (peg$silentFails === 0) {
1330
- peg$fail(peg$c47);
1654
+ peg$fail(peg$c59);
1331
1655
  }
1332
1656
  }
1333
1657
  peg$silentFails--;
1334
1658
  if (s0 === peg$FAILED) {
1335
1659
  s1 = peg$FAILED;
1336
1660
  if (peg$silentFails === 0) {
1337
- peg$fail(peg$c45);
1661
+ peg$fail(peg$c57);
1338
1662
  }
1339
1663
  }
1340
1664
  return s0;
1341
1665
  }
1342
1666
  function peg$parseversion() {
1343
1667
  var s0;
1344
- if (input.substr(peg$currPos, 7) === peg$c48) {
1345
- s0 = peg$c48;
1668
+ if (input.substr(peg$currPos, 7) === peg$c60) {
1669
+ s0 = peg$c60;
1346
1670
  peg$currPos += 7;
1347
1671
  } else {
1348
1672
  s0 = peg$FAILED;
1349
1673
  if (peg$silentFails === 0) {
1350
- peg$fail(peg$c49);
1674
+ peg$fail(peg$c61);
1351
1675
  }
1352
1676
  }
1353
1677
  return s0;
1354
1678
  }
1355
1679
  function peg$parsedo() {
1356
1680
  var s0;
1357
- if (input.substr(peg$currPos, 2) === peg$c50) {
1358
- s0 = peg$c50;
1681
+ if (input.substr(peg$currPos, 2) === peg$c62) {
1682
+ s0 = peg$c62;
1359
1683
  peg$currPos += 2;
1360
1684
  } else {
1361
1685
  s0 = peg$FAILED;
1362
1686
  if (peg$silentFails === 0) {
1363
- peg$fail(peg$c51);
1687
+ peg$fail(peg$c63);
1364
1688
  }
1365
1689
  }
1366
1690
  return s0;
1367
1691
  }
1368
1692
  function peg$parseend() {
1369
1693
  var s0;
1370
- if (input.substr(peg$currPos, 3) === peg$c52) {
1371
- s0 = peg$c52;
1694
+ if (input.substr(peg$currPos, 3) === peg$c64) {
1695
+ s0 = peg$c64;
1372
1696
  peg$currPos += 3;
1373
1697
  } else {
1374
1698
  s0 = peg$FAILED;
1375
1699
  if (peg$silentFails === 0) {
1376
- peg$fail(peg$c53);
1700
+ peg$fail(peg$c65);
1377
1701
  }
1378
1702
  }
1379
1703
  return s0;
@@ -1381,23 +1705,23 @@ function peg$parse(input, options) {
1381
1705
  function peg$parselambda_function() {
1382
1706
  var s0, s1;
1383
1707
  peg$silentFails++;
1384
- if (input.substr(peg$currPos, 2) === peg$c55) {
1385
- s0 = peg$c55;
1708
+ if (input.substr(peg$currPos, 2) === peg$c67) {
1709
+ s0 = peg$c67;
1386
1710
  peg$currPos += 2;
1387
1711
  } else {
1388
1712
  s0 = peg$FAILED;
1389
1713
  if (peg$silentFails === 0) {
1390
- peg$fail(peg$c56);
1714
+ peg$fail(peg$c68);
1391
1715
  }
1392
1716
  }
1393
1717
  if (s0 === peg$FAILED) {
1394
- if (input.substr(peg$currPos, 2) === peg$c57) {
1395
- s0 = peg$c57;
1718
+ if (input.substr(peg$currPos, 2) === peg$c69) {
1719
+ s0 = peg$c69;
1396
1720
  peg$currPos += 2;
1397
1721
  } else {
1398
1722
  s0 = peg$FAILED;
1399
1723
  if (peg$silentFails === 0) {
1400
- peg$fail(peg$c58);
1724
+ peg$fail(peg$c70);
1401
1725
  }
1402
1726
  }
1403
1727
  }
@@ -1405,7 +1729,7 @@ function peg$parse(input, options) {
1405
1729
  if (s0 === peg$FAILED) {
1406
1730
  s1 = peg$FAILED;
1407
1731
  if (peg$silentFails === 0) {
1408
- peg$fail(peg$c54);
1732
+ peg$fail(peg$c66);
1409
1733
  }
1410
1734
  }
1411
1735
  return s0;
@@ -1452,24 +1776,24 @@ function peg$parse(input, options) {
1452
1776
  s1 = peg$parsedouble_quote();
1453
1777
  if (s1 !== peg$FAILED) {
1454
1778
  s2 = [];
1455
- if (peg$c59.test(input.charAt(peg$currPos))) {
1779
+ if (peg$c71.test(input.charAt(peg$currPos))) {
1456
1780
  s3 = input.charAt(peg$currPos);
1457
1781
  peg$currPos++;
1458
1782
  } else {
1459
1783
  s3 = peg$FAILED;
1460
1784
  if (peg$silentFails === 0) {
1461
- peg$fail(peg$c60);
1785
+ peg$fail(peg$c72);
1462
1786
  }
1463
1787
  }
1464
1788
  while (s3 !== peg$FAILED) {
1465
1789
  s2.push(s3);
1466
- if (peg$c59.test(input.charAt(peg$currPos))) {
1790
+ if (peg$c71.test(input.charAt(peg$currPos))) {
1467
1791
  s3 = input.charAt(peg$currPos);
1468
1792
  peg$currPos++;
1469
1793
  } else {
1470
1794
  s3 = peg$FAILED;
1471
1795
  if (peg$silentFails === 0) {
1472
- peg$fail(peg$c60);
1796
+ peg$fail(peg$c72);
1473
1797
  }
1474
1798
  }
1475
1799
  }
@@ -1477,7 +1801,7 @@ function peg$parse(input, options) {
1477
1801
  s3 = peg$parsedouble_quote();
1478
1802
  if (s3 !== peg$FAILED) {
1479
1803
  peg$savedPos = s0;
1480
- s1 = peg$c61(s2);
1804
+ s1 = peg$c73(s2);
1481
1805
  s0 = s1;
1482
1806
  } else {
1483
1807
  peg$currPos = s0;
@@ -1499,24 +1823,24 @@ function peg$parse(input, options) {
1499
1823
  s1 = peg$parsesingle_quote();
1500
1824
  if (s1 !== peg$FAILED) {
1501
1825
  s2 = [];
1502
- if (peg$c62.test(input.charAt(peg$currPos))) {
1826
+ if (peg$c74.test(input.charAt(peg$currPos))) {
1503
1827
  s3 = input.charAt(peg$currPos);
1504
1828
  peg$currPos++;
1505
1829
  } else {
1506
1830
  s3 = peg$FAILED;
1507
1831
  if (peg$silentFails === 0) {
1508
- peg$fail(peg$c63);
1832
+ peg$fail(peg$c75);
1509
1833
  }
1510
1834
  }
1511
1835
  while (s3 !== peg$FAILED) {
1512
1836
  s2.push(s3);
1513
- if (peg$c62.test(input.charAt(peg$currPos))) {
1837
+ if (peg$c74.test(input.charAt(peg$currPos))) {
1514
1838
  s3 = input.charAt(peg$currPos);
1515
1839
  peg$currPos++;
1516
1840
  } else {
1517
1841
  s3 = peg$FAILED;
1518
1842
  if (peg$silentFails === 0) {
1519
- peg$fail(peg$c63);
1843
+ peg$fail(peg$c75);
1520
1844
  }
1521
1845
  }
1522
1846
  }
@@ -1524,7 +1848,7 @@ function peg$parse(input, options) {
1524
1848
  s3 = peg$parsesingle_quote();
1525
1849
  if (s3 !== peg$FAILED) {
1526
1850
  peg$savedPos = s0;
1527
- s1 = peg$c61(s2);
1851
+ s1 = peg$c73(s2);
1528
1852
  s0 = s1;
1529
1853
  } else {
1530
1854
  peg$currPos = s0;
@@ -1544,12 +1868,12 @@ function peg$parse(input, options) {
1544
1868
  var s0, s1, s2, s3;
1545
1869
  s0 = peg$currPos;
1546
1870
  if (input.charCodeAt(peg$currPos) === 58) {
1547
- s1 = peg$c6;
1871
+ s1 = peg$c7;
1548
1872
  peg$currPos++;
1549
1873
  } else {
1550
1874
  s1 = peg$FAILED;
1551
1875
  if (peg$silentFails === 0) {
1552
- peg$fail(peg$c7);
1876
+ peg$fail(peg$c8);
1553
1877
  }
1554
1878
  }
1555
1879
  if (s1 !== peg$FAILED) {
@@ -1561,7 +1885,7 @@ function peg$parse(input, options) {
1561
1885
  }
1562
1886
  if (s2 !== peg$FAILED) {
1563
1887
  peg$savedPos = s0;
1564
- s1 = peg$c61(s2);
1888
+ s1 = peg$c73(s2);
1565
1889
  s0 = s1;
1566
1890
  } else {
1567
1891
  peg$currPos = s0;
@@ -1588,7 +1912,7 @@ function peg$parse(input, options) {
1588
1912
  }
1589
1913
  if (s1 !== peg$FAILED) {
1590
1914
  peg$savedPos = s0;
1591
- s1 = peg$c61(s1);
1915
+ s1 = peg$c73(s1);
1592
1916
  }
1593
1917
  s0 = s1;
1594
1918
  return s0;
@@ -1599,12 +1923,12 @@ function peg$parse(input, options) {
1599
1923
  s1 = peg$parsecharacter();
1600
1924
  if (s1 !== peg$FAILED) {
1601
1925
  if (input.charCodeAt(peg$currPos) === 46) {
1602
- s2 = peg$c64;
1926
+ s2 = peg$c76;
1603
1927
  peg$currPos++;
1604
1928
  } else {
1605
1929
  s2 = peg$FAILED;
1606
1930
  if (peg$silentFails === 0) {
1607
- peg$fail(peg$c65);
1931
+ peg$fail(peg$c77);
1608
1932
  }
1609
1933
  }
1610
1934
  if (s2 !== peg$FAILED) {
@@ -1620,7 +1944,7 @@ function peg$parse(input, options) {
1620
1944
  }
1621
1945
  if (s3 !== peg$FAILED) {
1622
1946
  peg$savedPos = s0;
1623
- s1 = peg$c61(s3);
1947
+ s1 = peg$c73(s3);
1624
1948
  s0 = s1;
1625
1949
  } else {
1626
1950
  peg$currPos = s0;
@@ -1656,12 +1980,12 @@ function peg$parse(input, options) {
1656
1980
  } else {
1657
1981
  s2 = peg$FAILED;
1658
1982
  if (peg$silentFails === 0) {
1659
- peg$fail(peg$c66);
1983
+ peg$fail(peg$c78);
1660
1984
  }
1661
1985
  }
1662
1986
  if (s2 !== peg$FAILED) {
1663
1987
  peg$savedPos = s0;
1664
- s1 = peg$c67();
1988
+ s1 = peg$c79();
1665
1989
  s0 = s1;
1666
1990
  } else {
1667
1991
  peg$currPos = s0;
@@ -1675,13 +1999,13 @@ function peg$parse(input, options) {
1675
1999
  }
1676
2000
  function peg$parsenumber() {
1677
2001
  var s0;
1678
- if (peg$c68.test(input.charAt(peg$currPos))) {
2002
+ if (peg$c80.test(input.charAt(peg$currPos))) {
1679
2003
  s0 = input.charAt(peg$currPos);
1680
2004
  peg$currPos++;
1681
2005
  } else {
1682
2006
  s0 = peg$FAILED;
1683
2007
  if (peg$silentFails === 0) {
1684
- peg$fail(peg$c69);
2008
+ peg$fail(peg$c81);
1685
2009
  }
1686
2010
  }
1687
2011
  return s0;
@@ -1689,20 +2013,20 @@ function peg$parse(input, options) {
1689
2013
  function peg$parsecharacter() {
1690
2014
  var s0, s1;
1691
2015
  peg$silentFails++;
1692
- if (peg$c71.test(input.charAt(peg$currPos))) {
2016
+ if (peg$c83.test(input.charAt(peg$currPos))) {
1693
2017
  s0 = input.charAt(peg$currPos);
1694
2018
  peg$currPos++;
1695
2019
  } else {
1696
2020
  s0 = peg$FAILED;
1697
2021
  if (peg$silentFails === 0) {
1698
- peg$fail(peg$c72);
2022
+ peg$fail(peg$c84);
1699
2023
  }
1700
2024
  }
1701
2025
  peg$silentFails--;
1702
2026
  if (s0 === peg$FAILED) {
1703
2027
  s1 = peg$FAILED;
1704
2028
  if (peg$silentFails === 0) {
1705
- peg$fail(peg$c70);
2029
+ peg$fail(peg$c82);
1706
2030
  }
1707
2031
  }
1708
2032
  return s0;
@@ -1808,12 +2132,12 @@ function peg$parse(input, options) {
1808
2132
  }
1809
2133
  if (s1 !== peg$FAILED) {
1810
2134
  if (input.charCodeAt(peg$currPos) === 35) {
1811
- s2 = peg$c74;
2135
+ s2 = peg$c86;
1812
2136
  peg$currPos++;
1813
2137
  } else {
1814
2138
  s2 = peg$FAILED;
1815
2139
  if (peg$silentFails === 0) {
1816
- peg$fail(peg$c75);
2140
+ peg$fail(peg$c87);
1817
2141
  }
1818
2142
  }
1819
2143
  if (s2 !== peg$FAILED) {
@@ -1846,7 +2170,7 @@ function peg$parse(input, options) {
1846
2170
  if (s0 === peg$FAILED) {
1847
2171
  s1 = peg$FAILED;
1848
2172
  if (peg$silentFails === 0) {
1849
- peg$fail(peg$c73);
2173
+ peg$fail(peg$c85);
1850
2174
  }
1851
2175
  }
1852
2176
  return s0;
@@ -1855,24 +2179,24 @@ function peg$parse(input, options) {
1855
2179
  var s0, s1;
1856
2180
  peg$silentFails++;
1857
2181
  s0 = [];
1858
- if (peg$c77.test(input.charAt(peg$currPos))) {
2182
+ if (peg$c89.test(input.charAt(peg$currPos))) {
1859
2183
  s1 = input.charAt(peg$currPos);
1860
2184
  peg$currPos++;
1861
2185
  } else {
1862
2186
  s1 = peg$FAILED;
1863
2187
  if (peg$silentFails === 0) {
1864
- peg$fail(peg$c78);
2188
+ peg$fail(peg$c90);
1865
2189
  }
1866
2190
  }
1867
2191
  while (s1 !== peg$FAILED) {
1868
2192
  s0.push(s1);
1869
- if (peg$c77.test(input.charAt(peg$currPos))) {
2193
+ if (peg$c89.test(input.charAt(peg$currPos))) {
1870
2194
  s1 = input.charAt(peg$currPos);
1871
2195
  peg$currPos++;
1872
2196
  } else {
1873
2197
  s1 = peg$FAILED;
1874
2198
  if (peg$silentFails === 0) {
1875
- peg$fail(peg$c78);
2199
+ peg$fail(peg$c90);
1876
2200
  }
1877
2201
  }
1878
2202
  }
@@ -1880,20 +2204,20 @@ function peg$parse(input, options) {
1880
2204
  if (s0 === peg$FAILED) {
1881
2205
  s1 = peg$FAILED;
1882
2206
  if (peg$silentFails === 0) {
1883
- peg$fail(peg$c76);
2207
+ peg$fail(peg$c88);
1884
2208
  }
1885
2209
  }
1886
2210
  return s0;
1887
2211
  }
1888
2212
  function peg$parsewhatever() {
1889
2213
  var s0;
1890
- if (peg$c77.test(input.charAt(peg$currPos))) {
2214
+ if (peg$c89.test(input.charAt(peg$currPos))) {
1891
2215
  s0 = input.charAt(peg$currPos);
1892
2216
  peg$currPos++;
1893
2217
  } else {
1894
2218
  s0 = peg$FAILED;
1895
2219
  if (peg$silentFails === 0) {
1896
- peg$fail(peg$c78);
2220
+ peg$fail(peg$c90);
1897
2221
  }
1898
2222
  }
1899
2223
  return s0;
@@ -1901,12 +2225,12 @@ function peg$parse(input, options) {
1901
2225
  function peg$parsesingle_quote() {
1902
2226
  var s0;
1903
2227
  if (input.charCodeAt(peg$currPos) === 39) {
1904
- s0 = peg$c79;
2228
+ s0 = peg$c91;
1905
2229
  peg$currPos++;
1906
2230
  } else {
1907
2231
  s0 = peg$FAILED;
1908
2232
  if (peg$silentFails === 0) {
1909
- peg$fail(peg$c80);
2233
+ peg$fail(peg$c92);
1910
2234
  }
1911
2235
  }
1912
2236
  return s0;
@@ -1914,12 +2238,12 @@ function peg$parse(input, options) {
1914
2238
  function peg$parsedouble_quote() {
1915
2239
  var s0;
1916
2240
  if (input.charCodeAt(peg$currPos) === 34) {
1917
- s0 = peg$c81;
2241
+ s0 = peg$c93;
1918
2242
  peg$currPos++;
1919
2243
  } else {
1920
2244
  s0 = peg$FAILED;
1921
2245
  if (peg$silentFails === 0) {
1922
- peg$fail(peg$c82);
2246
+ peg$fail(peg$c94);
1923
2247
  }
1924
2248
  }
1925
2249
  return s0;
@@ -1963,12 +2287,12 @@ function peg$parse(input, options) {
1963
2287
  function peg$parseabs() {
1964
2288
  var s0;
1965
2289
  if (input.charCodeAt(peg$currPos) === 124) {
1966
- s0 = peg$c83;
2290
+ s0 = peg$c95;
1967
2291
  peg$currPos++;
1968
2292
  } else {
1969
2293
  s0 = peg$FAILED;
1970
2294
  if (peg$silentFails === 0) {
1971
- peg$fail(peg$c84);
2295
+ peg$fail(peg$c96);
1972
2296
  }
1973
2297
  }
1974
2298
  return s0;
@@ -2001,23 +2325,23 @@ function peg$parse(input, options) {
2001
2325
  var s0, s1, s2;
2002
2326
  peg$silentFails++;
2003
2327
  s0 = peg$currPos;
2004
- if (input.substr(peg$currPos, 2) === peg$c86) {
2005
- s1 = peg$c86;
2328
+ if (input.substr(peg$currPos, 2) === peg$c98) {
2329
+ s1 = peg$c98;
2006
2330
  peg$currPos += 2;
2007
2331
  } else {
2008
2332
  s1 = peg$FAILED;
2009
2333
  if (peg$silentFails === 0) {
2010
- peg$fail(peg$c87);
2334
+ peg$fail(peg$c99);
2011
2335
  }
2012
2336
  }
2013
2337
  if (s1 !== peg$FAILED) {
2014
- if (peg$c88.test(input.charAt(peg$currPos))) {
2338
+ if (peg$c100.test(input.charAt(peg$currPos))) {
2015
2339
  s2 = input.charAt(peg$currPos);
2016
2340
  peg$currPos++;
2017
2341
  } else {
2018
2342
  s2 = peg$FAILED;
2019
2343
  if (peg$silentFails === 0) {
2020
- peg$fail(peg$c89);
2344
+ peg$fail(peg$c101);
2021
2345
  }
2022
2346
  }
2023
2347
  if (s2 === peg$FAILED) {
@@ -2038,7 +2362,7 @@ function peg$parse(input, options) {
2038
2362
  if (s0 === peg$FAILED) {
2039
2363
  s1 = peg$FAILED;
2040
2364
  if (peg$silentFails === 0) {
2041
- peg$fail(peg$c85);
2365
+ peg$fail(peg$c97);
2042
2366
  }
2043
2367
  }
2044
2368
  return s0;
@@ -2046,23 +2370,23 @@ function peg$parse(input, options) {
2046
2370
  function peg$parsenewline() {
2047
2371
  var s0, s1;
2048
2372
  peg$silentFails++;
2049
- if (input.substr(peg$currPos, 2) === peg$c91) {
2050
- s0 = peg$c91;
2373
+ if (input.substr(peg$currPos, 2) === peg$c103) {
2374
+ s0 = peg$c103;
2051
2375
  peg$currPos += 2;
2052
2376
  } else {
2053
2377
  s0 = peg$FAILED;
2054
2378
  if (peg$silentFails === 0) {
2055
- peg$fail(peg$c92);
2379
+ peg$fail(peg$c104);
2056
2380
  }
2057
2381
  }
2058
2382
  if (s0 === peg$FAILED) {
2059
2383
  if (input.charCodeAt(peg$currPos) === 10) {
2060
- s0 = peg$c93;
2384
+ s0 = peg$c105;
2061
2385
  peg$currPos++;
2062
2386
  } else {
2063
2387
  s0 = peg$FAILED;
2064
2388
  if (peg$silentFails === 0) {
2065
- peg$fail(peg$c94);
2389
+ peg$fail(peg$c106);
2066
2390
  }
2067
2391
  }
2068
2392
  }
@@ -2070,7 +2394,7 @@ function peg$parse(input, options) {
2070
2394
  if (s0 === peg$FAILED) {
2071
2395
  s1 = peg$FAILED;
2072
2396
  if (peg$silentFails === 0) {
2073
- peg$fail(peg$c90);
2397
+ peg$fail(peg$c102);
2074
2398
  }
2075
2399
  }
2076
2400
  return s0;
@@ -2078,20 +2402,20 @@ function peg$parse(input, options) {
2078
2402
  function peg$parsewhitespace() {
2079
2403
  var s0, s1;
2080
2404
  peg$silentFails++;
2081
- if (peg$c96.test(input.charAt(peg$currPos))) {
2405
+ if (peg$c108.test(input.charAt(peg$currPos))) {
2082
2406
  s0 = input.charAt(peg$currPos);
2083
2407
  peg$currPos++;
2084
2408
  } else {
2085
2409
  s0 = peg$FAILED;
2086
2410
  if (peg$silentFails === 0) {
2087
- peg$fail(peg$c97);
2411
+ peg$fail(peg$c109);
2088
2412
  }
2089
2413
  }
2090
2414
  peg$silentFails--;
2091
2415
  if (s0 === peg$FAILED) {
2092
2416
  s1 = peg$FAILED;
2093
2417
  if (peg$silentFails === 0) {
2094
- peg$fail(peg$c95);
2418
+ peg$fail(peg$c107);
2095
2419
  }
2096
2420
  }
2097
2421
  return s0;
@@ -2099,12 +2423,12 @@ function peg$parse(input, options) {
2099
2423
  function peg$parsesp() {
2100
2424
  var s0;
2101
2425
  if (input.charCodeAt(peg$currPos) === 32) {
2102
- s0 = peg$c98;
2426
+ s0 = peg$c110;
2103
2427
  peg$currPos++;
2104
2428
  } else {
2105
2429
  s0 = peg$FAILED;
2106
2430
  if (peg$silentFails === 0) {
2107
- peg$fail(peg$c99);
2431
+ peg$fail(peg$c111);
2108
2432
  }
2109
2433
  }
2110
2434
  return s0;
@@ -2135,6 +2459,24 @@ function peg$parse(input, options) {
2135
2459
  data.tables.push(table);
2136
2460
  }
2137
2461
  }
2462
+ function addCheckConstraintToTable(tableName, expression, name) {
2463
+ var table = data.tables.find(function (t) {
2464
+ return t.name === tableName;
2465
+ });
2466
+ if (!table) {
2467
+ error("Table ${tableName} not found");
2468
+ }
2469
+ if (!table.constraints) {
2470
+ table.constraints = [];
2471
+ }
2472
+ var constraint = {
2473
+ expression: expression
2474
+ };
2475
+ if (name) {
2476
+ constraint.name = name;
2477
+ }
2478
+ table.constraints.push(constraint);
2479
+ }
2138
2480
  function addPrimaryKey() {
2139
2481
  var fields = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2140
2482
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];