@@ -192,18 +192,19 @@ TransactionRequest.formatTimestampOptions_ = function(options) {
192
192
* // If you anticipate many results, you can end a stream early to prevent
193
193
* // unnecessary processing and API requests.
194
194
* //-
195
- * database.runTransaction()
196
- * .then(function(data) {
197
- * var transaction = data[0];
198
- *
199
- * transaction.createReadStream('Singers', {
200
- * keys: ['1'],
201
- * columns: ['SingerId', 'name']
202
- * })
203
- * .on('data', function(row) {
204
- * this.end();
205
- * });
206
- * });
195
+ * database.runTransaction(function(err, transaction) {
196
+ * if (err) {
197
+ * // Error handling omitted.
198
+ * }
199
+ *
200
+ * transaction.createReadStream('Singers', {
201
+ * keys: ['1'],
202
+ * columns: ['SingerId', 'name']
203
+ * })
204
+ * .on('data', function(row) {
205
+ * this.end();
206
+ * });
207
+ * });
207
208
*/
208
209
TransactionRequest . prototype . createReadStream = function ( table , query ) {
209
210
var self = this ;
@@ -218,6 +219,12 @@ TransactionRequest.prototype.createReadStream = function(table, query) {
218
219
table : table
219
220
} , query ) ;
220
221
222
+ if ( this . transaction && this . id ) {
223
+ reqOpts . transaction = {
224
+ id : this . id
225
+ } ;
226
+ }
227
+
221
228
if ( query . keys ) {
222
229
reqOpts . keySet = {
223
230
keys : arrify ( query . keys ) . map ( function ( key ) {
@@ -284,26 +291,6 @@ TransactionRequest.prototype.createReadStream = function(table, query) {
284
291
* 'Name2'
285
292
* ]
286
293
* ];
287
- *
288
- * //-
289
- * // If you are using a Promise to retrieve the transaction.
290
- * //-
291
- * database.runTransaction()
292
- * .then(function(data) {
293
- * var transaction = data[0];
294
- *
295
- * // Queue this mutation until later calling `commit`.
296
- * // Note that a callback is not passed to `deleteRows`.
297
- * transaction.deleteRows('Singers', keys);
298
- *
299
- * // Commit the transaction.
300
- * return transaction.commit();
301
- * })
302
- * .then(function(data) {
303
- * var apiResponse = data[0];
304
- *
305
- * // The rows were deleted successfully.
306
- * });
307
294
*/
308
295
TransactionRequest . prototype . deleteRows = function ( table , keys , callback ) {
309
296
var mutation = { } ;
@@ -396,26 +383,6 @@ TransactionRequest.prototype.deleteRows = function(table, keys, callback) {
396
383
* }
397
384
* });
398
385
* });
399
- *
400
- * //-
401
- * // If you are using a Promise to retrieve the transaction.
402
- * //-
403
- * database.runTransaction()
404
- * .then(function(data) {
405
- * var transaction = data[0];
406
- *
407
- * // Queue this mutation until later calling `commit`.
408
- * // Note that a callback is not passed to `insert`.
409
- * transaction.insert('Singers', row);
410
- *
411
- * // Commit the transaction.
412
- * return transaction.commit();
413
- * })
414
- * .then(function(data) {
415
- * var apiResponse = data[0];
416
- *
417
- * // The row was inserted successfully.
418
- * });
419
386
*/
420
387
TransactionRequest . prototype . insert = function ( table , keyVals , callback ) {
421
388
return this . mutate_ ( 'insert' , table , keyVals , callback ) ;
@@ -516,22 +483,6 @@ TransactionRequest.prototype.insert = function(table, keyVals, callback) {
516
483
* transaction.end();
517
484
* });
518
485
* });
519
- *
520
- * //-
521
- * // If the callback is omitted, we'll return a Promise.
522
- * //-
523
- * database.runTransaction()
524
- * .then(function(data) {
525
- * var transaction = data[0];
526
- *
527
- * return transaction.read('Singers', query)
528
- * .then(function(data) {
529
- * var rows = data[0];
530
- *
531
- * // End the transaction. Note that no callback is provided.
532
- * transaction.end();
533
- * });
534
- * });
535
486
*/
536
487
TransactionRequest . prototype . read = function ( table , keyVals , callback ) {
537
488
var rows = [ ] ;
@@ -581,26 +532,6 @@ TransactionRequest.prototype.read = function(table, keyVals, callback) {
581
532
* }
582
533
* });
583
534
* });
584
- *
585
- * //-
586
- * // If you are using a Promise to retrieve the transaction.
587
- * //-
588
- * database.runTransaction()
589
- * .then(function(data) {
590
- * var transaction = data[0];
591
- *
592
- * // Queue this mutation until later calling `commit`.
593
- * // Note that a callback is not passed to `replace`.
594
- * transaction.replace('Singers', row);
595
- *
596
- * // Commit the transaction.
597
- * return transaction.commit();
598
- * })
599
- * .then(function(data) {
600
- * var apiResponse = data[0];
601
- *
602
- * // The row was replaced successfully.
603
- * });
604
535
*/
605
536
TransactionRequest . prototype . replace = function ( table , keyVals , callback ) {
606
537
return this . mutate_ ( 'replace' , table , keyVals , callback ) ;
@@ -659,26 +590,6 @@ TransactionRequest.prototype.requestStream = function() {};
659
590
* }
660
591
* });
661
592
* });
662
- *
663
- * //-
664
- * // If you are using a Promise to retrieve the transaction.
665
- * //-
666
- * database.runTransaction()
667
- * .then(function(data) {
668
- * var transaction = data[0];
669
- *
670
- * // Queue this mutation until later calling `commit`.
671
- * // Note that a callback is not passed to `update`.
672
- * transaction.update('Singers', row);
673
- *
674
- * // Commit the transaction.
675
- * return transaction.commit();
676
- * })
677
- * .then(function(data) {
678
- * var apiResponse = data[0];
679
- *
680
- * // The row was updated successfully.
681
- * });
682
593
*/
683
594
TransactionRequest . prototype . update = function ( table , keyVals , callback ) {
684
595
return this . mutate_ ( 'update' , table , keyVals , callback ) ;
@@ -719,26 +630,6 @@ TransactionRequest.prototype.update = function(table, keyVals, callback) {
719
630
* }
720
631
* });
721
632
* });
722
- *
723
- * //-
724
- * // If you are using a Promise to retrieve the transaction.
725
- * //-
726
- * database.runTransaction()
727
- * .then(function(data) {
728
- * var transaction = data[0];
729
- *
730
- * // Queue this mutation until later calling `commit`.
731
- * // Note that a callback is not passed to `upsert`.
732
- * transaction.upsert('Singers', row);
733
- *
734
- * // Commit the transaction.
735
- * return transaction.commit();
736
- * })
737
- * .then(function(data) {
738
- * var apiResponse = data[0];
739
- *
740
- * // The row was updated or inserted successfully.
741
- * });
742
633
*/
743
634
TransactionRequest . prototype . upsert = function ( table , keyVals , callback ) {
744
635
return this . mutate_ ( 'insertOrUpdate' , table , keyVals , callback ) ;
0 commit comments