Creating a database
Before we can store any objects in our database, we need to create the database first. This isn't as simple as createDatabase
or even an openDatabase
operation. Due to the asynchronous nature of IndexedDB and the fact that various browsers and platforms have used prefixed versions of IndexedDB, the process is actually a bit more complex.
Note
The snippets in this section are located at snippets/07/ex1-create-database/*
in the code package of this book. When using the interactive snippet playgroundselect 7: IndexedDB and the examples from 1a to 1c.
Here's an example:
// Example Snippet 1a // IndexedDB has been prefixed, so we need to get the prefixed // version if the non-prefixed versionis not available. from: // https://developer.mozilla.org/en- // US/docs/Web/API/IndexedDB_API/Using_IndexedDB let indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; //[1] function openDatabase({name, version, onopen, onerror...