google-cloud-spanner 2.0.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -0
- data/CONTRIBUTING.md +2 -2
- data/LOGGING.md +1 -1
- data/lib/google-cloud-spanner.rb +1 -0
- data/lib/google/cloud/spanner.rb +7 -5
- data/lib/google/cloud/spanner/backup.rb +10 -2
- data/lib/google/cloud/spanner/backup/job.rb +8 -8
- data/lib/google/cloud/spanner/backup/job/list.rb +2 -2
- data/lib/google/cloud/spanner/backup/list.rb +2 -2
- data/lib/google/cloud/spanner/batch_snapshot.rb +114 -15
- data/lib/google/cloud/spanner/batch_update.rb +3 -1
- data/lib/google/cloud/spanner/client.rb +413 -78
- data/lib/google/cloud/spanner/commit_response.rb +87 -0
- data/lib/google/cloud/spanner/commit_response/commit_stats.rb +51 -0
- data/lib/google/cloud/spanner/convert.rb +9 -0
- data/lib/google/cloud/spanner/data.rb +4 -5
- data/lib/google/cloud/spanner/database.rb +25 -3
- data/lib/google/cloud/spanner/database/backup_info.rb +12 -3
- data/lib/google/cloud/spanner/database/job/list.rb +2 -2
- data/lib/google/cloud/spanner/database/list.rb +4 -4
- data/lib/google/cloud/spanner/fields.rb +3 -2
- data/lib/google/cloud/spanner/instance/config/list.rb +4 -4
- data/lib/google/cloud/spanner/instance/list.rb +4 -4
- data/lib/google/cloud/spanner/partition.rb +4 -2
- data/lib/google/cloud/spanner/policy.rb +3 -2
- data/lib/google/cloud/spanner/pool.rb +10 -10
- data/lib/google/cloud/spanner/results.rb +105 -26
- data/lib/google/cloud/spanner/service.rb +218 -107
- data/lib/google/cloud/spanner/session.rb +361 -30
- data/lib/google/cloud/spanner/snapshot.rb +58 -4
- data/lib/google/cloud/spanner/status.rb +4 -1
- data/lib/google/cloud/spanner/transaction.rb +114 -8
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +12 -10
@@ -16,6 +16,7 @@
|
|
16
16
|
require "google/cloud/spanner/data"
|
17
17
|
require "google/cloud/spanner/results"
|
18
18
|
require "google/cloud/spanner/commit"
|
19
|
+
require "google/cloud/spanner/commit_response"
|
19
20
|
require "google/cloud/spanner/batch_update"
|
20
21
|
|
21
22
|
module Google
|
@@ -162,6 +163,19 @@ module Google
|
|
162
163
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
163
164
|
# Empty to use database default. "latest" to use the latest
|
164
165
|
# available optimizer version.
|
166
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
167
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
168
|
+
# optional. The following settings can be provided:
|
169
|
+
#
|
170
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
171
|
+
# that overrides the default setting.
|
172
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
173
|
+
# setting of retry policy with the following keys:
|
174
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
175
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
176
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
177
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
178
|
+
# trigger a retry.
|
165
179
|
#
|
166
180
|
# @return [Google::Cloud::Spanner::Results] The results of the query
|
167
181
|
# execution.
|
@@ -275,8 +289,32 @@ module Google
|
|
275
289
|
# puts "User #{row[:id]} is #{row[:name]}"
|
276
290
|
# end
|
277
291
|
#
|
292
|
+
# @example Query using custom timeout and retry policy:
|
293
|
+
# require "google/cloud/spanner"
|
294
|
+
#
|
295
|
+
# spanner = Google::Cloud::Spanner.new
|
296
|
+
#
|
297
|
+
# db = spanner.client "my-instance", "my-database"
|
298
|
+
#
|
299
|
+
# timeout = 30.0
|
300
|
+
# retry_policy = {
|
301
|
+
# initial_delay: 0.25,
|
302
|
+
# max_delay: 32.0,
|
303
|
+
# multiplier: 1.3,
|
304
|
+
# retry_codes: ["UNAVAILABLE"]
|
305
|
+
# }
|
306
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
307
|
+
#
|
308
|
+
# results = db.execute_query \
|
309
|
+
# "SELECT * FROM users", call_options: call_options
|
310
|
+
#
|
311
|
+
# results.rows.each do |row|
|
312
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
313
|
+
# end
|
314
|
+
#
|
278
315
|
def execute_query sql, params: nil, types: nil, transaction: nil,
|
279
|
-
partition_token: nil, seqno: nil, query_options: nil
|
316
|
+
partition_token: nil, seqno: nil, query_options: nil,
|
317
|
+
call_options: nil
|
280
318
|
ensure_service!
|
281
319
|
if query_options.nil?
|
282
320
|
query_options = @query_options
|
@@ -289,7 +327,8 @@ module Google
|
|
289
327
|
transaction: transaction,
|
290
328
|
partition_token: partition_token,
|
291
329
|
seqno: seqno,
|
292
|
-
query_options: query_options
|
330
|
+
query_options: query_options,
|
331
|
+
call_options: call_options
|
293
332
|
@last_updated_at = Time.now
|
294
333
|
results
|
295
334
|
end
|
@@ -302,6 +341,20 @@ module Google
|
|
302
341
|
# transactions.
|
303
342
|
# @param [Integer] seqno A per-transaction sequence number used to
|
304
343
|
# identify this request.
|
344
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
345
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
346
|
+
# optional. The following settings can be provided:
|
347
|
+
#
|
348
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
349
|
+
# that overrides the default setting.
|
350
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
351
|
+
# setting of retry policy with the following keys:
|
352
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
353
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
354
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
355
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
356
|
+
# trigger a retry.
|
357
|
+
#
|
305
358
|
# @yield [batch_update] a batch update object
|
306
359
|
# @yieldparam [Google::Cloud::Spanner::BatchUpdate] batch_update a batch
|
307
360
|
# update object accepting DML statements and optional parameters and
|
@@ -316,7 +369,7 @@ module Google
|
|
316
369
|
# @return [Array<Integer>] A list with the exact number of rows that
|
317
370
|
# were modified for each DML statement.
|
318
371
|
#
|
319
|
-
def batch_update transaction, seqno
|
372
|
+
def batch_update transaction, seqno, call_options: nil
|
320
373
|
ensure_service!
|
321
374
|
|
322
375
|
raise ArgumentError, "block is required" unless block_given?
|
@@ -325,7 +378,8 @@ module Google
|
|
325
378
|
yield batch
|
326
379
|
|
327
380
|
results = service.execute_batch_dml path, transaction,
|
328
|
-
batch.statements, seqno
|
381
|
+
batch.statements, seqno,
|
382
|
+
call_options: call_options
|
329
383
|
@last_updated_at = Time.now
|
330
384
|
results
|
331
385
|
end
|
@@ -349,6 +403,19 @@ module Google
|
|
349
403
|
# @param [Google::Cloud::Spanner::V1::TransactionSelector] transaction The
|
350
404
|
# transaction selector value to send. Only used for single-use
|
351
405
|
# transactions.
|
406
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
407
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
408
|
+
# optional. The following settings can be provided:
|
409
|
+
#
|
410
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
411
|
+
# that overrides the default setting.
|
412
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
413
|
+
# setting of retry policy with the following keys:
|
414
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
415
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
416
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
417
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
418
|
+
# trigger a retry.
|
352
419
|
#
|
353
420
|
# @return [Google::Cloud::Spanner::Results] The results of the read
|
354
421
|
# operation.
|
@@ -367,25 +434,28 @@ module Google
|
|
367
434
|
# end
|
368
435
|
#
|
369
436
|
def read table, columns, keys: nil, index: nil, limit: nil,
|
370
|
-
transaction: nil, partition_token: nil
|
437
|
+
transaction: nil, partition_token: nil, call_options: nil
|
371
438
|
ensure_service!
|
372
439
|
|
373
440
|
results = Results.read service, path, table, columns,
|
374
441
|
keys: keys, index: index, limit: limit,
|
375
442
|
transaction: transaction,
|
376
|
-
partition_token: partition_token
|
443
|
+
partition_token: partition_token,
|
444
|
+
call_options: call_options
|
377
445
|
@last_updated_at = Time.now
|
378
446
|
results
|
379
447
|
end
|
380
448
|
|
381
449
|
def partition_query sql, transaction, params: nil, types: nil,
|
382
|
-
partition_size_bytes: nil, max_partitions: nil
|
450
|
+
partition_size_bytes: nil, max_partitions: nil,
|
451
|
+
call_options: nil
|
383
452
|
ensure_service!
|
384
453
|
|
385
454
|
results = service.partition_query \
|
386
455
|
path, sql, transaction, params: params, types: types,
|
387
456
|
partition_size_bytes: partition_size_bytes,
|
388
|
-
max_partitions: max_partitions
|
457
|
+
max_partitions: max_partitions,
|
458
|
+
call_options: call_options
|
389
459
|
|
390
460
|
@last_updated_at = Time.now
|
391
461
|
|
@@ -394,14 +464,15 @@ module Google
|
|
394
464
|
|
395
465
|
def partition_read table, columns, transaction, keys: nil,
|
396
466
|
index: nil, partition_size_bytes: nil,
|
397
|
-
max_partitions: nil
|
467
|
+
max_partitions: nil, call_options: nil
|
398
468
|
ensure_service!
|
399
469
|
|
400
470
|
results = service.partition_read \
|
401
471
|
path, table, columns, transaction,
|
402
472
|
keys: keys, index: index,
|
403
473
|
partition_size_bytes: partition_size_bytes,
|
404
|
-
max_partitions: max_partitions
|
474
|
+
max_partitions: max_partitions,
|
475
|
+
call_options: call_options
|
405
476
|
|
406
477
|
@last_updated_at = Time.now
|
407
478
|
|
@@ -414,10 +485,34 @@ module Google
|
|
414
485
|
# @param [String] transaction_id The identifier of previously-started
|
415
486
|
# transaction to be used instead of starting a new transaction.
|
416
487
|
# Optional.
|
488
|
+
# @param [Hash] commit_options A hash of commit options.
|
489
|
+
# e.g., return_commit_stats. Commit options are optional.
|
490
|
+
# The following options can be provided:
|
491
|
+
#
|
492
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
493
|
+
# then statistics related to the transaction will be included in
|
494
|
+
# {CommitResponse}. Default value is `false`
|
495
|
+
#
|
496
|
+
# transaction. Default it is `false`.
|
497
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
498
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
499
|
+
# optional. The following settings can be provided:
|
500
|
+
#
|
501
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
502
|
+
# that overrides the default setting.
|
503
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
504
|
+
# setting of retry policy with the following keys:
|
505
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
506
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
507
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
508
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
509
|
+
# trigger a retry.
|
510
|
+
#
|
417
511
|
# @yield [commit] The block for mutating the data.
|
418
512
|
# @yieldparam [Google::Cloud::Spanner::Commit] commit The Commit object.
|
419
513
|
#
|
420
|
-
# @return [Time] The timestamp at which the operation
|
514
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
515
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
421
516
|
#
|
422
517
|
# @example
|
423
518
|
# require "google/cloud/spanner"
|
@@ -431,14 +526,33 @@ module Google
|
|
431
526
|
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
432
527
|
# end
|
433
528
|
#
|
434
|
-
|
529
|
+
# @example Get commit stats
|
530
|
+
# require "google/cloud/spanner"
|
531
|
+
#
|
532
|
+
# spanner = Google::Cloud::Spanner.new
|
533
|
+
#
|
534
|
+
# db = spanner.client "my-instance", "my-database"
|
535
|
+
#
|
536
|
+
# commit_options = { return_commit_stats: true }
|
537
|
+
# commit_resp = db.commit commit_options: commit_options do |c|
|
538
|
+
# c.update "users", [{ id: 1, name: "Charlie", active: false }]
|
539
|
+
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
540
|
+
# end
|
541
|
+
#
|
542
|
+
# puts commit_resp.timestamp
|
543
|
+
# puts commit_resp.stats.mutation_count
|
544
|
+
#
|
545
|
+
def commit transaction_id: nil, commit_options: nil, call_options: nil
|
435
546
|
ensure_service!
|
436
547
|
commit = Commit.new
|
437
548
|
yield commit
|
438
549
|
commit_resp = service.commit path, commit.mutations,
|
439
|
-
transaction_id: transaction_id
|
550
|
+
transaction_id: transaction_id,
|
551
|
+
commit_options: commit_options,
|
552
|
+
call_options: call_options
|
440
553
|
@last_updated_at = Time.now
|
441
|
-
|
554
|
+
resp = CommitResponse.from_grpc commit_resp
|
555
|
+
commit_options ? resp : resp.timestamp
|
442
556
|
end
|
443
557
|
|
444
558
|
##
|
@@ -468,7 +582,30 @@ module Google
|
|
468
582
|
# See [Data
|
469
583
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
470
584
|
#
|
471
|
-
# @
|
585
|
+
# @param [Hash] commit_options A hash of commit options.
|
586
|
+
# e.g., return_commit_stats. Commit options are optional.
|
587
|
+
# The following options can be provided:
|
588
|
+
#
|
589
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
590
|
+
# then statistics related to the transaction will be included in
|
591
|
+
# {CommitResponse}. Default value is `false`
|
592
|
+
#
|
593
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
594
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
595
|
+
# optional. The following settings can be provided:
|
596
|
+
#
|
597
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
598
|
+
# that overrides the default setting.
|
599
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
600
|
+
# setting of retry policy with the following keys:
|
601
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
602
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
603
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
604
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
605
|
+
# trigger a retry.
|
606
|
+
#
|
607
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
608
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
472
609
|
#
|
473
610
|
# @example
|
474
611
|
# require "google/cloud/spanner"
|
@@ -480,8 +617,29 @@ module Google
|
|
480
617
|
# db.upsert "users", [{ id: 1, name: "Charlie", active: false },
|
481
618
|
# { id: 2, name: "Harvey", active: true }]
|
482
619
|
#
|
483
|
-
|
484
|
-
|
620
|
+
# @example Get commit stats
|
621
|
+
# require "google/cloud/spanner"
|
622
|
+
#
|
623
|
+
# spanner = Google::Cloud::Spanner.new
|
624
|
+
#
|
625
|
+
# db = spanner.client "my-instance", "my-database"
|
626
|
+
#
|
627
|
+
# records = [{ id: 1, name: "Charlie", active: false },
|
628
|
+
# { id: 2, name: "Harvey", active: true }]
|
629
|
+
# commit_options = { return_commit_stats: true }
|
630
|
+
# commit_resp = db.upsert "users", records, commit_options: commit_options
|
631
|
+
#
|
632
|
+
# puts commit_resp.timestamp
|
633
|
+
# puts commit_resp.stats.mutation_count
|
634
|
+
#
|
635
|
+
def upsert table, *rows, transaction_id: nil, commit_options: nil,
|
636
|
+
call_options: nil
|
637
|
+
opts = {
|
638
|
+
transaction_id: transaction_id,
|
639
|
+
commit_options: commit_options,
|
640
|
+
call_options: call_options
|
641
|
+
}
|
642
|
+
commit(**opts) do |c|
|
485
643
|
c.upsert table, rows
|
486
644
|
end
|
487
645
|
end
|
@@ -513,7 +671,30 @@ module Google
|
|
513
671
|
# See [Data
|
514
672
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
515
673
|
#
|
516
|
-
# @
|
674
|
+
# @param [Hash] commit_options A hash of commit options.
|
675
|
+
# e.g., return_commit_stats. Commit options are optional.
|
676
|
+
# The following options can be provided:
|
677
|
+
#
|
678
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
679
|
+
# then statistics related to the transaction will be included in
|
680
|
+
# {CommitResponse}. Default value is `false`
|
681
|
+
#
|
682
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
683
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
684
|
+
# optional. The following settings can be provided:
|
685
|
+
#
|
686
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
687
|
+
# that overrides the default setting.
|
688
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
689
|
+
# setting of retry policy with the following keys:
|
690
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
691
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
692
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
693
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
694
|
+
# trigger a retry.
|
695
|
+
#
|
696
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
697
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
517
698
|
#
|
518
699
|
# @example
|
519
700
|
# require "google/cloud/spanner"
|
@@ -525,8 +706,29 @@ module Google
|
|
525
706
|
# db.insert "users", [{ id: 1, name: "Charlie", active: false },
|
526
707
|
# { id: 2, name: "Harvey", active: true }]
|
527
708
|
#
|
528
|
-
|
529
|
-
|
709
|
+
# @example Get commit stats
|
710
|
+
# require "google/cloud/spanner"
|
711
|
+
#
|
712
|
+
# spanner = Google::Cloud::Spanner.new
|
713
|
+
#
|
714
|
+
# db = spanner.client "my-instance", "my-database"
|
715
|
+
#
|
716
|
+
# records = [{ id: 1, name: "Charlie", active: false },
|
717
|
+
# { id: 2, name: "Harvey", active: true }]
|
718
|
+
# commit_options = { return_commit_stats: true }
|
719
|
+
# commit_resp = db.insert "users", records, commit_options: commit_options
|
720
|
+
#
|
721
|
+
# puts commit_resp.timestamp
|
722
|
+
# puts commit_resp.stats.mutation_count
|
723
|
+
#
|
724
|
+
def insert table, *rows, transaction_id: nil, commit_options: nil,
|
725
|
+
call_options: nil
|
726
|
+
opts = {
|
727
|
+
transaction_id: transaction_id,
|
728
|
+
commit_options: commit_options,
|
729
|
+
call_options: call_options
|
730
|
+
}
|
731
|
+
commit(**opts) do |c|
|
530
732
|
c.insert table, rows
|
531
733
|
end
|
532
734
|
end
|
@@ -557,7 +759,30 @@ module Google
|
|
557
759
|
# See [Data
|
558
760
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
559
761
|
#
|
560
|
-
# @
|
762
|
+
# @param [Hash] commit_options A hash of commit options.
|
763
|
+
# e.g., return_commit_stats. Commit options are optional.
|
764
|
+
# The following options can be provided:
|
765
|
+
#
|
766
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
767
|
+
# then statistics related to the transaction will be included in
|
768
|
+
# {CommitResponse}. Default value is `false`
|
769
|
+
#
|
770
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
771
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
772
|
+
# optional. The following settings can be provided:
|
773
|
+
#
|
774
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
775
|
+
# that overrides the default setting.
|
776
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
777
|
+
# setting of retry policy with the following keys:
|
778
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
779
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
780
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
781
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
782
|
+
# trigger a retry.
|
783
|
+
#
|
784
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
785
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
561
786
|
#
|
562
787
|
# @example
|
563
788
|
# require "google/cloud/spanner"
|
@@ -569,8 +794,29 @@ module Google
|
|
569
794
|
# db.update "users", [{ id: 1, name: "Charlie", active: false },
|
570
795
|
# { id: 2, name: "Harvey", active: true }]
|
571
796
|
#
|
572
|
-
|
573
|
-
|
797
|
+
# @example Get commit stats
|
798
|
+
# require "google/cloud/spanner"
|
799
|
+
#
|
800
|
+
# spanner = Google::Cloud::Spanner.new
|
801
|
+
#
|
802
|
+
# db = spanner.client "my-instance", "my-database"
|
803
|
+
#
|
804
|
+
# records = [{ id: 1, name: "Charlie", active: false },
|
805
|
+
# { id: 2, name: "Harvey", active: true }]
|
806
|
+
# commit_options = { return_commit_stats: true }
|
807
|
+
# commit_resp = db.update "users", records, commit_options: commit_options
|
808
|
+
#
|
809
|
+
# puts commit_resp.timestamp
|
810
|
+
# puts commit_resp.stats.mutation_count
|
811
|
+
#
|
812
|
+
def update table, *rows, transaction_id: nil, commit_options: nil,
|
813
|
+
call_options: nil
|
814
|
+
opts = {
|
815
|
+
transaction_id: transaction_id,
|
816
|
+
commit_options: commit_options,
|
817
|
+
call_options: call_options
|
818
|
+
}
|
819
|
+
commit(**opts) do |c|
|
574
820
|
c.update table, rows
|
575
821
|
end
|
576
822
|
end
|
@@ -603,7 +849,30 @@ module Google
|
|
603
849
|
# See [Data
|
604
850
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
605
851
|
#
|
606
|
-
# @
|
852
|
+
# @param [Hash] commit_options A hash of commit options.
|
853
|
+
# e.g., return_commit_stats. Commit options are optional.
|
854
|
+
# The following options can be provided:
|
855
|
+
#
|
856
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
857
|
+
# then statistics related to the transaction will be included in
|
858
|
+
# {CommitResponse}. Default value is `false`.
|
859
|
+
#
|
860
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
861
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
862
|
+
# optional. The following settings can be provided:
|
863
|
+
#
|
864
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
865
|
+
# that overrides the default setting.
|
866
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
867
|
+
# setting of retry policy with the following keys:
|
868
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
869
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
870
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
871
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
872
|
+
# trigger a retry.
|
873
|
+
#
|
874
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
875
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
607
876
|
#
|
608
877
|
# @example
|
609
878
|
# require "google/cloud/spanner"
|
@@ -615,8 +884,29 @@ module Google
|
|
615
884
|
# db.replace "users", [{ id: 1, name: "Charlie", active: false },
|
616
885
|
# { id: 2, name: "Harvey", active: true }]
|
617
886
|
#
|
618
|
-
|
619
|
-
|
887
|
+
# @example Get commit stats
|
888
|
+
# require "google/cloud/spanner"
|
889
|
+
#
|
890
|
+
# spanner = Google::Cloud::Spanner.new
|
891
|
+
#
|
892
|
+
# db = spanner.client "my-instance", "my-database"
|
893
|
+
#
|
894
|
+
# records = [{ id: 1, name: "Charlie", active: false },
|
895
|
+
# { id: 2, name: "Harvey", active: true }]
|
896
|
+
# commit_options = { return_commit_stats: true }
|
897
|
+
# commit_resp = db.replace "users", records, commit_options: commit_options
|
898
|
+
#
|
899
|
+
# puts commit_resp.timestamp
|
900
|
+
# puts commit_resp.stats.mutation_count
|
901
|
+
#
|
902
|
+
def replace table, *rows, transaction_id: nil, commit_options: nil,
|
903
|
+
call_options: nil
|
904
|
+
opts = {
|
905
|
+
transaction_id: transaction_id,
|
906
|
+
commit_options: commit_options,
|
907
|
+
call_options: call_options
|
908
|
+
}
|
909
|
+
commit(**opts) do |c|
|
620
910
|
c.replace table, rows
|
621
911
|
end
|
622
912
|
end
|
@@ -630,8 +920,30 @@ module Google
|
|
630
920
|
# @param [Object, Array<Object>] keys A single, or list of keys or key
|
631
921
|
# ranges to match returned data to. Values should have exactly as many
|
632
922
|
# elements as there are columns in the primary key.
|
633
|
-
#
|
634
|
-
#
|
923
|
+
# @param [Hash] commit_options A hash of commit options.
|
924
|
+
# e.g., return_commit_stats. Commit options are optional.
|
925
|
+
# The following options can be provided:
|
926
|
+
#
|
927
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
928
|
+
# then statistics related to the transaction will be included in
|
929
|
+
# {CommitResponse}. Default value is `false`
|
930
|
+
#
|
931
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
932
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
933
|
+
# optional. The following settings can be provided:
|
934
|
+
#
|
935
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
936
|
+
# that overrides the default setting.
|
937
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
938
|
+
# setting of retry policy with the following keys:
|
939
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
940
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
941
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
942
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
943
|
+
# trigger a retry.
|
944
|
+
#
|
945
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
946
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
635
947
|
#
|
636
948
|
# @example
|
637
949
|
# require "google/cloud/spanner"
|
@@ -642,8 +954,27 @@ module Google
|
|
642
954
|
#
|
643
955
|
# db.delete "users", [1, 2, 3]
|
644
956
|
#
|
645
|
-
|
646
|
-
|
957
|
+
# @example Get commit stats
|
958
|
+
# require "google/cloud/spanner"
|
959
|
+
#
|
960
|
+
# spanner = Google::Cloud::Spanner.new
|
961
|
+
#
|
962
|
+
# db = spanner.client "my-instance", "my-database"
|
963
|
+
#
|
964
|
+
# commit_options = { return_commit_stats: true }
|
965
|
+
# commit_resp = db.delete "users", [1,2,3], commit_options: commit_options
|
966
|
+
#
|
967
|
+
# puts commit_resp.timestamp
|
968
|
+
# puts commit_resp.stats.mutation_count
|
969
|
+
#
|
970
|
+
def delete table, keys = [], transaction_id: nil, commit_options: nil,
|
971
|
+
call_options: nil
|
972
|
+
opts = {
|
973
|
+
transaction_id: transaction_id,
|
974
|
+
commit_options: commit_options,
|
975
|
+
call_options: call_options
|
976
|
+
}
|
977
|
+
commit(**opts) do |c|
|
647
978
|
c.delete table, keys
|
648
979
|
end
|
649
980
|
end
|