Add BATCH_WRITING to database.worker
This commit is contained in:
parent
5a98fac745
commit
1dad1d4e2b
@ -45,6 +45,21 @@ self.addEventListener('message', async (event) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
event.ports[0].postMessage({ status: 'error', message: error.message });
|
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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user