@ix-xs/node-comfort 1.0.55 → 1.0.56
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/package.json +1 -1
- package/src/localStorage.js +21 -10
package/package.json
CHANGED
package/src/localStorage.js
CHANGED
|
@@ -203,10 +203,10 @@ module.exports = class localStorage {
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
/**
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
* @param {string} tableName
|
|
207
|
+
* @param {object} data
|
|
208
|
+
* @param {object|null} where
|
|
209
|
+
*/
|
|
210
210
|
async set(tableName, data, where = null) {
|
|
211
211
|
try {
|
|
212
212
|
if (!this.#models.has(tableName)) {
|
|
@@ -215,14 +215,24 @@ module.exports = class localStorage {
|
|
|
215
215
|
|
|
216
216
|
const lookup = where ?? (data.id ? { id: data.id } : null);
|
|
217
217
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
218
|
+
let finalData = data;
|
|
219
|
+
|
|
220
|
+
if (lookup) {
|
|
221
|
+
const existing = await this.get(tableName, lookup);
|
|
222
|
+
|
|
223
|
+
if (existing && !existing.error) {
|
|
224
|
+
finalData = { ...existing, ...data };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const columns = Object.keys(finalData);
|
|
229
|
+
const placeholders = columns.map(() => "?").join(", ");
|
|
230
|
+
const sql = `INSERT OR REPLACE INTO ${tableName} (${columns.join(
|
|
231
|
+
", ",
|
|
232
|
+
)}) VALUES (${placeholders})`;
|
|
223
233
|
|
|
224
234
|
const stmt = this.#$.prepare(sql);
|
|
225
|
-
stmt.run(...Object.values(
|
|
235
|
+
stmt.run(...Object.values(finalData));
|
|
226
236
|
|
|
227
237
|
return { ok: true };
|
|
228
238
|
} catch (error) {
|
|
@@ -230,6 +240,7 @@ module.exports = class localStorage {
|
|
|
230
240
|
}
|
|
231
241
|
}
|
|
232
242
|
|
|
243
|
+
|
|
233
244
|
/**
|
|
234
245
|
* @param {string} tableName
|
|
235
246
|
* @param {object} where
|