Skip to content

Commit cf89b17

Browse files
delete bulk fix
1 parent 33425e4 commit cf89b17

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Magic.IndexedDb/wwwroot/magicDB.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,24 +433,42 @@ export async function bulkUpdateItem(items) {
433433
}
434434
}
435435

436+
async function getKeyArrayForDelete(dbName, storeName, keyData) {
437+
const keyInfo = await getPrimaryKey(dbName, storeName);
438+
439+
if (!keyInfo.isCompound) {
440+
return keyData.find(k => k.JsName === keyInfo.keys[0])?.Value;
441+
}
442+
443+
return keyInfo.keys.map(pk => {
444+
const part = keyData.find(k => k.JsName === pk);
445+
if (!part) throw new Error(`Missing key part: ${pk}`);
446+
return part.Value;
447+
});
448+
}
436449

437450
/**
438451
* Deletes multiple items, supporting single and compound keys.
439452
*/
440453
export async function bulkDelete(dbName, storeName, items) {
441454
const table = await getTable(dbName, storeName);
442455
try {
443-
const formattedKeys = await Promise.all(items.map(async item => await formatKey(dbName, storeName, item)));
456+
const formattedKeys = await Promise.all(
457+
items.map(item => getKeyArrayForDelete(dbName, storeName, item))
458+
);
444459

460+
console.log('Keys to delete:', formattedKeys);
445461
await table.bulkDelete(formattedKeys);
446462
return items.length;
447463
} catch (e) {
448-
console.error(e);
464+
console.error('bulkDelete error:', e);
449465
throw new Error('Some items could not be deleted');
450466
}
451467
}
452468

453469

470+
471+
454472
/**
455473
* Deletes a single item.
456474
*/

0 commit comments

Comments
 (0)