Commit 6573ab6c authored by Tristan Cavelier's avatar Tristan Cavelier

post method added to indexeddbstorage

parent 8fa98134
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
}(["jio", "rsvp"], function (jIO, RSVP) { }(["jio", "rsvp"], function (jIO, RSVP) {
"use strict"; "use strict";
var Promise = RSVP.Promise; var Promise = RSVP.Promise, generateUuid = jIO.util.generateUuid;
// XXX doc string // XXX doc string
function metadataObjectToString(value) { function metadataObjectToString(value) {
...@@ -287,6 +287,30 @@ ...@@ -287,6 +287,30 @@
}, command.error, command.notify); }, command.error, command.notify);
}; };
// XXX doc string
IndexedDBStorage.prototype.post = function (command, metadata) {
var promise;
promise = this.createDBIfNecessary();
if (metadata._id) {
promise = promise.
then(this.getMetadata.bind(this, metadata._id)).
then(function () {
throw "conflict";
}, function (error) {
if (error === "not_found") {
return;
}
throw error;
});
} else {
metadata._id = generateUuid();
}
promise.then(this.putMetadata.bind(this, metadata)).
then(function () {
command.success({"id": metadata._id});
}, command.error, command.notify);
};
// XXX doc string // XXX doc string
IndexedDBStorage.prototype.put = function (command, metadata) { IndexedDBStorage.prototype.put = function (command, metadata) {
var status; var status;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment