@dbml/core 3.15.0-alpha.0 → 5.0.0-alpha.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 +19 -19
- package/lib/export/MysqlExporter.js +21 -21
- package/lib/export/OracleExporter.js +21 -21
- package/lib/export/PostgresExporter.js +21 -21
- package/lib/export/SqlServerExporter.js +23 -23
- package/lib/index.js +1 -1
- package/lib/model_structure/{constraint.js → check.js} +9 -9
- package/lib/model_structure/database.js +1 -1
- package/lib/model_structure/dbState.js +1 -1
- package/lib/model_structure/field.js +13 -13
- package/lib/model_structure/table.js +19 -19
- package/lib/model_structure/tablePartial.js +3 -3
- package/lib/parse/ANTLR/ASTGeneration/AST.js +8 -8
- package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +39 -144
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +5 -5
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +6 -6
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +1 -1
- package/lib/parse/schemarb/parser.pegjs +15 -15
- package/lib/parse/schemarbParser.js +19 -19
- package/package.json +3 -3
- package/types/model_structure/{constraint.d.ts → check.d.ts} +10 -10
- package/types/model_structure/database.d.ts +2 -2
- package/types/model_structure/dbState.d.ts +1 -0
- package/types/model_structure/field.d.ts +7 -7
- package/types/model_structure/table.d.ts +8 -8
- package/types/model_structure/tablePartial.d.ts +4 -4
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
function addCheckConstraintToTable(tableName, expression, name) {
|
|
26
26
|
const table = data.tables.find(t => t.name === tableName);
|
|
27
27
|
if (!table) {
|
|
28
|
-
error("Table
|
|
28
|
+
error("Table ${tableName} not found");
|
|
29
29
|
}
|
|
30
|
-
if (!table.
|
|
31
|
-
table.
|
|
30
|
+
if (!table.checks) {
|
|
31
|
+
table.checks = [];
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const check = { expression };
|
|
34
34
|
if (name) {
|
|
35
|
-
|
|
35
|
+
check.name = name;
|
|
36
36
|
}
|
|
37
|
-
table.
|
|
37
|
+
table.checks.push(check);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function addPrimaryKey(fields = [], props = []) {
|
|
@@ -284,8 +284,8 @@ rule = tableData:create_table_syntax {
|
|
|
284
284
|
|
|
285
285
|
add_check_constraint_syntax
|
|
286
286
|
= sp* add_check_constraint sp* tableName:(symbol / name) "," sp* expression:name props:check_constraint_props* {
|
|
287
|
-
const
|
|
288
|
-
addCheckConstraintToTable(tableName, expression,
|
|
287
|
+
const checkName = props.find(p => p.name)?.name;
|
|
288
|
+
addCheckConstraintToTable(tableName, expression, checkName);
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
add_foreign_key_syntax
|
|
@@ -319,8 +319,8 @@ create_table_syntax
|
|
|
319
319
|
fields: addPrimaryKey(body.fields),
|
|
320
320
|
// index: _.union(...body.index)
|
|
321
321
|
})
|
|
322
|
-
if (body.
|
|
323
|
-
table.
|
|
322
|
+
if (body.checks && body.checks.length > 0) {
|
|
323
|
+
table.checks = body.checks;
|
|
324
324
|
}
|
|
325
325
|
return {
|
|
326
326
|
table,
|
|
@@ -333,7 +333,7 @@ table_body = fields:field* {
|
|
|
333
333
|
fields: fields.filter(field => field.isField).map(field => field.field),
|
|
334
334
|
index: fields.filter(field => field.isIndex).map(field => field.index),
|
|
335
335
|
references: fields.filter(field => field.isReferences).map(field => field.reference),
|
|
336
|
-
|
|
336
|
+
checks: fields.filter(field => field.isCheck).map(field => field.check),
|
|
337
337
|
});
|
|
338
338
|
}
|
|
339
339
|
|
|
@@ -342,7 +342,7 @@ field = whitespace* field:table_field_syntax whatever* endline { return field }
|
|
|
342
342
|
table_field_syntax
|
|
343
343
|
= field_index_syntax
|
|
344
344
|
/ reference: field_reference_syntax { return ({ reference, isReferences: true })}
|
|
345
|
-
/
|
|
345
|
+
/ check: field_check_constraint_syntax { return ({ check, isCheck: true })}
|
|
346
346
|
/ field:field_type_syntax { return ({ field, isField: true }) }
|
|
347
347
|
|
|
348
348
|
field_index_syntax = index sp+ whateters
|
|
@@ -350,13 +350,13 @@ field_reference_syntax = references sp+ reference:reference_value {
|
|
|
350
350
|
return reference;
|
|
351
351
|
}
|
|
352
352
|
field_check_constraint_syntax = check_constraint sp+ expression:name props:check_constraint_props* {
|
|
353
|
-
const
|
|
353
|
+
const check = { expression };
|
|
354
354
|
for (let i = 0; i < props.length; i++) {
|
|
355
355
|
if (props[i].name) {
|
|
356
|
-
|
|
356
|
+
check.name = props[i].name;
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
|
-
return
|
|
359
|
+
return check;
|
|
360
360
|
}
|
|
361
361
|
field_type_syntax = type:field_type sp+ name:name {
|
|
362
362
|
return ({
|
|
@@ -129,10 +129,10 @@ function peg$parse(input, options) {
|
|
|
129
129
|
peg$c4 = peg$literalExpectation(",", false),
|
|
130
130
|
peg$c5 = function peg$c5(tableName, expression, props) {
|
|
131
131
|
var _props$find;
|
|
132
|
-
var
|
|
132
|
+
var checkName = (_props$find = props.find(function (p) {
|
|
133
133
|
return p.name;
|
|
134
134
|
})) === null || _props$find === void 0 ? void 0 : _props$find.name;
|
|
135
|
-
addCheckConstraintToTable(tableName, expression,
|
|
135
|
+
addCheckConstraintToTable(tableName, expression, checkName);
|
|
136
136
|
},
|
|
137
137
|
peg$c6 = function peg$c6(fromTable, toTable, props) {
|
|
138
138
|
var foreign = refactorForeign(createForeign(fromTable, toTable, props));
|
|
@@ -168,8 +168,8 @@ function peg$parse(input, options) {
|
|
|
168
168
|
fields: addPrimaryKey(body.fields)
|
|
169
169
|
// index: _.union(...body.index)
|
|
170
170
|
};
|
|
171
|
-
if (body.
|
|
172
|
-
table.
|
|
171
|
+
if (body.checks && body.checks.length > 0) {
|
|
172
|
+
table.checks = body.checks;
|
|
173
173
|
}
|
|
174
174
|
return {
|
|
175
175
|
table: table,
|
|
@@ -193,10 +193,10 @@ function peg$parse(input, options) {
|
|
|
193
193
|
}).map(function (field) {
|
|
194
194
|
return field.reference;
|
|
195
195
|
}),
|
|
196
|
-
|
|
197
|
-
return field.
|
|
196
|
+
checks: fields.filter(function (field) {
|
|
197
|
+
return field.isCheck;
|
|
198
198
|
}).map(function (field) {
|
|
199
|
-
return field.
|
|
199
|
+
return field.check;
|
|
200
200
|
})
|
|
201
201
|
};
|
|
202
202
|
},
|
|
@@ -209,10 +209,10 @@ function peg$parse(input, options) {
|
|
|
209
209
|
isReferences: true
|
|
210
210
|
};
|
|
211
211
|
},
|
|
212
|
-
peg$c16 = function peg$c16(
|
|
212
|
+
peg$c16 = function peg$c16(check) {
|
|
213
213
|
return {
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
check: check,
|
|
215
|
+
isCheck: true
|
|
216
216
|
};
|
|
217
217
|
},
|
|
218
218
|
peg$c17 = function peg$c17(field) {
|
|
@@ -225,15 +225,15 @@ function peg$parse(input, options) {
|
|
|
225
225
|
return reference;
|
|
226
226
|
},
|
|
227
227
|
peg$c19 = function peg$c19(expression, props) {
|
|
228
|
-
var
|
|
228
|
+
var check = {
|
|
229
229
|
expression: expression
|
|
230
230
|
};
|
|
231
231
|
for (var i = 0; i < props.length; i++) {
|
|
232
232
|
if (props[i].name) {
|
|
233
|
-
|
|
233
|
+
check.name = props[i].name;
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
-
return
|
|
236
|
+
return check;
|
|
237
237
|
},
|
|
238
238
|
peg$c20 = function peg$c20(type, name) {
|
|
239
239
|
return {
|
|
@@ -2464,18 +2464,18 @@ function peg$parse(input, options) {
|
|
|
2464
2464
|
return t.name === tableName;
|
|
2465
2465
|
});
|
|
2466
2466
|
if (!table) {
|
|
2467
|
-
error("Table
|
|
2467
|
+
error("Table ${tableName} not found");
|
|
2468
2468
|
}
|
|
2469
|
-
if (!table.
|
|
2470
|
-
table.
|
|
2469
|
+
if (!table.checks) {
|
|
2470
|
+
table.checks = [];
|
|
2471
2471
|
}
|
|
2472
|
-
var
|
|
2472
|
+
var check = {
|
|
2473
2473
|
expression: expression
|
|
2474
2474
|
};
|
|
2475
2475
|
if (name) {
|
|
2476
|
-
|
|
2476
|
+
check.name = name;
|
|
2477
2477
|
}
|
|
2478
|
-
table.
|
|
2478
|
+
table.checks.push(check);
|
|
2479
2479
|
}
|
|
2480
2480
|
function addPrimaryKey() {
|
|
2481
2481
|
var fields = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-alpha.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "Holistics <dev@holistics.io>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"prepublish": "npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@dbml/parse": "^
|
|
35
|
+
"@dbml/parse": "^5.0.0-alpha.0",
|
|
36
36
|
"antlr4": "^4.13.1",
|
|
37
37
|
"lodash": "^4.17.15",
|
|
38
38
|
"parsimmon": "^1.13.0",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"^lodash-es$": "lodash"
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "630548187910efa893579e80ab07f447df1ef61e",
|
|
66
66
|
"engines": {
|
|
67
67
|
"node": ">=16"
|
|
68
68
|
}
|
|
@@ -4,27 +4,27 @@ import Field from './field';
|
|
|
4
4
|
import Table from './table';
|
|
5
5
|
import TablePartial from './tablePartial';
|
|
6
6
|
|
|
7
|
-
interface
|
|
7
|
+
interface RawCheck {
|
|
8
8
|
token: Token;
|
|
9
9
|
name: string;
|
|
10
|
-
expression:
|
|
10
|
+
expression: string;
|
|
11
11
|
table: Table;
|
|
12
12
|
column?: Field | null;
|
|
13
13
|
injectedPartial?: TablePartial | null;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
declare class
|
|
16
|
+
declare class Check extends Element {
|
|
17
17
|
name: string;
|
|
18
|
-
expression:
|
|
18
|
+
expression: string;
|
|
19
19
|
table: Table;
|
|
20
20
|
column: Field | null;
|
|
21
21
|
injectedPartial: TablePartial | null;
|
|
22
22
|
|
|
23
|
-
constructor({ token, name, expression, table, column, injectedPartial }:
|
|
23
|
+
constructor({ token, name, expression, table, column, injectedPartial }: RawCheck);
|
|
24
24
|
generateId(): void;
|
|
25
25
|
export(): {
|
|
26
26
|
name: string;
|
|
27
|
-
expression:
|
|
27
|
+
expression: string;
|
|
28
28
|
};
|
|
29
29
|
exportParentIds(): {
|
|
30
30
|
tableId: number;
|
|
@@ -33,20 +33,20 @@ declare class Constraint extends Element {
|
|
|
33
33
|
};
|
|
34
34
|
shallowExport(): {
|
|
35
35
|
name: string;
|
|
36
|
-
expression:
|
|
36
|
+
expression: string;
|
|
37
37
|
};
|
|
38
38
|
normalize(model: NormalizedDatabase): void;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export interface
|
|
41
|
+
export interface NormalizedCheck {
|
|
42
42
|
[_id: number]: {
|
|
43
43
|
id: number;
|
|
44
44
|
name: string;
|
|
45
|
-
expression:
|
|
45
|
+
expression: string;
|
|
46
46
|
tableId: number;
|
|
47
47
|
columnId: number | null;
|
|
48
48
|
injectedPartialId: number | null;
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export default
|
|
52
|
+
export default Check;
|
|
@@ -11,7 +11,7 @@ import { NormalizedEnumValue } from './enumValue';
|
|
|
11
11
|
import { NormalizedField } from './field';
|
|
12
12
|
import { NormalizedIndexColumn } from './indexColumn';
|
|
13
13
|
import { NormalizedIndex } from './indexes';
|
|
14
|
-
import {
|
|
14
|
+
import { NormalizedCheck } from './check';
|
|
15
15
|
import TablePartial, { NormalizedTablePartial } from './tablePartial';
|
|
16
16
|
export interface Project {
|
|
17
17
|
note: RawNote;
|
|
@@ -300,7 +300,7 @@ export interface NormalizedDatabase {
|
|
|
300
300
|
enumValues: NormalizedEnumValue;
|
|
301
301
|
indexes: NormalizedIndex;
|
|
302
302
|
indexColumns: NormalizedIndexColumn;
|
|
303
|
-
|
|
303
|
+
checks: NormalizedCheck;
|
|
304
304
|
fields: NormalizedField;
|
|
305
305
|
records: NormalizedRecords;
|
|
306
306
|
tablePartials: NormalizedTablePartial;
|
|
@@ -5,7 +5,7 @@ import Endpoint from './endpoint';
|
|
|
5
5
|
import Enum from './enum';
|
|
6
6
|
import Table from './table';
|
|
7
7
|
import TablePartial from './tablePartial';
|
|
8
|
-
import
|
|
8
|
+
import Check from './check';
|
|
9
9
|
interface RawField {
|
|
10
10
|
name: string;
|
|
11
11
|
type: any;
|
|
@@ -16,7 +16,7 @@ interface RawField {
|
|
|
16
16
|
note: RawNote;
|
|
17
17
|
dbdefault: any;
|
|
18
18
|
increment: boolean;
|
|
19
|
-
|
|
19
|
+
checks?: any[];
|
|
20
20
|
table: Table;
|
|
21
21
|
}
|
|
22
22
|
declare class Field extends Element {
|
|
@@ -30,16 +30,16 @@ declare class Field extends Element {
|
|
|
30
30
|
noteToken: Token;
|
|
31
31
|
dbdefault: any;
|
|
32
32
|
increment: boolean;
|
|
33
|
-
|
|
33
|
+
checks: Check[];
|
|
34
34
|
table: Table;
|
|
35
35
|
endpoints: Endpoint[];
|
|
36
36
|
_enum: Enum;
|
|
37
37
|
injectedPartial?: TablePartial;
|
|
38
38
|
injectedToken: Token;
|
|
39
|
-
constructor({ name, type, unique, pk, token, not_null, note, dbdefault, increment,
|
|
39
|
+
constructor({ name, type, unique, pk, token, not_null, note, dbdefault, increment, checks, table }: RawField);
|
|
40
40
|
generateId(): void;
|
|
41
41
|
pushEndpoint(endpoint: any): void;
|
|
42
|
-
|
|
42
|
+
processChecks(checks: any[]): void;
|
|
43
43
|
export(): {
|
|
44
44
|
name: string;
|
|
45
45
|
type: any;
|
|
@@ -68,7 +68,7 @@ declare class Field extends Element {
|
|
|
68
68
|
dbdefault: any;
|
|
69
69
|
increment: boolean;
|
|
70
70
|
injectedPartialId?: number;
|
|
71
|
-
|
|
71
|
+
checkIds: number[];
|
|
72
72
|
};
|
|
73
73
|
normalize(model: NormalizedDatabase): void;
|
|
74
74
|
}
|
|
@@ -87,7 +87,7 @@ export interface NormalizedField {
|
|
|
87
87
|
endpointIds: number[];
|
|
88
88
|
enumId: number;
|
|
89
89
|
injectedPartialId?: number;
|
|
90
|
-
|
|
90
|
+
checkIds: number[];
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
export default Field;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Element, { RawNote, Token } from './element';
|
|
2
2
|
import Field from './field';
|
|
3
3
|
import Index from './indexes';
|
|
4
|
-
import
|
|
4
|
+
import Check from './check';
|
|
5
5
|
import Schema from './schema';
|
|
6
6
|
import DbState from './dbState';
|
|
7
7
|
import TableGroup from './tableGroup';
|
|
@@ -14,7 +14,7 @@ interface RawTable {
|
|
|
14
14
|
note: RawNote;
|
|
15
15
|
fields: Field[];
|
|
16
16
|
indexes: Index[];
|
|
17
|
-
|
|
17
|
+
checks?: any[];
|
|
18
18
|
schema: Schema;
|
|
19
19
|
token: Token;
|
|
20
20
|
headerColor: string;
|
|
@@ -28,7 +28,7 @@ declare class Table extends Element {
|
|
|
28
28
|
noteToken: Token;
|
|
29
29
|
fields: Field[];
|
|
30
30
|
indexes: Index[];
|
|
31
|
-
|
|
31
|
+
checks: Check[];
|
|
32
32
|
schema: Schema;
|
|
33
33
|
headerColor: string;
|
|
34
34
|
dbState: DbState;
|
|
@@ -36,7 +36,7 @@ declare class Table extends Element {
|
|
|
36
36
|
group: TableGroup;
|
|
37
37
|
partials: TablePartial[];
|
|
38
38
|
|
|
39
|
-
constructor({ name, alias, note, fields, indexes,
|
|
39
|
+
constructor({ name, alias, note, fields, indexes, checks, schema, token, headerColor }: RawTable);
|
|
40
40
|
generateId(): void;
|
|
41
41
|
processFields(rawFields: any): void;
|
|
42
42
|
pushField(field: any): void;
|
|
@@ -44,8 +44,8 @@ declare class Table extends Element {
|
|
|
44
44
|
processIndexes(rawIndexes: any): void;
|
|
45
45
|
pushIndex(index: any): void;
|
|
46
46
|
checkIndex(index: any): void;
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
processChecks(checks: any[]): void;
|
|
48
|
+
pushCheck(check: any): void;
|
|
49
49
|
findField(fieldName: any): Field;
|
|
50
50
|
checkSameId(table: any): boolean;
|
|
51
51
|
processPartials(): void;
|
|
@@ -103,7 +103,7 @@ declare class Table extends Element {
|
|
|
103
103
|
exportChildIds(): {
|
|
104
104
|
fieldIds: number[];
|
|
105
105
|
indexIds: number[];
|
|
106
|
-
|
|
106
|
+
checkIds: number[];
|
|
107
107
|
};
|
|
108
108
|
exportParentIds(): {
|
|
109
109
|
schemaId: number;
|
|
@@ -128,7 +128,7 @@ export interface NormalizedTable {
|
|
|
128
128
|
headerColor: string;
|
|
129
129
|
fieldIds: number[];
|
|
130
130
|
indexIds: number[];
|
|
131
|
-
|
|
131
|
+
checkIds: number[];
|
|
132
132
|
schemaId: number;
|
|
133
133
|
groupId: number;
|
|
134
134
|
partials: TablePartial[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Element, { RawNote, Token } from './element';
|
|
2
2
|
import Field from './field';
|
|
3
3
|
import Index from './indexes';
|
|
4
|
-
import
|
|
4
|
+
import Check from './check';
|
|
5
5
|
import DbState from './dbState';
|
|
6
6
|
import { NormalizedDatabase } from './database';
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ interface RawTablePartial {
|
|
|
10
10
|
note: RawNote;
|
|
11
11
|
fields: Field[];
|
|
12
12
|
indexes: Index[];
|
|
13
|
-
|
|
13
|
+
checks?: any[];
|
|
14
14
|
token: Token;
|
|
15
15
|
headerColor: string;
|
|
16
16
|
dbState: DbState;
|
|
@@ -22,12 +22,12 @@ declare class TablePartial extends Element {
|
|
|
22
22
|
noteToken: Token;
|
|
23
23
|
fields: Field[];
|
|
24
24
|
indexes: Index[];
|
|
25
|
-
|
|
25
|
+
checks: Check[];
|
|
26
26
|
headerColor: string;
|
|
27
27
|
dbState: DbState;
|
|
28
28
|
id: number;
|
|
29
29
|
|
|
30
|
-
constructor({ name, note, fields, indexes,
|
|
30
|
+
constructor({ name, note, fields, indexes, checks, token, headerColor, dbState }: RawTablePartial);
|
|
31
31
|
generateId(): void;
|
|
32
32
|
export(): {
|
|
33
33
|
name: string;
|