-
-
Notifications
You must be signed in to change notification settings - Fork 641
Migrating existing DB to Dexie
Dexie can open any indexedDB database, no matter if you've created it via raw indexedDB or another indexedDB wrapper. It's very simple:
- Publish this HTML page somewhere in the same origin as your app resides (such as http://locahost:8080/dump-databases.html).
- Use Chrome or Opera to navigate to your existing app (to ensure it will create the database your way). Then just navigate to the dump-database.html page and copy the generated code from the output and your with your app.
That's all. After that, you may even use Dexie and your own raw indexedDB code / other wrapper in parallell if you like.
NOTE: Dexie will use the version number divided by 10. Nothing to be afraid of. It just is like that. Here's an explanation.
A log window will display the Dexie-code required to open it. It will show something like the following:
Dumping Databases
=================
var db = new Dexie('MyDB');
db.version(1).stores({
friends: '++id,name,shoeSize'
});
var db = new Dexie('someDB');
db.version(3).stores({
someTable: '++id,someIndex'
});
var db = new Dexie('todos-dexie');
db.version(1).stores({
todo: '_id'
});
Finished dumping databases
==========================
You can always go back to not using Dexie if you later on decides so, or you could run parts of the code through Dexie and parts through the raw indexedDB API or other wrapper.
If un-migrating, just be aware of the version multiplied by 10 thingie. If you're on version(2) in Dexie, your raw database would be on version 20.
DISCLAIMBER: If you've been using an indexedDB libraries that maintains complementary metadata (PouchDB and Lovefield for example), be cautious that those libs may not work well after having played with their data using Dexie.
Happy migration!
Dexie.js - minimalistic and bullet proof indexedDB library