@nest-omni/core 4.1.3-0 → 4.1.3-1
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.
|
@@ -171,44 +171,13 @@ const insertWithPk = function (entity) {
|
|
|
171
171
|
if (columnName) {
|
|
172
172
|
columnNames.push(columnName);
|
|
173
173
|
columnValues.push(value);
|
|
174
|
-
valuePlaceholders.push(
|
|
174
|
+
valuePlaceholders.push(`?`);
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
-
const
|
|
178
|
-
const databaseType = connection.options.type;
|
|
177
|
+
const sql = `INSERT INTO ${tableName} (${columnNames.join(', ')}) VALUES (${valuePlaceholders.join(', ')})`;
|
|
179
178
|
try {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const sql = `INSERT INTO ${tableName} (${columnNames.join(', ')}) VALUES (${valuePlaceholders.join(', ')}) RETURNING *`;
|
|
183
|
-
const queryResult = yield this.query(sql, columnValues);
|
|
184
|
-
result = queryResult;
|
|
185
|
-
}
|
|
186
|
-
else if (['mysql', 'mariadb'].includes(databaseType)) {
|
|
187
|
-
const insertSql = `INSERT INTO ${tableName} (${columnNames.join(', ')}) VALUES (${valuePlaceholders.join(', ')})`;
|
|
188
|
-
yield this.query(insertSql, columnValues);
|
|
189
|
-
const pkFields = this.getPrimaryKeyFields();
|
|
190
|
-
const whereConditions = pkFields.map(pkField => {
|
|
191
|
-
const column = columns.find(col => col.propertyName === pkField);
|
|
192
|
-
const dbName = (column === null || column === void 0 ? void 0 : column.databaseName) || pkField;
|
|
193
|
-
return `${dbName} = ?`;
|
|
194
|
-
});
|
|
195
|
-
const pkValues = pkFields.map(pkField => entity[pkField]);
|
|
196
|
-
const selectSql = `SELECT * FROM ${tableName} WHERE ${whereConditions.join(' AND ')}`;
|
|
197
|
-
const queryResult = yield this.query(selectSql, pkValues);
|
|
198
|
-
result = queryResult;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
const sql = `INSERT INTO ${tableName} (${columnNames.join(', ')}) VALUES (${valuePlaceholders.join(', ')})`;
|
|
202
|
-
yield this.query(sql, columnValues);
|
|
203
|
-
return entity;
|
|
204
|
-
}
|
|
205
|
-
if (result && result.length > 0) {
|
|
206
|
-
return result[0];
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
console.warn(`Native SQL insert completed but no result returned for ${tableName}, falling back to regular save`);
|
|
210
|
-
return yield this.save(entity);
|
|
211
|
-
}
|
|
179
|
+
const result = yield this.query(sql, columnValues);
|
|
180
|
+
return result[0];
|
|
212
181
|
}
|
|
213
182
|
catch (error) {
|
|
214
183
|
console.warn(`Native SQL insert failed for ${tableName}, falling back to regular save:`, error);
|
package/package.json
CHANGED