I implement some logging library for Chrome that when my webapp codes call console.log(message)
, I also write the message data into IndexedDB store, something like
const db = indexedDB.open("store", 1);
const transaction = db.transaction(['devlogs'], "readwrite");
const objectStore = transaction.objectStore('devlogs');
const log = {
timestamp: new Date(),
message,
level
};
await objectStore.add(log);
await transaction.done;
I also want my logging library to delete the old log, say 10 days ago, automatically.
I only have limited experience with IndexedDB, so to me, the simple way to do that is in the db’s onsuccess
handler I use a transaction to delete the old log.
But if there is another transaction to add the log, will the delete action cause the problem ? Is there a better place to delete the old log ?