Skip to content

Commit

Permalink
Merge pull request #956 from stephenplusplus/spp--datastore-runQuery-bug
Browse files Browse the repository at this point in the history
datastore: allow running queries in a transaction
  • Loading branch information
callmehiphop committed Nov 23, 2015
2 parents 78d8496 + 4ad9931 commit 7b6c1cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/datastore/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ DatastoreRequest.prototype.makeReq_ = function(method, body, callback) {
body.transaction = this.id;
}

if (method === 'lookup' && this.id) {
if (this.id && (method === 'lookup' || method === 'runQuery')) {
body.read_options = body.read_options || {};
body.read_options.transaction = this.id;
}
Expand Down
25 changes: 25 additions & 0 deletions test/datastore/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,31 @@ describe('Request', function() {
request.makeReq_('lookup', util.noop);
});
});

describe('runQuery', function() {
it('should attach transactional properties', function(done) {
request.id = 'EeMXCSGvwcSWGkkABRmGMTWdbi_pa66VflNhQAGblQFMXf9HrmNGa' +
'GugEsO1M2_2x7wZvLencG51uwaDOTZCjTkkRh7bw_oyKUgTmtJ0iWJwath7';
var expected = new pb.RunQueryRequest({
read_options: {
transaction: request.id
}
}).toBuffer();
requestOverride = function(req) {
assert.deepEqual(req.body, expected);
done();
};
request.makeReq_('runQuery', util.noop);
});

it('should not attach transactional properties', function(done) {
requestOverride = function(req) {
assert.strictEqual(req.body, '');
done();
};
request.makeReq_('runQuery', util.noop);
});
});
});
});
});

0 comments on commit 7b6c1cf

Please sign in to comment.