-
-
Notifications
You must be signed in to change notification settings - Fork 641
Version
David Fahlander edited this page Mar 26, 2014
·
7 revisions
An instance of a Version class can only be returned from the Dexie.version() method. Use it to define the schema and any upgrader function for that specific version.
var db = new Dexie("FriendsAndPetsDatabase");
db.version(2).stores({
friends: "++id,name,birthdate,sex",
pets: "++id,name,kind"
}).upgrade (function (trans) {
var YEAR = 365 * 24 * 60 * 60 * 1000;
trans.friends.each (function (friend, cursor) {
friend.birthdate = new Date(Date.now() - (friend.age * YEAR));
delete friend.age;
cursor.update (friend);
});
});
// Always keep the declarations previous versions as long as there might be users having them running.
db.version(1).stores({
friends: "++id,name,age,sex",
pets: "++id,name,kind"
});
db.open();
Specify the database schema (object stores and indexes) for a certain version.
Specify an upgrade function for upgrading between previous version to this one.
Dexie.js - minimalistic and bullet proof indexedDB library