Skip to content

Commit

Permalink
Use transactions for querying.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Jun 8, 2018
1 parent 5ce5d04 commit b870424
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions system-test/spanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -1348,28 +1348,50 @@ describe('Spanner', function() {
Spanner.int(PHONE_NUMBERS[1]),
];

var TRANSACTION;

before(function(done) {
table.insert(INSERT_ROW, function(err) {
if (err) {
done(err);
return;
}

// Allow Spanner time to insert the data before our tests query it.
setTimeout(done, 500);
var options = {
readOnly: true,
strong: true,
};

database.runTransaction(options, function(err, transaction) {
if (err) {
done(err);
return;
}
TRANSACTION = transaction;
done();
});
});
});

after(function() {
TRANSACTION.end();
});

it('should query in callback mode', function(done) {
database.run('SELECT * FROM Singers', function(err, rows) {
var options = {
readOnly: true,
strong: true,
};

TRANSACTION.run('SELECT * FROM Singers', function(err, rows) {
assert.ifError(err);
assert.deepEqual(rows.shift().toJSON(), EXPECTED_ROW);
done();
});
});

it('should query in promise mode', function(done) {
database
TRANSACTION
.run('SELECT * FROM Singers')
.then(function(data) {
var rows = data[0];
Expand All @@ -1382,7 +1404,7 @@ describe('Spanner', function() {
it('should query in stream mode', function(done) {
var row;

database
TRANSACTION
.runStream('SELECT * FROM Singers')
.on('error', done)
.once('data', function(row_) {
Expand Down

0 comments on commit b870424

Please sign in to comment.