From fd6727776db8da419d86d8ae7cf158ff1d6d5f2e Mon Sep 17 00:00:00 2001 From: Silvano Luciani Date: Wed, 16 Jul 2014 15:31:03 -0700 Subject: [PATCH 1/2] Fixed typo in error message --- lib/datastore/entity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datastore/entity.js b/lib/datastore/entity.js index aa22300688c..d07ee077bb5 100644 --- a/lib/datastore/entity.js +++ b/lib/datastore/entity.js @@ -76,7 +76,7 @@ module.exports.keyFromKeyProto = keyFromKeyProto; var keyToKeyProto = function(datasetId, key) { if (key.length < 2) { - throw new Error("A key should contain at least a kind and an idenfier.") + throw new Error("A key should contain at least a kind and an identifier.") } var namespace = null, start = 0; if (key.length % 2 == 1) { From 0afe6fd859346ec480c6ef64f5def5dbc788ab9a Mon Sep 17 00:00:00 2001 From: Silvano Luciani Date: Wed, 16 Jul 2014 15:34:09 -0700 Subject: [PATCH 2/2] Changed mutation from update to upsert This allows to pass a key id or name for an entity that is not already existing. --- lib/datastore/index.js | 4 ++-- test/datastore.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/datastore/index.js b/lib/datastore/index.js index c3c7cea500e..53ebc0acb1c 100644 --- a/lib/datastore/index.js +++ b/lib/datastore/index.js @@ -172,7 +172,7 @@ Transaction.prototype.saveAll = function(keys, objs, callback) { var req = { mode: MODE_NON_TRANSACTIONAL, mutation: { - update: [], + upsert: [], insertAutoId: [] } }; @@ -184,7 +184,7 @@ Transaction.prototype.saveAll = function(keys, objs, callback) { var e = entity.entityToEntityProto(objs[i]); e.key = entity.keyToKeyProto(this.id, keys[i]); if (entity.isKeyComplete(keys[i])) { - req.mutation.update.push(e); + req.mutation.upsert.push(e); } else { insertIndexes.push(i); req.mutation.insertAutoId.push(e); diff --git a/test/datastore.js b/test/datastore.js index 2d1132a869e..444b71d9ef4 100644 --- a/test/datastore.js +++ b/test/datastore.js @@ -163,8 +163,8 @@ describe('Dataset', function() { var ds = new datastore.Dataset({ projectId: 'test' }); ds.transaction.makeReq = function(method, proto, callback) { assert.equal(method, 'commit'); - assert.equal(proto.mutation.update.length, 2); - assert.equal(proto.mutation.update[0].properties.k.stringValue, 'v'); + assert.equal(proto.mutation.upsert.length, 2); + assert.equal(proto.mutation.upsert[0].properties.k.stringValue, 'v'); callback(); }; ds.saveAll([