Reading data from object stores

Whenever a connection is established, the onsuccess event is fired. Only read-write operations in the onupgradeneeded work because it won't be fired if the version number of the database is not increased.

As a matter of fact, we recommend changing the database schema from the onupgradeneeded event. When you're in onsuccess, perform only the CRUD operations (which are Create, Update, Retrieve, and Delete).

We can do our operations inside the success event with the following code:

const open = window.indexedDB.open("types", 1); // same database as aboveopen.onsuccess = () => {    const dbHandler = open.result;    const transaction = dbHandler.transaction(['frontend'], 'readonly'); const storeHandler = transaction.objectStore('frontend'); ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.