google-cloud-spanner 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -155,6 +155,19 @@ module Google
155
155
  # * `:optimizer_version` (String) The version of optimizer to use.
156
156
  # Empty to use database default. "latest" to use the latest
157
157
  # available optimizer version.
158
+ # @param [Hash] call_options A hash of values to specify the custom
159
+ # call options, e.g., timeout, retries, etc. Call options are
160
+ # optional. The following settings can be provided:
161
+ #
162
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
163
+ # that overrides the default setting.
164
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
165
+ # setting of retry policy with the following keys:
166
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
167
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
168
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
169
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
170
+ # trigger a retry.
158
171
  #
159
172
  # @return [Google::Cloud::Spanner::Results] The results of the query
160
173
  # execution.
@@ -274,7 +287,32 @@ module Google
274
287
  # end
275
288
  # end
276
289
  #
277
- def execute_query sql, params: nil, types: nil, query_options: nil
290
+ # @example Query using custom timeout and retry policy:
291
+ # require "google/cloud/spanner"
292
+ #
293
+ # spanner = Google::Cloud::Spanner.new
294
+ # db = spanner.client "my-instance", "my-database"
295
+ #
296
+ # timeout = 30.0
297
+ # retry_policy = {
298
+ # initial_delay: 0.25,
299
+ # max_delay: 32.0,
300
+ # multiplier: 1.3,
301
+ # retry_codes: ["UNAVAILABLE"]
302
+ # }
303
+ # call_options = { timeout: timeout, retry_policy: retry_policy }
304
+ #
305
+ # db.transaction do |tx|
306
+ # results = tx.execute_query \
307
+ # "SELECT * FROM users", call_options: call_options
308
+ #
309
+ # results.rows.each do |row|
310
+ # puts "User #{row[:id]} is #{row[:name]}"
311
+ # end
312
+ # end
313
+ #
314
+ def execute_query sql, params: nil, types: nil, query_options: nil,
315
+ call_options: nil
278
316
  ensure_session!
279
317
 
280
318
  @seqno += 1
@@ -282,7 +320,8 @@ module Google
282
320
  params, types = Convert.to_input_params_and_types params, types
283
321
  session.execute_query sql, params: params, types: types,
284
322
  transaction: tx_selector, seqno: @seqno,
285
- query_options: query_options
323
+ query_options: query_options,
324
+ call_options: call_options
286
325
  end
287
326
  alias execute execute_query
288
327
  alias query execute_query
@@ -352,6 +391,19 @@ module Google
352
391
  # * `:optimizer_version` (String) The version of optimizer to use.
353
392
  # Empty to use database default. "latest" to use the latest
354
393
  # available optimizer version.
394
+ # @param [Hash] call_options A hash of values to specify the custom
395
+ # call options, e.g., timeout, retries, etc. Call options are
396
+ # optional. The following settings can be provided:
397
+ #
398
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
399
+ # that overrides the default setting.
400
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
401
+ # setting of retry policy with the following keys:
402
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
403
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
404
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
405
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
406
+ # trigger a retry.
355
407
  #
356
408
  # @return [Integer] The exact number of rows that were modified.
357
409
  #
@@ -393,9 +445,33 @@ module Google
393
445
  # )
394
446
  # end
395
447
  #
396
- def execute_update sql, params: nil, types: nil, query_options: nil
448
+ # @example Update using custom timeout and retry policy:
449
+ # require "google/cloud/spanner"
450
+ #
451
+ # spanner = Google::Cloud::Spanner.new
452
+ # db = spanner.client "my-instance", "my-database"
453
+ #
454
+ # timeout = 30.0
455
+ # retry_policy = {
456
+ # initial_delay: 0.25,
457
+ # max_delay: 32.0,
458
+ # multiplier: 1.3,
459
+ # retry_codes: ["UNAVAILABLE"]
460
+ # }
461
+ # call_options = { timeout: timeout, retry_policy: retry_policy }
462
+ #
463
+ # db.transaction do |tx|
464
+ # row_count = tx.execute_update(
465
+ # "UPDATE users SET name = 'Charlie' WHERE id = 1",
466
+ # call_options: call_options
467
+ # )
468
+ # end
469
+ #
470
+ def execute_update sql, params: nil, types: nil, query_options: nil,
471
+ call_options: nil
397
472
  results = execute_query sql, params: params, types: types,
398
- query_options: query_options
473
+ query_options: query_options,
474
+ call_options: call_options
399
475
  # Stream all PartialResultSet to get ResultSetStats
400
476
  results.rows.to_a
401
477
  # Raise an error if there is not a row count returned
@@ -409,6 +485,20 @@ module Google
409
485
  ##
410
486
  # Executes DML statements in a batch.
411
487
  #
488
+ # @param [Hash] call_options A hash of values to specify the custom
489
+ # call options, e.g., timeout, retries, etc. Call options are
490
+ # optional. The following settings can be provided:
491
+ #
492
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
493
+ # that overrides the default setting.
494
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
495
+ # setting of retry policy with the following keys:
496
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
497
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
498
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
499
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
500
+ # trigger a retry.
501
+ #
412
502
  # @yield [batch_update] a batch update object
413
503
  # @yieldparam [Google::Cloud::Spanner::BatchUpdate] batch_update a batch
414
504
  # update object accepting DML statements and optional parameters and
@@ -464,10 +554,11 @@ module Google
464
554
  # end
465
555
  # end
466
556
  #
467
- def batch_update &block
557
+ def batch_update call_options: nil, &block
468
558
  ensure_session!
469
559
  @seqno += 1
470
- session.batch_update tx_selector, @seqno, &block
560
+ session.batch_update tx_selector, @seqno,
561
+ call_options: call_options, &block
471
562
  end
472
563
 
473
564
  ##
@@ -486,6 +577,19 @@ module Google
486
577
  # Optional.
487
578
  # @param [Integer] limit If greater than zero, no more than this number
488
579
  # of rows will be returned. The default is no limit.
580
+ # @param [Hash] call_options A hash of values to specify the custom
581
+ # call options, e.g., timeout, retries, etc. Call options are
582
+ # optional. The following settings can be provided:
583
+ #
584
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
585
+ # that overrides the default setting.
586
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
587
+ # setting of retry policy with the following keys:
588
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
589
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
590
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
591
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
592
+ # trigger a retry.
489
593
  #
490
594
  # @return [Google::Cloud::Spanner::Results] The results of the read
491
595
  # operation.
@@ -504,14 +608,16 @@ module Google
504
608
  # end
505
609
  # end
506
610
  #
507
- def read table, columns, keys: nil, index: nil, limit: nil
611
+ def read table, columns, keys: nil, index: nil, limit: nil,
612
+ call_options: nil
508
613
  ensure_session!
509
614
 
510
615
  columns = Array(columns).map(&:to_s)
511
616
  keys = Convert.to_key_set keys
512
617
 
513
618
  session.read table, columns, keys: keys, index: index, limit: limit,
514
- transaction: tx_selector
619
+ transaction: tx_selector,
620
+ call_options: call_options
515
621
  end
516
622
 
517
623
  ##
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Spanner
19
- VERSION = "2.0.0".freeze
19
+ VERSION = "2.1.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-spanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-07-23 00:00:00.000000000 Z
12
+ date: 2020-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core