sqlmorpheus 0.2.2 → 0.2.4
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/dist/index.js +17 -10
- package/dist/index.mjs +17 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -82,10 +82,12 @@ var TableObj = class _TableObj {
|
|
|
82
82
|
if (value instanceof Date) {
|
|
83
83
|
dataType = "date";
|
|
84
84
|
break;
|
|
85
|
-
} else {
|
|
85
|
+
} else if (value !== null) {
|
|
86
86
|
Logger.warn(`${key} was skipped because its type (${typeof value}) is not supported`);
|
|
87
87
|
return null;
|
|
88
88
|
}
|
|
89
|
+
dataType = "string";
|
|
90
|
+
break;
|
|
89
91
|
case "undefined":
|
|
90
92
|
case "symbol":
|
|
91
93
|
Logger.warn(`${key} was skipped because its type (${typeof value}) is not supported`);
|
|
@@ -124,7 +126,7 @@ var TableObj = class _TableObj {
|
|
|
124
126
|
return this;
|
|
125
127
|
}
|
|
126
128
|
dataType(column, type) {
|
|
127
|
-
this.tableStructure.columns[column.toString()].
|
|
129
|
+
this.tableStructure.columns[column.toString()].inputType = type;
|
|
128
130
|
return this;
|
|
129
131
|
}
|
|
130
132
|
maxCharacterLength(column, max) {
|
|
@@ -178,17 +180,19 @@ var TableStructureGenerator = class {
|
|
|
178
180
|
generateTableStructure() {
|
|
179
181
|
const tables = {};
|
|
180
182
|
for (const table of this.dbInstructions.tables) {
|
|
183
|
+
let structure;
|
|
181
184
|
if (TableObj.isTableObj(table)) {
|
|
185
|
+
structure = table.tableStructure;
|
|
182
186
|
tables[table.tableName] = table.tableStructure;
|
|
183
187
|
} else {
|
|
184
188
|
const classTable = table;
|
|
185
|
-
|
|
189
|
+
structure = getTableStructure(classTable);
|
|
186
190
|
tables[classTable.name] = structure;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
191
|
+
}
|
|
192
|
+
for (const key in structure.columns) {
|
|
193
|
+
const entry = structure.columns[key];
|
|
194
|
+
entry.defaultValue = entry.inputDefaultValue === null ? this.dialect.types.null : this.dialect.formatValueToSql(entry.inputDefaultValue, entry.inputType);
|
|
195
|
+
entry.type = this.dialect.getSqlType(entry.inputType, entry);
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
return tables;
|
|
@@ -984,12 +988,15 @@ function TableClass(tableName, primaryKey) {
|
|
|
984
988
|
foreignKey.toTable = tableName;
|
|
985
989
|
}
|
|
986
990
|
}
|
|
987
|
-
|
|
988
|
-
|
|
991
|
+
const obj = new table();
|
|
992
|
+
for (const key in obj) {
|
|
993
|
+
const value = obj[key];
|
|
989
994
|
const existingEntry = tableStructure.columns[key];
|
|
990
995
|
const defaultEntry = TableObj.getColumnEntry(key, value);
|
|
991
996
|
if (!defaultEntry)
|
|
992
997
|
continue;
|
|
998
|
+
if (key == primaryKey)
|
|
999
|
+
defaultEntry.isPrimaryKey = true;
|
|
993
1000
|
tableStructure.columns[key] = {
|
|
994
1001
|
...defaultEntry,
|
|
995
1002
|
...existingEntry
|
package/dist/index.mjs
CHANGED
|
@@ -48,10 +48,12 @@ var TableObj = class _TableObj {
|
|
|
48
48
|
if (value instanceof Date) {
|
|
49
49
|
dataType = "date";
|
|
50
50
|
break;
|
|
51
|
-
} else {
|
|
51
|
+
} else if (value !== null) {
|
|
52
52
|
Logger.warn(`${key} was skipped because its type (${typeof value}) is not supported`);
|
|
53
53
|
return null;
|
|
54
54
|
}
|
|
55
|
+
dataType = "string";
|
|
56
|
+
break;
|
|
55
57
|
case "undefined":
|
|
56
58
|
case "symbol":
|
|
57
59
|
Logger.warn(`${key} was skipped because its type (${typeof value}) is not supported`);
|
|
@@ -90,7 +92,7 @@ var TableObj = class _TableObj {
|
|
|
90
92
|
return this;
|
|
91
93
|
}
|
|
92
94
|
dataType(column, type) {
|
|
93
|
-
this.tableStructure.columns[column.toString()].
|
|
95
|
+
this.tableStructure.columns[column.toString()].inputType = type;
|
|
94
96
|
return this;
|
|
95
97
|
}
|
|
96
98
|
maxCharacterLength(column, max) {
|
|
@@ -144,17 +146,19 @@ var TableStructureGenerator = class {
|
|
|
144
146
|
generateTableStructure() {
|
|
145
147
|
const tables = {};
|
|
146
148
|
for (const table of this.dbInstructions.tables) {
|
|
149
|
+
let structure;
|
|
147
150
|
if (TableObj.isTableObj(table)) {
|
|
151
|
+
structure = table.tableStructure;
|
|
148
152
|
tables[table.tableName] = table.tableStructure;
|
|
149
153
|
} else {
|
|
150
154
|
const classTable = table;
|
|
151
|
-
|
|
155
|
+
structure = getTableStructure(classTable);
|
|
152
156
|
tables[classTable.name] = structure;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
157
|
+
}
|
|
158
|
+
for (const key in structure.columns) {
|
|
159
|
+
const entry = structure.columns[key];
|
|
160
|
+
entry.defaultValue = entry.inputDefaultValue === null ? this.dialect.types.null : this.dialect.formatValueToSql(entry.inputDefaultValue, entry.inputType);
|
|
161
|
+
entry.type = this.dialect.getSqlType(entry.inputType, entry);
|
|
158
162
|
}
|
|
159
163
|
}
|
|
160
164
|
return tables;
|
|
@@ -950,12 +954,15 @@ function TableClass(tableName, primaryKey) {
|
|
|
950
954
|
foreignKey.toTable = tableName;
|
|
951
955
|
}
|
|
952
956
|
}
|
|
953
|
-
|
|
954
|
-
|
|
957
|
+
const obj = new table();
|
|
958
|
+
for (const key in obj) {
|
|
959
|
+
const value = obj[key];
|
|
955
960
|
const existingEntry = tableStructure.columns[key];
|
|
956
961
|
const defaultEntry = TableObj.getColumnEntry(key, value);
|
|
957
962
|
if (!defaultEntry)
|
|
958
963
|
continue;
|
|
964
|
+
if (key == primaryKey)
|
|
965
|
+
defaultEntry.isPrimaryKey = true;
|
|
959
966
|
tableStructure.columns[key] = {
|
|
960
967
|
...defaultEntry,
|
|
961
968
|
...existingEntry
|