Skip to content

Commit

Permalink
Re-add upsert.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Mar 1, 2016
1 parent daa12aa commit d72e429
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions datastore/concepts.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,27 @@ Entity.prototype.testBasicEntity = function(callback) {
}, callback);
};

Entity.prototype.testUpsert = function(callback) {
var taskKey = this.getIncompleteKey();
var task = this.getTask();

// [START upsert]
datastore.upsert({
key: taskKey,
data: task
}, function(err) {
if (!err) {
// Task inserted successfully.
}
});
// [END upsert]

this.datastore.upsert({
key: this.datastore.key(['Task', 1]),
data: task
}, callback);
};

Entity.prototype.testInsert = function(callback) {
var taskKey = this.getIncompleteKey();
var task = this.getTask();
Expand Down
6 changes: 6 additions & 0 deletions test/datastore/entity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ describe('datastore/concepts/entity', function () {
});
});

describe('testUpsert', function() {
it('saves with an upsert', function(done) {
entity.testUpsert(done);
});
});

describe('testInsert', function() {
it('saves with an insert', function(done) {
entity.testInsert(done);
Expand Down

0 comments on commit d72e429

Please sign in to comment.