1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | class SchemaOperator {
|
4 | |
5 |
|
6 |
|
7 | removePrimaryKeys(tableName, data) {
|
8 | const filtered = JSON.parse(JSON.stringify(data));
|
9 | this.getPrimaryKeyNames(tableName).forEach(pk => delete filtered[pk]);
|
10 | return filtered;
|
11 | }
|
12 | retainPrimaryKeys(tableName, data) {
|
13 | const keyData = {};
|
14 | this.getPrimaryKeyNames(tableName).forEach(key => keyData[key] = data[key]);
|
15 | return keyData;
|
16 | }
|
17 | getPkCols(tableName) {
|
18 | if (!tableName) {
|
19 | return [];
|
20 | }
|
21 | const cols = [];
|
22 | const table = this.definition.tables[tableName];
|
23 | for (const key in table) {
|
24 | if (table[key].isPrimary) {
|
25 | cols.push(table[key]);
|
26 | }
|
27 | }
|
28 | return cols;
|
29 | }
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | stripNoneBelonging(tableName, data) {
|
37 | const table = this.definition.tables[tableName];
|
38 | const copy = {};
|
39 | Object.keys(data).filter(key => !!table[key]).forEach(key => {
|
40 | copy[key] = data[key];
|
41 | });
|
42 | return copy;
|
43 | }
|
44 | |
45 |
|
46 |
|
47 |
|
48 | getPrimaryKeyNames(tableName) {
|
49 | const cols = this.getPkCols(tableName);
|
50 | if (!cols || cols.length === 0) {
|
51 | return [];
|
52 | }
|
53 | return cols.map(col => col.field);
|
54 | }
|
55 | }
|
56 | exports.SchemaOperator = SchemaOperator;
|
57 |
|
\ | No newline at end of file |