@dbml/core 4.0.0 → 5.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 +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/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 +9 -9
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +5 -5
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +6 -6
- package/lib/parse/schemarb/parser.pegjs +14 -14
- package/lib/parse/schemarbParser.js +18 -18
- package/package.json +3 -3
- package/types/model_structure/{constraint.d.ts → check.d.ts} +5 -5
- 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
|
@@ -89,9 +89,9 @@ var DbmlExporter = /*#__PURE__*/function () {
|
|
|
89
89
|
if (field.increment) {
|
|
90
90
|
constraints.push('increment');
|
|
91
91
|
}
|
|
92
|
-
if (field.
|
|
93
|
-
constraints.push.apply(constraints, _toConsumableArray(field.
|
|
94
|
-
return "
|
|
92
|
+
if (field.checkIds) {
|
|
93
|
+
constraints.push.apply(constraints, _toConsumableArray(field.checkIds.map(function (id) {
|
|
94
|
+
return "check: `".concat(model.checks[id].expression, "`");
|
|
95
95
|
})));
|
|
96
96
|
}
|
|
97
97
|
if (field.dbdefault) {
|
|
@@ -167,14 +167,14 @@ var DbmlExporter = /*#__PURE__*/function () {
|
|
|
167
167
|
return lines;
|
|
168
168
|
}
|
|
169
169
|
}, {
|
|
170
|
-
key: "
|
|
171
|
-
value: function
|
|
170
|
+
key: "getCheckLines",
|
|
171
|
+
value: function getCheckLines(tableId, model) {
|
|
172
172
|
var table = model.tables[tableId];
|
|
173
|
-
var lines = table.
|
|
173
|
+
var lines = table.checkIds.map(function (checkId) {
|
|
174
174
|
var line = '';
|
|
175
|
-
var _model$
|
|
176
|
-
expression = _model$
|
|
177
|
-
name = _model$
|
|
175
|
+
var _model$checks$checkId = model.checks[checkId],
|
|
176
|
+
expression = _model$checks$checkId.expression,
|
|
177
|
+
name = _model$checks$checkId.name;
|
|
178
178
|
line += "`".concat(expression, "`");
|
|
179
179
|
if (name) {
|
|
180
180
|
line += " [name: '".concat(name, "']");
|
|
@@ -188,12 +188,12 @@ var DbmlExporter = /*#__PURE__*/function () {
|
|
|
188
188
|
value: function getTableContentArr(tableIds, model) {
|
|
189
189
|
var tableContentArr = tableIds.map(function (tableId) {
|
|
190
190
|
var fieldContents = DbmlExporter.getFieldLines(tableId, model);
|
|
191
|
-
var
|
|
191
|
+
var checkContents = DbmlExporter.getCheckLines(tableId, model);
|
|
192
192
|
var indexContents = DbmlExporter.getIndexLines(tableId, model);
|
|
193
193
|
return {
|
|
194
194
|
tableId: tableId,
|
|
195
195
|
fieldContents: fieldContents,
|
|
196
|
-
|
|
196
|
+
checkContents: checkContents,
|
|
197
197
|
indexContents: indexContents
|
|
198
198
|
};
|
|
199
199
|
});
|
|
@@ -226,12 +226,12 @@ var DbmlExporter = /*#__PURE__*/function () {
|
|
|
226
226
|
var fieldStr = tableContent.fieldContents.map(function (field) {
|
|
227
227
|
return " ".concat(field, "\n");
|
|
228
228
|
}).join('');
|
|
229
|
-
var
|
|
230
|
-
if (!(0, _lodash.isEmpty)(tableContent.
|
|
231
|
-
var
|
|
232
|
-
return " ".concat(
|
|
229
|
+
var checkStr = '';
|
|
230
|
+
if (!(0, _lodash.isEmpty)(tableContent.checkContents)) {
|
|
231
|
+
var checkBody = tableContent.checkContents.map(function (checkLine) {
|
|
232
|
+
return " ".concat(checkLine, "\n");
|
|
233
233
|
}).join('');
|
|
234
|
-
|
|
234
|
+
checkStr = "\n Checks {\n".concat(checkBody, " }\n");
|
|
235
235
|
}
|
|
236
236
|
var indexStr = '';
|
|
237
237
|
if (!(0, _lodash.isEmpty)(tableContent.indexContents)) {
|
|
@@ -241,7 +241,7 @@ var DbmlExporter = /*#__PURE__*/function () {
|
|
|
241
241
|
indexStr = "\n Indexes {\n".concat(indexBody, " }\n");
|
|
242
242
|
}
|
|
243
243
|
var noteStr = table.note ? " Note: ".concat(DbmlExporter.escapeNote(table.note), "\n") : '';
|
|
244
|
-
return "Table ".concat(tableName).concat(tableSettingStr, " {\n").concat(fieldStr).concat(
|
|
244
|
+
return "Table ".concat(tableName).concat(tableSettingStr, " {\n").concat(fieldStr).concat(checkStr).concat(indexStr).concat(noteStr, "}\n");
|
|
245
245
|
});
|
|
246
246
|
return tableStrs.length ? tableStrs.join('\n') : '';
|
|
247
247
|
}
|
|
@@ -320,7 +320,7 @@ var DbmlExporter = /*#__PURE__*/function () {
|
|
|
320
320
|
var table = model.tables[tableId];
|
|
321
321
|
var tableSchema = model.schemas[table.schemaId];
|
|
322
322
|
var tableName = " ".concat((0, _utils.shouldPrintSchema)(tableSchema, model) ? "\"".concat(tableSchema.name, "\".") : '', "\"").concat(table.name, "\"");
|
|
323
|
-
return
|
|
323
|
+
return "".concat(result).concat(tableName, "\n");
|
|
324
324
|
}, '');
|
|
325
325
|
return "TableGroup ".concat(groupName).concat(groupSettingStr, " {\n").concat(tableNames).concat(groupNote, "}\n");
|
|
326
326
|
});
|
|
@@ -334,7 +334,7 @@ var DbmlExporter = /*#__PURE__*/function () {
|
|
|
334
334
|
var stickyNote = "Note ".concat(note.name, " {\n").concat(escapedContent, "\n}\n");
|
|
335
335
|
|
|
336
336
|
// Add a blank line between note elements
|
|
337
|
-
return result ? result
|
|
337
|
+
return result ? "".concat(result, "\n").concat(stickyNote) : stickyNote;
|
|
338
338
|
}, '');
|
|
339
339
|
}
|
|
340
340
|
}, {
|
|
@@ -52,19 +52,19 @@ var MySQLExporter = /*#__PURE__*/function () {
|
|
|
52
52
|
if (field.increment) {
|
|
53
53
|
line += ' AUTO_INCREMENT';
|
|
54
54
|
}
|
|
55
|
-
if (field.
|
|
56
|
-
if (field.
|
|
57
|
-
var
|
|
58
|
-
if (
|
|
59
|
-
line += " CONSTRAINT `".concat(
|
|
55
|
+
if (field.checkIds && field.checkIds.length > 0) {
|
|
56
|
+
if (field.checkIds.length === 1) {
|
|
57
|
+
var check = model.checks[field.checkIds[0]];
|
|
58
|
+
if (check.name) {
|
|
59
|
+
line += " CONSTRAINT `".concat(check.name, "`");
|
|
60
60
|
}
|
|
61
|
-
line += " CHECK (".concat(
|
|
61
|
+
line += " CHECK (".concat(check.expression, ")");
|
|
62
62
|
} else {
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
return "(".concat(
|
|
63
|
+
var checkExpressions = field.checkIds.map(function (checkId) {
|
|
64
|
+
var check = model.checks[checkId];
|
|
65
|
+
return "(".concat(check.expression, ")");
|
|
66
66
|
});
|
|
67
|
-
line += " CHECK (".concat(
|
|
67
|
+
line += " CHECK (".concat(checkExpressions.join(' AND '), ")");
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
if (field.dbdefault) {
|
|
@@ -110,19 +110,19 @@ var MySQLExporter = /*#__PURE__*/function () {
|
|
|
110
110
|
return lines;
|
|
111
111
|
}
|
|
112
112
|
}, {
|
|
113
|
-
key: "
|
|
114
|
-
value: function
|
|
113
|
+
key: "getCheckLines",
|
|
114
|
+
value: function getCheckLines(tableId, model) {
|
|
115
115
|
var table = model.tables[tableId];
|
|
116
|
-
if (!table.
|
|
116
|
+
if (!table.checkIds || table.checkIds.length === 0) {
|
|
117
117
|
return [];
|
|
118
118
|
}
|
|
119
|
-
var lines = table.
|
|
120
|
-
var
|
|
119
|
+
var lines = table.checkIds.map(function (checkId) {
|
|
120
|
+
var check = model.checks[checkId];
|
|
121
121
|
var line = '';
|
|
122
|
-
if (
|
|
123
|
-
line = "CONSTRAINT `".concat(
|
|
122
|
+
if (check.name) {
|
|
123
|
+
line = "CONSTRAINT `".concat(check.name, "` ");
|
|
124
124
|
}
|
|
125
|
-
line += "CHECK (".concat(
|
|
125
|
+
line += "CHECK (".concat(check.expression, ")");
|
|
126
126
|
return line;
|
|
127
127
|
});
|
|
128
128
|
return lines;
|
|
@@ -132,12 +132,12 @@ var MySQLExporter = /*#__PURE__*/function () {
|
|
|
132
132
|
value: function getTableContentArr(tableIds, model) {
|
|
133
133
|
var tableContentArr = tableIds.map(function (tableId) {
|
|
134
134
|
var fieldContents = MySQLExporter.getFieldLines(tableId, model);
|
|
135
|
-
var
|
|
135
|
+
var checkContents = MySQLExporter.getCheckLines(tableId, model);
|
|
136
136
|
var compositePKs = MySQLExporter.getCompositePKs(tableId, model);
|
|
137
137
|
return {
|
|
138
138
|
tableId: tableId,
|
|
139
139
|
fieldContents: fieldContents,
|
|
140
|
-
|
|
140
|
+
checkContents: checkContents,
|
|
141
141
|
compositePKs: compositePKs
|
|
142
142
|
};
|
|
143
143
|
});
|
|
@@ -148,7 +148,7 @@ var MySQLExporter = /*#__PURE__*/function () {
|
|
|
148
148
|
value: function exportTables(tableIds, model) {
|
|
149
149
|
var tableContentArr = MySQLExporter.getTableContentArr(tableIds, model);
|
|
150
150
|
var tableStrs = tableContentArr.map(function (tableContent) {
|
|
151
|
-
var content = [].concat(_toConsumableArray(tableContent.fieldContents), _toConsumableArray(tableContent.
|
|
151
|
+
var content = [].concat(_toConsumableArray(tableContent.fieldContents), _toConsumableArray(tableContent.checkContents), _toConsumableArray(tableContent.compositePKs));
|
|
152
152
|
var table = model.tables[tableContent.tableId];
|
|
153
153
|
var schema = model.schemas[table.schemaId];
|
|
154
154
|
var tableStr = "CREATE TABLE ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "`".concat(schema.name, "`.") : '', "`").concat(table.name, "` (\n").concat(content.map(function (line) {
|
|
@@ -100,19 +100,19 @@ var OracleExporter = /*#__PURE__*/function () {
|
|
|
100
100
|
if (cloneField.not_null) {
|
|
101
101
|
line += ' NOT NULL';
|
|
102
102
|
}
|
|
103
|
-
if (cloneField.
|
|
104
|
-
if (cloneField.
|
|
105
|
-
var
|
|
106
|
-
if (
|
|
107
|
-
line += " CONSTRAINT \"".concat(
|
|
103
|
+
if (cloneField.checkIds && cloneField.checkIds.length > 0) {
|
|
104
|
+
if (cloneField.checkIds.length === 1) {
|
|
105
|
+
var check = model.checks[cloneField.checkIds[0]];
|
|
106
|
+
if (check.name) {
|
|
107
|
+
line += " CONSTRAINT \"".concat(check.name, "\"");
|
|
108
108
|
}
|
|
109
|
-
line += " CHECK (".concat(
|
|
109
|
+
line += " CHECK (".concat(check.expression, ")");
|
|
110
110
|
} else {
|
|
111
|
-
var
|
|
112
|
-
var
|
|
113
|
-
return "(".concat(
|
|
111
|
+
var checkExpressions = cloneField.checkIds.map(function (checkId) {
|
|
112
|
+
var check = model.checks[checkId];
|
|
113
|
+
return "(".concat(check.expression, ")");
|
|
114
114
|
});
|
|
115
|
-
line += " CHECK (".concat(
|
|
115
|
+
line += " CHECK (".concat(checkExpressions.join(' AND '), ")");
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
return line;
|
|
@@ -146,19 +146,19 @@ var OracleExporter = /*#__PURE__*/function () {
|
|
|
146
146
|
return lines;
|
|
147
147
|
}
|
|
148
148
|
}, {
|
|
149
|
-
key: "
|
|
150
|
-
value: function
|
|
149
|
+
key: "getCheckLines",
|
|
150
|
+
value: function getCheckLines(tableId, model) {
|
|
151
151
|
var table = model.tables[tableId];
|
|
152
|
-
if (!table.
|
|
152
|
+
if (!table.checkIds || table.checkIds.length === 0) {
|
|
153
153
|
return [];
|
|
154
154
|
}
|
|
155
|
-
var lines = table.
|
|
156
|
-
var
|
|
155
|
+
var lines = table.checkIds.map(function (checkId) {
|
|
156
|
+
var check = model.checks[checkId];
|
|
157
157
|
var line = '';
|
|
158
|
-
if (
|
|
159
|
-
line = "CONSTRAINT \"".concat(
|
|
158
|
+
if (check.name) {
|
|
159
|
+
line = "CONSTRAINT \"".concat(check.name, "\" ");
|
|
160
160
|
}
|
|
161
|
-
line += "CHECK (".concat(
|
|
161
|
+
line += "CHECK (".concat(check.expression, ")");
|
|
162
162
|
return line;
|
|
163
163
|
});
|
|
164
164
|
return lines;
|
|
@@ -169,12 +169,12 @@ var OracleExporter = /*#__PURE__*/function () {
|
|
|
169
169
|
var _this = this;
|
|
170
170
|
var tableContentArr = tableIds.map(function (tableId) {
|
|
171
171
|
var fieldContents = _this.getFieldLines(tableId, model);
|
|
172
|
-
var
|
|
172
|
+
var checkContents = _this.getCheckLines(tableId, model);
|
|
173
173
|
var compositePKs = _this.getCompositePKs(tableId, model);
|
|
174
174
|
return {
|
|
175
175
|
tableId: tableId,
|
|
176
176
|
fieldContents: fieldContents,
|
|
177
|
-
|
|
177
|
+
checkContents: checkContents,
|
|
178
178
|
compositePKs: compositePKs
|
|
179
179
|
};
|
|
180
180
|
});
|
|
@@ -186,7 +186,7 @@ var OracleExporter = /*#__PURE__*/function () {
|
|
|
186
186
|
var _this2 = this;
|
|
187
187
|
var tableContentList = this.getTableContents(tableIds, model);
|
|
188
188
|
var tableStrs = tableContentList.map(function (tableContent) {
|
|
189
|
-
var content = [].concat(_toConsumableArray(tableContent.fieldContents), _toConsumableArray(tableContent.
|
|
189
|
+
var content = [].concat(_toConsumableArray(tableContent.fieldContents), _toConsumableArray(tableContent.checkContents), _toConsumableArray(tableContent.compositePKs));
|
|
190
190
|
var table = model.tables[tableContent.tableId];
|
|
191
191
|
var schema = model.schemas[table.schemaId];
|
|
192
192
|
var tableName = _this2.buildTableNameWithSchema(model, schema, table);
|
|
@@ -122,19 +122,19 @@ var PostgresExporter = /*#__PURE__*/function () {
|
|
|
122
122
|
if (field.not_null) {
|
|
123
123
|
line += ' NOT NULL';
|
|
124
124
|
}
|
|
125
|
-
if (field.
|
|
126
|
-
if (field.
|
|
127
|
-
var
|
|
128
|
-
if (
|
|
129
|
-
line += " CONSTRAINT \"".concat(
|
|
125
|
+
if (field.checkIds && field.checkIds.length > 0) {
|
|
126
|
+
if (field.checkIds.length === 1) {
|
|
127
|
+
var check = model.checks[field.checkIds[0]];
|
|
128
|
+
if (check.name) {
|
|
129
|
+
line += " CONSTRAINT \"".concat(check.name, "\"");
|
|
130
130
|
}
|
|
131
|
-
line += " CHECK (".concat(
|
|
131
|
+
line += " CHECK (".concat(check.expression, ")");
|
|
132
132
|
} else {
|
|
133
|
-
var
|
|
134
|
-
var
|
|
135
|
-
return "(".concat(
|
|
133
|
+
var checkExpressions = field.checkIds.map(function (checkId) {
|
|
134
|
+
var check = model.checks[checkId];
|
|
135
|
+
return "(".concat(check.expression, ")");
|
|
136
136
|
});
|
|
137
|
-
line += " CHECK (".concat(
|
|
137
|
+
line += " CHECK (".concat(checkExpressions.join(' AND '), ")");
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
if (field.dbdefault) {
|
|
@@ -177,19 +177,19 @@ var PostgresExporter = /*#__PURE__*/function () {
|
|
|
177
177
|
return lines;
|
|
178
178
|
}
|
|
179
179
|
}, {
|
|
180
|
-
key: "
|
|
181
|
-
value: function
|
|
180
|
+
key: "getCheckLines",
|
|
181
|
+
value: function getCheckLines(tableId, model) {
|
|
182
182
|
var table = model.tables[tableId];
|
|
183
|
-
if (!table.
|
|
183
|
+
if (!table.checkIds || table.checkIds.length === 0) {
|
|
184
184
|
return [];
|
|
185
185
|
}
|
|
186
|
-
var lines = table.
|
|
187
|
-
var
|
|
186
|
+
var lines = table.checkIds.map(function (checkId) {
|
|
187
|
+
var check = model.checks[checkId];
|
|
188
188
|
var line = '';
|
|
189
|
-
if (
|
|
190
|
-
line = "CONSTRAINT \"".concat(
|
|
189
|
+
if (check.name) {
|
|
190
|
+
line = "CONSTRAINT \"".concat(check.name, "\" ");
|
|
191
191
|
}
|
|
192
|
-
line += "CHECK (".concat(
|
|
192
|
+
line += "CHECK (".concat(check.expression, ")");
|
|
193
193
|
return line;
|
|
194
194
|
});
|
|
195
195
|
return lines;
|
|
@@ -199,12 +199,12 @@ var PostgresExporter = /*#__PURE__*/function () {
|
|
|
199
199
|
value: function getTableContentArr(tableIds, model, enumSet) {
|
|
200
200
|
var tableContentArr = tableIds.map(function (tableId) {
|
|
201
201
|
var fieldContents = PostgresExporter.getFieldLines(tableId, model, enumSet);
|
|
202
|
-
var
|
|
202
|
+
var checkContents = PostgresExporter.getCheckLines(tableId, model);
|
|
203
203
|
var compositePKs = PostgresExporter.getCompositePKs(tableId, model);
|
|
204
204
|
return {
|
|
205
205
|
tableId: tableId,
|
|
206
206
|
fieldContents: fieldContents,
|
|
207
|
-
|
|
207
|
+
checkContents: checkContents,
|
|
208
208
|
compositePKs: compositePKs
|
|
209
209
|
};
|
|
210
210
|
});
|
|
@@ -215,7 +215,7 @@ var PostgresExporter = /*#__PURE__*/function () {
|
|
|
215
215
|
value: function exportTables(tableIds, model, enumSet) {
|
|
216
216
|
var tableContentArr = PostgresExporter.getTableContentArr(tableIds, model, enumSet);
|
|
217
217
|
var tableStrs = tableContentArr.map(function (tableContent) {
|
|
218
|
-
var content = [].concat(_toConsumableArray(tableContent.fieldContents), _toConsumableArray(tableContent.
|
|
218
|
+
var content = [].concat(_toConsumableArray(tableContent.fieldContents), _toConsumableArray(tableContent.checkContents), _toConsumableArray(tableContent.compositePKs));
|
|
219
219
|
var table = model.tables[tableContent.tableId];
|
|
220
220
|
var schema = model.schemas[table.schemaId];
|
|
221
221
|
var tableStr = "CREATE TABLE ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "\"".concat(schema.name, "\".") : '', "\"").concat(table.name, "\" (\n").concat(content.map(function (line) {
|
|
@@ -53,19 +53,19 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
53
53
|
if (field.increment) {
|
|
54
54
|
line += ' IDENTITY(1, 1)';
|
|
55
55
|
}
|
|
56
|
-
if (field.
|
|
57
|
-
if (field.
|
|
58
|
-
var
|
|
59
|
-
if (
|
|
60
|
-
line += " CONSTRAINT [".concat(
|
|
56
|
+
if (field.checkIds && field.checkIds.length > 0) {
|
|
57
|
+
if (field.checkIds.length === 1) {
|
|
58
|
+
var check = model.checks[field.checkIds[0]];
|
|
59
|
+
if (check.name) {
|
|
60
|
+
line += " CONSTRAINT [".concat(check.name, "]");
|
|
61
61
|
}
|
|
62
|
-
line += " CHECK (".concat(
|
|
62
|
+
line += " CHECK (".concat(check.expression, ")");
|
|
63
63
|
} else {
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
return "(".concat(
|
|
64
|
+
var checkExpressions = field.checkIds.map(function (checkId) {
|
|
65
|
+
var check = model.checks[checkId];
|
|
66
|
+
return "(".concat(check.expression, ")");
|
|
67
67
|
});
|
|
68
|
-
line += " CHECK (".concat(
|
|
68
|
+
line += " CHECK (".concat(checkExpressions.join(' AND '), ")");
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
if (field.dbdefault) {
|
|
@@ -108,19 +108,19 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
108
108
|
return lines;
|
|
109
109
|
}
|
|
110
110
|
}, {
|
|
111
|
-
key: "
|
|
112
|
-
value: function
|
|
111
|
+
key: "getCheckLines",
|
|
112
|
+
value: function getCheckLines(tableId, model) {
|
|
113
113
|
var table = model.tables[tableId];
|
|
114
|
-
if (!table.
|
|
114
|
+
if (!table.checkIds || table.checkIds.length === 0) {
|
|
115
115
|
return [];
|
|
116
116
|
}
|
|
117
|
-
var lines = table.
|
|
118
|
-
var
|
|
117
|
+
var lines = table.checkIds.map(function (checkId) {
|
|
118
|
+
var check = model.checks[checkId];
|
|
119
119
|
var line = '';
|
|
120
|
-
if (
|
|
121
|
-
line = "CONSTRAINT [".concat(
|
|
120
|
+
if (check.name) {
|
|
121
|
+
line = "CONSTRAINT [".concat(check.name, "] ");
|
|
122
122
|
}
|
|
123
|
-
line += "CHECK (".concat(
|
|
123
|
+
line += "CHECK (".concat(check.expression, ")");
|
|
124
124
|
return line;
|
|
125
125
|
});
|
|
126
126
|
return lines;
|
|
@@ -130,12 +130,12 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
130
130
|
value: function getTableContentArr(tableIds, model) {
|
|
131
131
|
var tableContentArr = tableIds.map(function (tableId) {
|
|
132
132
|
var fieldContents = SqlServerExporter.getFieldLines(tableId, model);
|
|
133
|
-
var
|
|
133
|
+
var checkContents = SqlServerExporter.getCheckLines(tableId, model);
|
|
134
134
|
var compositePKs = SqlServerExporter.getCompositePKs(tableId, model);
|
|
135
135
|
return {
|
|
136
136
|
tableId: tableId,
|
|
137
137
|
fieldContents: fieldContents,
|
|
138
|
-
|
|
138
|
+
checkContents: checkContents,
|
|
139
139
|
compositePKs: compositePKs
|
|
140
140
|
};
|
|
141
141
|
});
|
|
@@ -146,7 +146,7 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
146
146
|
value: function exportTables(tableIds, model) {
|
|
147
147
|
var tableContentArr = SqlServerExporter.getTableContentArr(tableIds, model);
|
|
148
148
|
var tableStrs = tableContentArr.map(function (tableContent) {
|
|
149
|
-
var content = [].concat(_toConsumableArray(tableContent.fieldContents), _toConsumableArray(tableContent.
|
|
149
|
+
var content = [].concat(_toConsumableArray(tableContent.fieldContents), _toConsumableArray(tableContent.checkContents), _toConsumableArray(tableContent.compositePKs));
|
|
150
150
|
var table = model.tables[tableContent.tableId];
|
|
151
151
|
var schema = model.schemas[table.schemaId];
|
|
152
152
|
var tableStr = "CREATE TABLE ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "[".concat(schema.name, "].") : '', "[").concat(table.name, "] (\n").concat(content.map(function (line) {
|
|
@@ -280,7 +280,7 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
280
280
|
switch (comment.type) {
|
|
281
281
|
case 'table':
|
|
282
282
|
{
|
|
283
|
-
line +=
|
|
283
|
+
line += '@name = N\'Table_Description\',\n';
|
|
284
284
|
line += "@value = '".concat(table.note.replace(/'/g, "''"), "',\n");
|
|
285
285
|
line += "@level0type = N'Schema', @level0name = '".concat((0, _utils.shouldPrintSchema)(schema, model) ? "".concat(schema.name) : 'dbo', "',\n");
|
|
286
286
|
line += "@level1type = N'Table', @level1name = '".concat(table.name, "';\n");
|
|
@@ -289,7 +289,7 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
289
289
|
case 'column':
|
|
290
290
|
{
|
|
291
291
|
var field = model.fields[comment.fieldId];
|
|
292
|
-
line +=
|
|
292
|
+
line += '@name = N\'Column_Description\',\n';
|
|
293
293
|
line += "@value = '".concat(field.note.replace(/'/g, "''"), "',\n");
|
|
294
294
|
line += "@level0type = N'Schema', @level0name = '".concat((0, _utils.shouldPrintSchema)(schema, model) ? "".concat(schema.name) : 'dbo', "',\n");
|
|
295
295
|
line += "@level1type = N'Table', @level1name = '".concat(table.name, "',\n");
|
|
@@ -22,8 +22,8 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
22
22
|
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
23
23
|
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); }
|
|
24
24
|
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
25
|
-
var
|
|
26
|
-
function
|
|
25
|
+
var Check = /*#__PURE__*/function (_Element) {
|
|
26
|
+
function Check() {
|
|
27
27
|
var _this;
|
|
28
28
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
29
29
|
token = _ref.token,
|
|
@@ -34,8 +34,8 @@ var Constraint = /*#__PURE__*/function (_Element) {
|
|
|
34
34
|
column = _ref$column === void 0 ? null : _ref$column,
|
|
35
35
|
_ref$injectedPartial = _ref.injectedPartial,
|
|
36
36
|
injectedPartial = _ref$injectedPartial === void 0 ? null : _ref$injectedPartial;
|
|
37
|
-
_classCallCheck(this,
|
|
38
|
-
_this = _callSuper(this,
|
|
37
|
+
_classCallCheck(this, Check);
|
|
38
|
+
_this = _callSuper(this, Check, [token]);
|
|
39
39
|
_this.name = name;
|
|
40
40
|
_this.expression = expression;
|
|
41
41
|
_this.table = table;
|
|
@@ -45,11 +45,11 @@ var Constraint = /*#__PURE__*/function (_Element) {
|
|
|
45
45
|
_this.generateId();
|
|
46
46
|
return _this;
|
|
47
47
|
}
|
|
48
|
-
_inherits(
|
|
49
|
-
return _createClass(
|
|
48
|
+
_inherits(Check, _Element);
|
|
49
|
+
return _createClass(Check, [{
|
|
50
50
|
key: "generateId",
|
|
51
51
|
value: function generateId() {
|
|
52
|
-
this.id = this.dbState.generateId('
|
|
52
|
+
this.id = this.dbState.generateId('checkId');
|
|
53
53
|
}
|
|
54
54
|
}, {
|
|
55
55
|
key: "export",
|
|
@@ -77,10 +77,10 @@ var Constraint = /*#__PURE__*/function (_Element) {
|
|
|
77
77
|
}, {
|
|
78
78
|
key: "normalize",
|
|
79
79
|
value: function normalize(model) {
|
|
80
|
-
model.
|
|
80
|
+
model.checks[this.id] = _objectSpread(_objectSpread({
|
|
81
81
|
id: this.id
|
|
82
82
|
}, this.shallowExport()), this.exportParentIds());
|
|
83
83
|
}
|
|
84
84
|
}]);
|
|
85
85
|
}(_element["default"]);
|
|
86
|
-
var _default = exports["default"] =
|
|
86
|
+
var _default = exports["default"] = Check;
|
|
@@ -8,7 +8,7 @@ exports["default"] = void 0;
|
|
|
8
8
|
var _lodash = require("lodash");
|
|
9
9
|
var _element = _interopRequireDefault(require("./element"));
|
|
10
10
|
var _config = require("./config");
|
|
11
|
-
var
|
|
11
|
+
var _check = _interopRequireDefault(require("./check"));
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
13
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
14
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -38,8 +38,8 @@ var Field = /*#__PURE__*/function (_Element) {
|
|
|
38
38
|
note = _ref.note,
|
|
39
39
|
dbdefault = _ref.dbdefault,
|
|
40
40
|
increment = _ref.increment,
|
|
41
|
-
_ref$
|
|
42
|
-
|
|
41
|
+
_ref$checks = _ref.checks,
|
|
42
|
+
checks = _ref$checks === void 0 ? [] : _ref$checks,
|
|
43
43
|
_ref$table = _ref.table,
|
|
44
44
|
table = _ref$table === void 0 ? {} : _ref$table,
|
|
45
45
|
_ref$noteToken = _ref.noteToken,
|
|
@@ -66,7 +66,7 @@ var Field = /*#__PURE__*/function (_Element) {
|
|
|
66
66
|
_this.noteToken = note ? (0, _lodash.get)(note, 'token', noteToken) : null;
|
|
67
67
|
_this.dbdefault = dbdefault;
|
|
68
68
|
_this.increment = increment;
|
|
69
|
-
_this.
|
|
69
|
+
_this.checks = [];
|
|
70
70
|
_this.endpoints = [];
|
|
71
71
|
_this.table = table;
|
|
72
72
|
_this.injectedPartial = injectedPartial;
|
|
@@ -74,7 +74,7 @@ var Field = /*#__PURE__*/function (_Element) {
|
|
|
74
74
|
_this.dbState = _this.table.dbState;
|
|
75
75
|
_this.generateId();
|
|
76
76
|
_this.bindType();
|
|
77
|
-
_this.
|
|
77
|
+
_this.processChecks(checks);
|
|
78
78
|
return _this;
|
|
79
79
|
}
|
|
80
80
|
_inherits(Field, _Element);
|
|
@@ -149,8 +149,8 @@ var Field = /*#__PURE__*/function (_Element) {
|
|
|
149
149
|
dbdefault: this.dbdefault,
|
|
150
150
|
increment: this.increment,
|
|
151
151
|
injectedPartialId: (_this$injectedPartial = this.injectedPartial) === null || _this$injectedPartial === void 0 ? void 0 : _this$injectedPartial.id,
|
|
152
|
-
|
|
153
|
-
return
|
|
152
|
+
checkIds: this.checks.map(function (check) {
|
|
153
|
+
return check.id;
|
|
154
154
|
})
|
|
155
155
|
};
|
|
156
156
|
}
|
|
@@ -160,16 +160,16 @@ var Field = /*#__PURE__*/function (_Element) {
|
|
|
160
160
|
model.fields[this.id] = _objectSpread(_objectSpread(_objectSpread({
|
|
161
161
|
id: this.id
|
|
162
162
|
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds());
|
|
163
|
-
this.
|
|
164
|
-
return
|
|
163
|
+
this.checks.forEach(function (check) {
|
|
164
|
+
return check.normalize(model);
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
}, {
|
|
168
|
-
key: "
|
|
169
|
-
value: function
|
|
168
|
+
key: "processChecks",
|
|
169
|
+
value: function processChecks(checks) {
|
|
170
170
|
var _this2 = this;
|
|
171
|
-
|
|
172
|
-
_this2.
|
|
171
|
+
checks.forEach(function (check) {
|
|
172
|
+
_this2.checks.push(new _check["default"](_objectSpread(_objectSpread({}, check), {}, {
|
|
173
173
|
table: _this2.table,
|
|
174
174
|
column: _this2
|
|
175
175
|
})));
|