0
private get ctxMessage() {
    const messageTransaction = this.db.transaction('messages', 'readwrite');
    const messageStore = messageTransaction.objectStore('messages');
    return { messageTransaction, messageStore };
}


private async getAllMessage(message: Message) {
    const { messageStore ,messageTransaction } = this.ctxMessage;
    const result =  await messageStore.getAll();
    return result
}

Showing transaction is not active when I try to call getAllMessage method.

I am using idb npm package

1 Answers1

2

The call to getAll must occur within the same event loop iteration as db.transaction(...) because a transaction completes when no pending requests are detected at the end of the current event loop iteration. This error occurs because you are trying to start an IDBRequest on a transaction that has already completed and is therefore no longer active. To fix the error, revise the code to ensure that getAll is called immediately after creating the transaction. One simple way to do this is to just create a new transaction every time you need to call getAll.

Josh
  • 17,834
  • 7
  • 50
  • 68