1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-14 21:45:08 -05:00
kaiwa/clientapp/storage/rosterver.js
2013-09-05 16:53:23 -07:00

64 lines
1.5 KiB
JavaScript

"use strict";
// SCHEMA
// jid: 'string',
// ver: 'string'
function RosterVerStorage(storage) {
this.storage = storage;
}
RosterVerStorage.prototype = {
constructor: {
value: RosterVerStorage
},
setup: function (db) {
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;