@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.
- package/lib/export/DbmlExporter.js +38 -1
- package/lib/export/MysqlExporter.js +36 -1
- package/lib/export/OracleExporter.js +36 -1
- package/lib/export/PostgresExporter.js +36 -1
- package/lib/export/SqlServerExporter.js +36 -1
- package/lib/index.js +1 -1
- package/lib/model_structure/constraint.js +86 -0
- package/lib/model_structure/database.js +1 -0
- package/lib/model_structure/dbState.js +1 -0
- package/lib/model_structure/field.js +23 -1
- package/lib/model_structure/table.js +51 -17
- package/lib/model_structure/tablePartial.js +3 -0
- package/lib/parse/ANTLR/ASTGeneration/AST.js +18 -6
- package/lib/parse/ANTLR/ASTGeneration/constants.js +2 -1
- package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +53 -101
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +73 -19
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +50 -16
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +1 -1
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +1 -1
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +2 -2
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +1314 -1314
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +1 -1
- package/lib/parse/schemarb/parser.pegjs +41 -0
- package/lib/parse/schemarbParser.js +568 -226
- package/package.json +3 -3
- package/types/model_structure/constraint.d.ts +52 -0
- package/types/model_structure/database.d.ts +2 -0
- package/types/model_structure/field.d.ts +7 -1
- package/types/model_structure/table.d.ts +8 -1
- package/types/model_structure/tablePartial.d.ts +4 -1
|
@@ -18,7 +18,7 @@ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError(
|
|
|
18
18
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
19
19
|
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
20
20
|
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
21
|
-
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } // Generated from
|
|
21
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } // Generated from PostgreSQLParser.g4 by ANTLR 4.13.2
|
|
22
22
|
// jshint ignore: start
|
|
23
23
|
// This class defines a complete generic visitor for a parse tree produced by PostgreSQLParser.
|
|
24
24
|
var PostgreSQLParserVisitor = exports["default"] = /*#__PURE__*/function (_antlr4$tree$ParseTre) {
|
|
@@ -22,6 +22,21 @@
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
function addCheckConstraintToTable(tableName, expression, name) {
|
|
26
|
+
const table = data.tables.find(t => t.name === tableName);
|
|
27
|
+
if (!table) {
|
|
28
|
+
error("Table ${tableName} not found");
|
|
29
|
+
}
|
|
30
|
+
if (!table.constraints) {
|
|
31
|
+
table.constraints = [];
|
|
32
|
+
}
|
|
33
|
+
const constraint = { expression };
|
|
34
|
+
if (name) {
|
|
35
|
+
constraint.name = name;
|
|
36
|
+
}
|
|
37
|
+
table.constraints.push(constraint);
|
|
38
|
+
}
|
|
39
|
+
|
|
25
40
|
function addPrimaryKey(fields = [], props = []) {
|
|
26
41
|
const primaryKey = props.find(prop => prop.name === 'primary_key');
|
|
27
42
|
if (!primaryKey) return fields;
|
|
@@ -264,8 +279,15 @@ rule = tableData:create_table_syntax {
|
|
|
264
279
|
/ r:add_foreign_key_syntax {
|
|
265
280
|
pushRef(r);
|
|
266
281
|
}
|
|
282
|
+
/ add_check_constraint_syntax
|
|
267
283
|
/ other_class_prop
|
|
268
284
|
|
|
285
|
+
add_check_constraint_syntax
|
|
286
|
+
= sp* add_check_constraint sp* tableName:(symbol / name) "," sp* expression:name props:check_constraint_props* {
|
|
287
|
+
const constraintName = props.find(p => p.name)?.name;
|
|
288
|
+
addCheckConstraintToTable(tableName, expression, constraintName);
|
|
289
|
+
}
|
|
290
|
+
|
|
269
291
|
add_foreign_key_syntax
|
|
270
292
|
= sp* add_foreign_key sp* fromTable:name","sp* toTable:name props:add_foreign_key_props_syntax* {
|
|
271
293
|
const foreign = refactorForeign(createForeign(fromTable, toTable, props));
|
|
@@ -297,6 +319,9 @@ create_table_syntax
|
|
|
297
319
|
fields: addPrimaryKey(body.fields),
|
|
298
320
|
// index: _.union(...body.index)
|
|
299
321
|
})
|
|
322
|
+
if (body.constraints && body.constraints.length > 0) {
|
|
323
|
+
table.constraints = body.constraints;
|
|
324
|
+
}
|
|
300
325
|
return {
|
|
301
326
|
table,
|
|
302
327
|
refs: createRefFromTableWithReference(table, body.references)
|
|
@@ -308,6 +333,7 @@ table_body = fields:field* {
|
|
|
308
333
|
fields: fields.filter(field => field.isField).map(field => field.field),
|
|
309
334
|
index: fields.filter(field => field.isIndex).map(field => field.index),
|
|
310
335
|
references: fields.filter(field => field.isReferences).map(field => field.reference),
|
|
336
|
+
constraints: fields.filter(field => field.isConstraint).map(field => field.constraint),
|
|
311
337
|
});
|
|
312
338
|
}
|
|
313
339
|
|
|
@@ -316,12 +342,22 @@ field = whitespace* field:table_field_syntax whatever* endline { return field }
|
|
|
316
342
|
table_field_syntax
|
|
317
343
|
= field_index_syntax
|
|
318
344
|
/ reference: field_reference_syntax { return ({ reference, isReferences: true })}
|
|
345
|
+
/ constraint: field_check_constraint_syntax { return ({ constraint, isConstraint: true })}
|
|
319
346
|
/ field:field_type_syntax { return ({ field, isField: true }) }
|
|
320
347
|
|
|
321
348
|
field_index_syntax = index sp+ whateters
|
|
322
349
|
field_reference_syntax = references sp+ reference:reference_value {
|
|
323
350
|
return reference;
|
|
324
351
|
}
|
|
352
|
+
field_check_constraint_syntax = check_constraint sp+ expression:name props:check_constraint_props* {
|
|
353
|
+
const constraint = { expression };
|
|
354
|
+
for (let i = 0; i < props.length; i++) {
|
|
355
|
+
if (props[i].name) {
|
|
356
|
+
constraint.name = props[i].name;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return constraint;
|
|
360
|
+
}
|
|
325
361
|
field_type_syntax = type:field_type sp+ name:name {
|
|
326
362
|
return ({
|
|
327
363
|
name: name,
|
|
@@ -332,6 +368,9 @@ field_type_syntax = type:field_type sp+ name:name {
|
|
|
332
368
|
reference_value = ":"reference:variable { return reference }
|
|
333
369
|
/ reference:name { return reference }
|
|
334
370
|
|
|
371
|
+
check_constraint_props
|
|
372
|
+
= "," sp* "name"i":" sp* constraintName:name { return ({ name: constraintName }) }
|
|
373
|
+
|
|
335
374
|
referential_actions = "on_delete"i / "on_update"i
|
|
336
375
|
|
|
337
376
|
// Keywords
|
|
@@ -341,6 +380,8 @@ create_table "create table" = "create_table"i
|
|
|
341
380
|
end_create_table "do |t|" = do sp+ abs character abs endline
|
|
342
381
|
index "index" = character ".index"
|
|
343
382
|
references "references" = character ".references"
|
|
383
|
+
check_constraint "check constraint" = character ".check_constraint"
|
|
384
|
+
add_check_constraint "add check constraint" = "add_check_constraint"i
|
|
344
385
|
add_foreign_key "add foreign key" = "add_foreign_key"i
|
|
345
386
|
column "column" = "column"
|
|
346
387
|
primary_key "primary key" = "primary_key"
|