Add method 'createItem' to DB plugins
This commit is contained in:
parent
126a57d5ab
commit
5eade81294
4 changed files with 34 additions and 0 deletions
|
|
@ -16,6 +16,16 @@ LocalStorage.prototype.getItem = function(k,cb) {
|
|||
return cb(null, localStorage.getItem(k));
|
||||
};
|
||||
|
||||
/**
|
||||
* Same as setItem, but fails if an item already exists
|
||||
*/
|
||||
LocalStorage.prototype.createItem = function(name, value, callback) {
|
||||
if (localStorage.getItem(name)) {
|
||||
return callback('EEXISTS');
|
||||
}
|
||||
return this.setItem(name, value, callback);
|
||||
};
|
||||
|
||||
LocalStorage.prototype.setItem = function(k,v,cb) {
|
||||
localStorage.setItem(k,v);
|
||||
return cb();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue