I'm making a tool for my own use that needs a simple database. This seems like a good chance to learn the HTML5 IndexedDB API, but it's important that I don't lose data at any point.
I suppose backing up the browser's profile directory would do for a backup, but I'd also like to potentially work with different computers so exporting and importing the database would be nice. Is there an easy way to export and import IndexedDB databases? Browser-specific solutions are ok.
No browser's devtools allow you to export or import an IndexedDB database (as of 2020–12–17), but you can invoke dexie and dexie-export-import on any page and make it do the export for you.
More specifically, IndexedDB data is stored in the browser profile folder.
Browsing your Database. Browsers make it trivially simple to view the contents of your store. First open up the developer console with F12 . On Chrome you will find it under the Application -> Storage -> IndexedDB .
There is nothing like this available in the pure IndexedDB spec, however, it's possible to write your own methods that will accomplish this.
The basic steps to import data are to
add
or put
operation)For exporting an object store you can:
onsuccess
callback to the request object to capture the row valuevar
.The final row will emit null
, which is a state you can watch for to figure out when the cursor has exhausted all its records and is done. When that happens, you can call an export callback passing the privileged array of objects representing a backup of your object store.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With