version-storage
v0.0.7
Published
localStorage like, fileSystem/localStorage based storage with upgrade
Downloads
2
Readme
version-storage
localStorage like, fileSystem/localStorage based storage with upgrade.
Usage
var upgrade = function(storage) {
var oldVersion = storage.version;
if(oldVersion < 1) {
// Version 1 is the first version of the database.
storage.setItem('hello', '[1, 2, 3]');
}
if(oldVersion < 2) {
// Version 2 changes the data structure of `hello`
var hello = storage.getItem('hello');
// do some remaping
storage.setItem('hello', newhello);
}
if(oldVersion < 3) {
// Version 3 changes the name of `hello`
var hello = storage.getItem('hello');
storage.removeItem('hello');
storage.setItem('world', hello);
}
storage.setVersion(3);
};
var storage = new VersionStorage('kizz/file', upgrade);
var sth = storage.getItem('sth');
// for nodejs
var FsStroage = require('fs-storage');
var fsStorage = new Storage('./storage/');
var storage = new VersionStorage('kizz/file', {storage: fsStorage}, upgrade);
var sth = storage.getItem('sth');