1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-13 13:05:00 -05:00
kaiwa/clientapp/storage/rosterver.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2013-09-05 19:53:23 -04:00
"use strict";
// SCHEMA
// jid: 'string',
// ver: 'string'
function RosterVerStorage(storage) {
this.storage = storage;
}
RosterVerStorage.prototype = {
constructor: {
value: RosterVerStorage
},
setup: function (db) {
if (db.objectStoreNames.contains('rosterver')) {
db.deleteObjectStore('rosterver');
}
2013-09-05 19:53:23 -04:00
db.createObjectStore('rosterver', {
keyPath: 'jid'
});
},
transaction: function (mode) {
var trans = this.storage.db.transaction('rosterver', mode);
return trans.objectStore('rosterver');
},
set: function (jid, ver, cb) {
cb = cb || function () {};
var data = {
jid: jid,
ver: ver
};
var request = this.transaction('readwrite').put(data);
request.onsuccess = function () {
cb(false, data);
};
request.onerror = cb;
},
get: function (jid, cb) {
cb = cb || function () {};
if (!jid) {
return cb('not-found');
}
var request = this.transaction('readonly').get(jid);
request.onsuccess = function (e) {
var res = request.result;
if (res === undefined) {
return cb('not-found');
}
cb(false, request.result);
};
request.onerror = cb;
},
remove: function (jid, cb) {
cb = cb || function () {};
var request = this.transaction('readwrite')['delete'](id);
request.onsuccess = function (e) {
cb(false, request.result);
};
request.onerror = cb;
}
};
module.exports = RosterVerStorage;