Add BATCH_WRITING to database.worker

This commit is contained in:
Sosthene 2025-07-01 18:01:42 +02:00
parent 5a98fac745
commit 1dad1d4e2b

View File

@ -45,6 +45,21 @@ self.addEventListener('message', async (event) => {
} catch (error) {
event.ports[0].postMessage({ status: 'error', message: error.message });
}
} else if (data.type === 'BATCH_WRITING') {
const { storeName, objects } = data.payload;
const db = await openDatabase();
const tx = db.transaction(storeName, 'readwrite');
const store = tx.objectStore(storeName);
for (const { key, object } of objects) {
if (key) {
await store.put(object, key);
} else {
await store.put(object);
}
}
await tx.done;
}
});