google-cloud-spanner 1.16.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +1 -1
  3. data/CHANGELOG.md +23 -0
  4. data/lib/google-cloud-spanner.rb +10 -13
  5. data/lib/google/cloud/spanner.rb +6 -8
  6. data/lib/google/cloud/spanner/admin/database/credentials.rb +2 -2
  7. data/lib/google/cloud/spanner/admin/instance/credentials.rb +2 -2
  8. data/lib/google/cloud/spanner/backup.rb +1 -1
  9. data/lib/google/cloud/spanner/backup/job.rb +2 -2
  10. data/lib/google/cloud/spanner/backup/job/list.rb +2 -2
  11. data/lib/google/cloud/spanner/backup/list.rb +1 -2
  12. data/lib/google/cloud/spanner/backup/restore/job.rb +2 -2
  13. data/lib/google/cloud/spanner/batch_client.rb +2 -2
  14. data/lib/google/cloud/spanner/batch_snapshot.rb +6 -8
  15. data/lib/google/cloud/spanner/batch_update.rb +1 -1
  16. data/lib/google/cloud/spanner/client.rb +8 -8
  17. data/lib/google/cloud/spanner/commit.rb +14 -14
  18. data/lib/google/cloud/spanner/convert.rb +7 -7
  19. data/lib/google/cloud/spanner/credentials.rb +2 -2
  20. data/lib/google/cloud/spanner/data.rb +2 -2
  21. data/lib/google/cloud/spanner/database.rb +22 -22
  22. data/lib/google/cloud/spanner/database/backup_info.rb +1 -1
  23. data/lib/google/cloud/spanner/database/job.rb +3 -3
  24. data/lib/google/cloud/spanner/database/job/list.rb +2 -2
  25. data/lib/google/cloud/spanner/database/list.rb +1 -1
  26. data/lib/google/cloud/spanner/database/restore_info.rb +1 -1
  27. data/lib/google/cloud/spanner/fields.rb +8 -8
  28. data/lib/google/cloud/spanner/instance.rb +5 -12
  29. data/lib/google/cloud/spanner/instance/config.rb +1 -1
  30. data/lib/google/cloud/spanner/instance/config/list.rb +1 -1
  31. data/lib/google/cloud/spanner/instance/job.rb +2 -2
  32. data/lib/google/cloud/spanner/instance/list.rb +1 -1
  33. data/lib/google/cloud/spanner/partition.rb +4 -4
  34. data/lib/google/cloud/spanner/policy.rb +2 -2
  35. data/lib/google/cloud/spanner/service.rb +209 -297
  36. data/lib/google/cloud/spanner/session.rb +9 -9
  37. data/lib/google/cloud/spanner/snapshot.rb +2 -2
  38. data/lib/google/cloud/spanner/transaction.rb +2 -2
  39. data/lib/google/cloud/spanner/version.rb +1 -1
  40. metadata +18 -107
  41. data/lib/google/cloud/spanner/admin/database.rb +0 -149
  42. data/lib/google/cloud/spanner/admin/database/v1.rb +0 -147
  43. data/lib/google/cloud/spanner/admin/database/v1/credentials.rb +0 -46
  44. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +0 -1513
  45. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +0 -111
  46. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/iam_policy.rb +0 -64
  47. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/options.rb +0 -33
  48. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/policy.rb +0 -151
  49. data/lib/google/cloud/spanner/admin/database/v1/doc/google/longrunning/operations.rb +0 -51
  50. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/any.rb +0 -131
  51. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/empty.rb +0 -29
  52. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/field_mask.rb +0 -222
  53. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/timestamp.rb +0 -113
  54. data/lib/google/cloud/spanner/admin/database/v1/doc/google/rpc/status.rb +0 -39
  55. data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/backup.rb +0 -325
  56. data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +0 -368
  57. data/lib/google/cloud/spanner/admin/database/v1/doc/google/type/expr.rb +0 -45
  58. data/lib/google/cloud/spanner/admin/instance.rb +0 -164
  59. data/lib/google/cloud/spanner/admin/instance/v1.rb +0 -162
  60. data/lib/google/cloud/spanner/admin/instance/v1/credentials.rb +0 -46
  61. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/iam_policy.rb +0 -64
  62. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/options.rb +0 -33
  63. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/policy.rb +0 -151
  64. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/longrunning/operations.rb +0 -51
  65. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/any.rb +0 -131
  66. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/empty.rb +0 -29
  67. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/field_mask.rb +0 -222
  68. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/rpc/status.rb +0 -39
  69. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +0 -334
  70. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/type/expr.rb +0 -45
  71. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +0 -975
  72. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +0 -76
  73. data/lib/google/cloud/spanner/v1.rb +0 -16
  74. data/lib/google/cloud/spanner/v1/credentials.rb +0 -42
  75. data/lib/google/cloud/spanner/v1/doc/google/protobuf/any.rb +0 -131
  76. data/lib/google/cloud/spanner/v1/doc/google/protobuf/duration.rb +0 -91
  77. data/lib/google/cloud/spanner/v1/doc/google/protobuf/empty.rb +0 -29
  78. data/lib/google/cloud/spanner/v1/doc/google/protobuf/struct.rb +0 -74
  79. data/lib/google/cloud/spanner/v1/doc/google/protobuf/timestamp.rb +0 -113
  80. data/lib/google/cloud/spanner/v1/doc/google/rpc/status.rb +0 -39
  81. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/keys.rb +0 -150
  82. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +0 -95
  83. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/query_plan.rb +0 -121
  84. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/result_set.rb +0 -190
  85. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +0 -570
  86. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/transaction.rb +0 -432
  87. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/type.rb +0 -112
  88. data/lib/google/cloud/spanner/v1/spanner_client.rb +0 -1485
  89. data/lib/google/cloud/spanner/v1/spanner_client_config.json +0 -121
  90. data/lib/google/spanner/admin/database/v1/backup_pb.rb +0 -98
  91. data/lib/google/spanner/admin/database/v1/common_pb.rb +0 -28
  92. data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +0 -141
  93. data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +0 -169
  94. data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_pb.rb +0 -125
  95. data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +0 -181
  96. data/lib/google/spanner/v1/keys_pb.rb +0 -34
  97. data/lib/google/spanner/v1/mutation_pb.rb +0 -39
  98. data/lib/google/spanner/v1/query_plan_pb.rb +0 -48
  99. data/lib/google/spanner/v1/result_set_pb.rb +0 -48
  100. data/lib/google/spanner/v1/spanner_pb.rb +0 -179
  101. data/lib/google/spanner/v1/spanner_services_pb.rb +0 -179
  102. data/lib/google/spanner/v1/transaction_pb.rb +0 -56
  103. data/lib/google/spanner/v1/type_pb.rb +0 -44
@@ -169,12 +169,12 @@ module Google
169
169
  return field.to_grpc_type if field.respond_to? :to_grpc_type
170
170
 
171
171
  if Array === field
172
- Google::Spanner::V1::Type.new(
172
+ V1::Type.new(
173
173
  code: :ARRAY,
174
174
  array_element_type: grpc_type_for_field(field.first)
175
175
  )
176
176
  else
177
- Google::Spanner::V1::Type.new(code: field)
177
+ V1::Type.new(code: field)
178
178
  end
179
179
  end
180
180
 
@@ -274,24 +274,24 @@ module Google
274
274
  range_opts.delete :end_closed
275
275
  end
276
276
 
277
- Google::Spanner::V1::KeyRange.new range_opts
277
+ V1::KeyRange.new range_opts
278
278
  end
279
279
 
280
280
  def to_key_set keys
281
- return Google::Spanner::V1::KeySet.new(all: true) if keys.nil?
281
+ return V1::KeySet.new(all: true) if keys.nil?
282
282
  keys = [keys] unless keys.is_a? Array
283
- return Google::Spanner::V1::KeySet.new(all: true) if keys.empty?
283
+ return V1::KeySet.new(all: true) if keys.empty?
284
284
 
285
285
  if keys_are_ranges? keys
286
286
  key_ranges = keys.map { |r| to_key_range(r) }
287
- return Google::Spanner::V1::KeySet.new(ranges: key_ranges)
287
+ return V1::KeySet.new(ranges: key_ranges)
288
288
  end
289
289
 
290
290
  key_list = keys.map do |key|
291
291
  key = [key] unless key.is_a? Array
292
292
  object_to_grpc_value(key).list_value
293
293
  end
294
- Google::Spanner::V1::KeySet.new keys: key_list
294
+ V1::KeySet.new keys: key_list
295
295
  end
296
296
 
297
297
  def keys_are_ranges? keys
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
- require "google/cloud/spanner/v1/credentials"
16
+ require "google/cloud/spanner/v1/spanner/credentials"
17
17
 
18
18
  module Google
19
19
  module Cloud
@@ -37,7 +37,7 @@ module Google
37
37
  #
38
38
  # spanner.project_id #=> "my-project"
39
39
  #
40
- class Credentials < Google::Cloud::Spanner::V1::Credentials
40
+ class Credentials < Google::Cloud::Spanner::V1::Spanner::Credentials
41
41
  end
42
42
  end
43
43
  end
@@ -216,9 +216,9 @@ module Google
216
216
  ##
217
217
  # @private
218
218
  def to_grpc_type
219
- Google::Spanner::V1::Type.new(
219
+ V1::Type.new(
220
220
  code: :STRUCT,
221
- struct_type: Google::Spanner::V1::StructType.new(
221
+ struct_type: V1::StructType.new(
222
222
  fields: @grpc_fields
223
223
  )
224
224
  )
@@ -229,7 +229,6 @@ module Google
229
229
  true
230
230
  end
231
231
 
232
-
233
232
  # @private
234
233
  DATBASE_OPERATION_METADAT_FILTER_TEMPLATE = [
235
234
  "(metadata.@type:CreateDatabaseMetadata AND " \
@@ -248,10 +247,10 @@ module Google
248
247
  # response.
249
248
  #
250
249
  # The response returns a list of
251
- # {Google::Longrunning::Operation long-running operations} whose names
250
+ # `Google::Longrunning::Operation` long-running operations whose names
252
251
  # are prefixed by a database name within the specified instance.
253
252
  # The long-running operation
254
- # {Google::Longrunning::Operation#metadata metadata} field type
253
+ # `Google::Longrunning::Operation#metadata` metadata field type
255
254
  # `metadata.type_url` describes the type of the metadata.
256
255
  #
257
256
  # The filter expression must specify the field name,
@@ -384,10 +383,9 @@ module Google
384
383
  )
385
384
  end
386
385
 
387
- grpc = service.list_database_operations \
388
- instance_id,
389
- filter: database_filter,
390
- page_size: page_size
386
+ grpc = service.list_database_operations instance_id,
387
+ filter: database_filter,
388
+ page_size: page_size
391
389
  Database::Job::List.from_grpc grpc, service
392
390
  end
393
391
 
@@ -573,20 +571,22 @@ module Google
573
571
  #
574
572
  # The permissions that can be checked on a database are:
575
573
  #
576
- # * pubsub.databases.create
577
- # * pubsub.databases.list
578
- # * pubsub.databases.update
579
- # * pubsub.databases.updateDdl
580
- # * pubsub.databases.get
581
- # * pubsub.databases.getDdl
582
- # * pubsub.databases.getIamPolicy
583
- # * pubsub.databases.setIamPolicy
584
- # * pubsub.databases.beginReadOnlyTransaction
585
- # * pubsub.databases.beginOrRollbackReadWriteTransaction
586
- # * pubsub.databases.read
587
- # * pubsub.databases.select
588
- # * pubsub.databases.write
589
- # * pubsub.databases.drop
574
+ # * spanner.databases.beginPartitionedDmlTransaction
575
+ # * spanner.databases.create
576
+ # * spanner.databases.createBackup
577
+ # * spanner.databases.list
578
+ # * spanner.databases.update
579
+ # * spanner.databases.updateDdl
580
+ # * spanner.databases.get
581
+ # * spanner.databases.getDdl
582
+ # * spanner.databases.getIamPolicy
583
+ # * spanner.databases.setIamPolicy
584
+ # * spanner.databases.beginReadOnlyTransaction
585
+ # * spanner.databases.beginOrRollbackReadWriteTransaction
586
+ # * spanner.databases.read
587
+ # * spanner.databases.select
588
+ # * spanner.databases.write
589
+ # * spanner.databases.drop
590
590
  #
591
591
  # @return [Array<Strings>] The permissions that have access.
592
592
  #
@@ -611,7 +611,7 @@ module Google
611
611
 
612
612
  ##
613
613
  # @private Creates a new Database instance from a
614
- # Google::Spanner::Admin::Database::V1::Database.
614
+ # `Google::Cloud::Spanner::Admin::Database::V1::Database`.
615
615
  def self.from_grpc grpc, service
616
616
  new grpc, service
617
617
  end
@@ -94,7 +94,7 @@ module Google
94
94
 
95
95
  ##
96
96
  # @private Creates a new Database::BackupInfo instance from a
97
- # Google::Spanner::Admin::Database::V1::BackupInfo.
97
+ # `Google::Cloud::Spanner::Admin::Database::V1::BackupInfo`.
98
98
  def self.from_grpc grpc
99
99
  new grpc
100
100
  end
@@ -52,7 +52,7 @@ module Google
52
52
  #
53
53
  class Job
54
54
  ##
55
- # @private The Google::Gax::Operation gRPC object.
55
+ # @private The `Gapic::Operation` gRPC object.
56
56
  attr_accessor :grpc
57
57
 
58
58
  ##
@@ -89,7 +89,7 @@ module Google
89
89
  return nil unless done?
90
90
  return nil unless @grpc.grpc_op.result == :response
91
91
  return nil unless @grpc.results.instance_of? \
92
- Google::Spanner::Admin::Database::V1::Database
92
+ Admin::Database::V1::Database
93
93
  Database.from_grpc @grpc.results, service
94
94
  end
95
95
 
@@ -201,7 +201,7 @@ module Google
201
201
  end
202
202
 
203
203
  ##
204
- # @private New Database::Job from a Google::Gax::Operation object.
204
+ # @private New Database::Job from a `Gapic::Operation` object.
205
205
  def self.from_grpc grpc, service
206
206
  new.tap do |job|
207
207
  job.instance_variable_set :@grpc, grpc
@@ -146,7 +146,7 @@ module Google
146
146
  # @private
147
147
  #
148
148
  # New Database::Job::List from a
149
- # Google::Gax::PagedEnumerable<Google::Longrunning::Operation>
149
+ # `Gapic::PagedEnumerable<Google::Longrunning::Operation>`
150
150
  # object. Operation object is a database operation.
151
151
  #
152
152
  def self.from_grpc grpc, service
@@ -154,7 +154,7 @@ module Google
154
154
  service.databases.instance_variable_get "@operations_client"
155
155
  jobs = new(Array(grpc.response.operations).map do |job_grpc|
156
156
  Job.from_grpc \
157
- Google::Gax::Operation.new(job_grpc, operations_client),
157
+ Gapic::Operation.new(job_grpc, operations_client),
158
158
  service
159
159
  end)
160
160
  jobs.grpc = grpc
@@ -142,7 +142,7 @@ module Google
142
142
 
143
143
  ##
144
144
  # @private New Database::List from a
145
- # Google::Spanner::Admin::Database::V1::ListDatabasesResponse
145
+ # `Google::Cloud::Spanner::Admin::Database::V1::ListDatabasesResponse`
146
146
  # object.
147
147
  def self.from_grpc grpc, service, instance_id, max = nil
148
148
  databases = List.new(Array(grpc.databases).map do |database|
@@ -52,7 +52,7 @@ module Google
52
52
 
53
53
  ##
54
54
  # @private Creates a new Database::RestoreInfo instance from a
55
- # Google::Spanner::Admin::Database::V1::RestoreInfo.
55
+ # `Google::Cloud::Spanner::Admin::Database::V1::RestoreInfo`
56
56
  def self.from_grpc grpc
57
57
  new grpc
58
58
  end
@@ -372,9 +372,9 @@ module Google
372
372
  ##
373
373
  # @private
374
374
  def to_grpc_type
375
- Google::Spanner::V1::Type.new(
375
+ V1::Type.new(
376
376
  code: :STRUCT,
377
- struct_type: Google::Spanner::V1::StructType.new(
377
+ struct_type: V1::StructType.new(
378
378
  fields: @grpc_fields
379
379
  )
380
380
  )
@@ -382,7 +382,7 @@ module Google
382
382
 
383
383
  ##
384
384
  # @private Creates a new Fields instance from a
385
- # Google::Spanner::V1::Metadata::Row_type::Fields.
385
+ # V1::Metadata::Row_type::Fields.
386
386
  def self.from_grpc fields
387
387
  new([]).tap do |f|
388
388
  f.instance_variable_set :@grpc_fields, Array(fields)
@@ -412,18 +412,18 @@ module Google
412
412
  if pair.is_a?(Array)
413
413
  if pair.count == 2
414
414
  if pair.first.is_a?(Integer)
415
- Google::Spanner::V1::StructType::Field.new(
415
+ V1::StructType::Field.new(
416
416
  type: Convert.grpc_type_for_field(pair.last)
417
417
  )
418
418
  else
419
- Google::Spanner::V1::StructType::Field.new(
419
+ V1::StructType::Field.new(
420
420
  name: String(pair.first),
421
421
  type: Convert.grpc_type_for_field(pair.last)
422
422
  )
423
423
  end
424
424
  else
425
- Google::Spanner::V1::StructType::Field.new(
426
- type: Google::Spanner::V1::Type.new(
425
+ V1::StructType::Field.new(
426
+ type: V1::Type.new(
427
427
  code: :ARRAY,
428
428
  array_element_type: Convert.grpc_type_for_field(pair.last)
429
429
  )
@@ -435,7 +435,7 @@ module Google
435
435
  unless pair.is_a?(Symbol)
436
436
  raise ArgumentError, "type must be a symbol"
437
437
  end
438
- Google::Spanner::V1::StructType::Field.new(
438
+ V1::StructType::Field.new(
439
439
  type: Convert.grpc_type_for_field(pair)
440
440
  )
441
441
  end
@@ -342,10 +342,10 @@ module Google
342
342
  # response.
343
343
  #
344
344
  # The response returns a list of
345
- # {Google::Longrunning::Operation long-running operations} whose names
345
+ # `Google::Longrunning::Operation` long-running operations whose names
346
346
  # are prefixed by a database name within the specified instance.
347
347
  # The long-running operation
348
- # {Google::Longrunning::Operation#metadata metadata} field type
348
+ # `Google::Longrunning::Operation#metadata` metadata field type
349
349
  # `metadata.type_url` describes the type of the metadata.
350
350
  #
351
351
  # The filter expression must specify the field name,
@@ -603,10 +603,10 @@ module Google
603
603
  # response.
604
604
  #
605
605
  # The response returns a list of
606
- # {Google::Longrunning::Operation long-running operations} whose names
606
+ # `Google::Longrunning::Operation` long-running operations whose names
607
607
  # are prefixed by a backup name within the specified instance.
608
608
  # The long-running operation
609
- # {Google::Longrunning::Operation#metadata metadata} field type
609
+ # `Google::Longrunning::Operation#metadata` metadata field type
610
610
  # `metadata.type_url` describes the type of the metadata.
611
611
  #
612
612
  # The filter expression must specify the field name of an operation, a
@@ -856,7 +856,7 @@ module Google
856
856
 
857
857
  ##
858
858
  # @private Creates a new Instance instance from a
859
- # Google::Spanner::Admin::Instance::V1::Instance.
859
+ # `Google::Cloud::Spanner::Admin::Instance::V1::Instance`.
860
860
  def self.from_grpc grpc, service
861
861
  new grpc, service
862
862
  end
@@ -869,13 +869,6 @@ module Google
869
869
  def ensure_service!
870
870
  raise "Must have active connection to service" unless service
871
871
  end
872
-
873
- def instance_config_path name
874
- return name if name.to_s.include? "/"
875
- Admin::Instance::V1::InstanceAdminClient.instance_config_path(
876
- project, name.to_s
877
- )
878
- end
879
872
  end
880
873
  end
881
874
  end
@@ -77,7 +77,7 @@ module Google
77
77
 
78
78
  ##
79
79
  # @private Creates a new Instance::Config instance from a
80
- # Google::Spanner::Admin::Instance::V1::InstanceConfig.
80
+ # `Google::Cloud::Spanner::Admin::Instance::V1::InstanceConfig`.
81
81
  def self.from_grpc grpc
82
82
  new grpc
83
83
  end
@@ -142,7 +142,7 @@ module Google
142
142
 
143
143
  ##
144
144
  # @private New Instance::Config::List from a
145
- # Google::Spanner::Admin::Instance::V1::ListInstanceConfigsResponse
145
+ # `Google::Cloud::Spanner::Admin::Instance::V1::ListInstanceConfigsResponse`
146
146
  # object.
147
147
  def self.from_grpc grpc, service, max = nil
148
148
  configs = List.new(Array(grpc.instance_configs).map do |config|
@@ -54,7 +54,7 @@ module Google
54
54
  #
55
55
  class Job
56
56
  ##
57
- # @private The Google::Gax::Operation gRPC object.
57
+ # @private The `Gapic::Operation` gRPC object.
58
58
  attr_accessor :grpc
59
59
 
60
60
  ##
@@ -219,7 +219,7 @@ module Google
219
219
  end
220
220
 
221
221
  ##
222
- # @private New Instance::Job from a Google::Gax::Operation object.
222
+ # @private New Instance::Job from a `Gapic::Operation` object.
223
223
  def self.from_grpc grpc, service
224
224
  new.tap do |job|
225
225
  job.instance_variable_set :@grpc, grpc
@@ -139,7 +139,7 @@ module Google
139
139
 
140
140
  ##
141
141
  # @private New Instance::List from a
142
- # Google::Spanner::Admin::Instance::V1::ListInstancesResponse
142
+ # `Google::Cloud::Spanner::Admin::Instance::V1::ListInstancesResponse`
143
143
  # object.
144
144
  def self.from_grpc grpc, service, max = nil
145
145
  instances = List.new(Array(grpc.instances).map do |instance|
@@ -172,13 +172,13 @@ module Google
172
172
  new.tap do |p|
173
173
  if data[:execute]
174
174
  execute_sql_grpc = \
175
- Google::Spanner::V1::ExecuteSqlRequest.decode(
175
+ V1::ExecuteSqlRequest.decode(
176
176
  Base64.decode64(data[:execute])
177
177
  )
178
178
  p.instance_variable_set :@execute, execute_sql_grpc
179
179
  end
180
180
  if data[:read]
181
- read_grpc = Google::Spanner::V1::ReadRequest.decode \
181
+ read_grpc = V1::ReadRequest.decode \
182
182
  Base64.decode64(data[:read])
183
183
  p.instance_variable_set :@read, read_grpc
184
184
  end
@@ -194,7 +194,7 @@ module Google
194
194
  end
195
195
 
196
196
  ##
197
- # @private New Partition from a Google::Spanner::V1::ExecuteSqlRequest
197
+ # @private New Partition from a `Google::Cloud::Spanner::V1::ExecuteSqlRequest`
198
198
  # object.
199
199
  def self.from_execute_sql_grpc grpc
200
200
  new.tap do |p|
@@ -203,7 +203,7 @@ module Google
203
203
  end
204
204
 
205
205
  ##
206
- # @private New Partition from a Google::Spanner::V1::ReadRequest object.
206
+ # @private New Partition from a `Google::Cloud::Spanner::V1::ReadRequest` object.
207
207
  def self.from_read_grpc grpc
208
208
  new.tap do |p|
209
209
  p.instance_variable_set :@read, grpc
@@ -159,7 +159,7 @@ module Google
159
159
  end
160
160
 
161
161
  ##
162
- # @private Convert the Policy to a Google::Iam::V1::Policy object.
162
+ # @private Convert the Policy to a `Google::Iam::V1::Policy` object.
163
163
  def to_grpc
164
164
  Google::Iam::V1::Policy.new(
165
165
  etag: etag,
@@ -174,7 +174,7 @@ module Google
174
174
  end
175
175
 
176
176
  ##
177
- # @private New Policy from a Google::Iam::V1::Policy object.
177
+ # @private New Policy from a `Google::Iam::V1::Policy` object.
178
178
  def self.from_grpc grpc
179
179
  roles = grpc.bindings.each_with_object({}) do |binding, memo|
180
180
  memo[binding.role] = binding.members.to_a
@@ -20,7 +20,6 @@ require "google/cloud/spanner/v1"
20
20
  require "google/cloud/spanner/admin/instance/v1"
21
21
  require "google/cloud/spanner/admin/database/v1"
22
22
  require "google/cloud/spanner/convert"
23
- require "uri"
24
23
 
25
24
  module Google
26
25
  module Cloud
@@ -29,18 +28,17 @@ module Google
29
28
  # @private Represents the gRPC Spanner service, including all the API
30
29
  # methods.
31
30
  class Service
32
- attr_accessor :project, :credentials, :timeout, :client_config, :host,
33
- :lib_name, :lib_version
31
+ attr_accessor :project, :credentials, :timeout, :host, :lib_name,
32
+ :lib_version
34
33
 
35
34
  ##
36
35
  # Creates a new Service instance.
37
- def initialize project, credentials, host: nil, timeout: nil,
38
- client_config: nil, lib_name: nil, lib_version: nil
36
+ def initialize project, credentials,
37
+ host: nil, timeout: nil, lib_name: nil, lib_version: nil
39
38
  @project = project
40
39
  @credentials = credentials
41
- @host = host || V1::SpannerClient::SERVICE_ADDRESS
40
+ @host = host
42
41
  @timeout = timeout
43
- @client_config = client_config || {}
44
42
  @lib_name = lib_name
45
43
  @lib_version = lib_version
46
44
  end
@@ -64,45 +62,42 @@ module Google
64
62
  def service
65
63
  return mocked_service if mocked_service
66
64
  @service ||= \
67
- V1::SpannerClient.new(
68
- credentials: channel,
69
- timeout: timeout,
70
- client_config: client_config,
71
- service_address: service_address,
72
- service_port: service_port,
73
- lib_name: lib_name_with_prefix,
74
- lib_version: Google::Cloud::Spanner::VERSION
75
- )
65
+ V1::Spanner::Client.new do |config|
66
+ config.credentials = channel
67
+ config.timeout = timeout if timeout
68
+ config.endpoint = host if host
69
+ config.lib_name = lib_name_with_prefix
70
+ config.lib_version = Google::Cloud::Spanner::VERSION
71
+ config.metadata = { "google-cloud-resource-prefix" => "projects/#{@project}" }
72
+ end
76
73
  end
77
74
  attr_accessor :mocked_service
78
75
 
79
76
  def instances
80
77
  return mocked_instances if mocked_instances
81
78
  @instances ||= \
82
- Admin::Instance::V1::InstanceAdminClient.new(
83
- credentials: channel,
84
- timeout: timeout,
85
- client_config: client_config,
86
- service_address: service_address,
87
- service_port: service_port,
88
- lib_name: lib_name_with_prefix,
89
- lib_version: Google::Cloud::Spanner::VERSION
90
- )
79
+ Admin::Instance::V1::InstanceAdmin::Client.new do |config|
80
+ config.credentials = channel
81
+ config.timeout = timeout if timeout
82
+ config.endpoint = host if host
83
+ config.lib_name = lib_name_with_prefix
84
+ config.lib_version = Google::Cloud::Spanner::VERSION
85
+ config.metadata = { "google-cloud-resource-prefix" => "projects/#{@project}" }
86
+ end
91
87
  end
92
88
  attr_accessor :mocked_instances
93
89
 
94
90
  def databases
95
91
  return mocked_databases if mocked_databases
96
92
  @databases ||= \
97
- Admin::Database::V1::DatabaseAdminClient.new(
98
- credentials: channel,
99
- timeout: timeout,
100
- client_config: client_config,
101
- service_address: service_address,
102
- service_port: service_port,
103
- lib_name: lib_name_with_prefix,
104
- lib_version: Google::Cloud::Spanner::VERSION
105
- )
93
+ Admin::Database::V1::DatabaseAdmin::Client.new do |config|
94
+ config.credentials = channel
95
+ config.timeout = timeout if timeout
96
+ config.endpoint = host if host
97
+ config.lib_name = lib_name_with_prefix
98
+ config.lib_version = Google::Cloud::Spanner::VERSION
99
+ config.metadata = { "google-cloud-resource-prefix" => "projects/#{@project}" }
100
+ end
106
101
  end
107
102
  attr_accessor :mocked_databases
108
103
 
@@ -111,194 +106,148 @@ module Google
111
106
  end
112
107
 
113
108
  def list_instances token: nil, max: nil
114
- call_options = nil
115
- call_options = Google::Gax::CallOptions.new page_token: token if token
116
-
117
- execute do
118
- paged_enum = instances.list_instances project_path,
119
- page_size: max,
120
- options: call_options
121
-
122
- paged_enum.page.response
123
- end
109
+ paged_enum = instances.list_instances parent: project_path,
110
+ page_size: max,
111
+ page_token: token
112
+ paged_enum.response
124
113
  end
125
114
 
126
115
  def get_instance name
127
- execute do
128
- instances.get_instance instance_path(name)
129
- end
116
+ instances.get_instance name: instance_path(name)
130
117
  end
131
118
 
132
119
  def create_instance instance_id, name: nil, config: nil, nodes: nil,
133
120
  labels: nil
134
121
  labels = Hash[labels.map { |k, v| [String(k), String(v)] }] if labels
135
122
 
136
- create_obj = Google::Spanner::Admin::Instance::V1::Instance.new({
123
+ create_obj = Admin::Instance::V1::Instance.new({
137
124
  display_name: name, config: instance_config_path(config),
138
125
  node_count: nodes, labels: labels
139
126
  }.delete_if { |_, v| v.nil? })
140
127
 
141
- execute do
142
- instances.create_instance project_path, instance_id, create_obj
143
- end
128
+ instances.create_instance parent: project_path,
129
+ instance_id: instance_id,
130
+ instance: create_obj
144
131
  end
145
132
 
146
- def update_instance instance_obj
133
+ def update_instance instance
147
134
  mask = Google::Protobuf::FieldMask.new(
148
135
  paths: %w[display_name node_count labels]
149
136
  )
150
137
 
151
- execute do
152
- instances.update_instance instance_obj, mask
153
- end
138
+ instances.update_instance instance: instance, field_mask: mask
154
139
  end
155
140
 
156
141
  def delete_instance name
157
- execute do
158
- instances.delete_instance instance_path(name)
159
- end
142
+ instances.delete_instance name: instance_path(name)
160
143
  end
161
144
 
162
145
  def get_instance_policy name
163
- execute do
164
- instances.get_iam_policy instance_path(name)
165
- end
146
+ instances.get_iam_policy resource: instance_path(name)
166
147
  end
167
148
 
168
149
  def set_instance_policy name, new_policy
169
- execute do
170
- instances.set_iam_policy instance_path(name), new_policy
171
- end
150
+ instances.set_iam_policy resource: instance_path(name),
151
+ policy: new_policy
172
152
  end
173
153
 
174
154
  def test_instance_permissions name, permissions
175
- execute do
176
- instances.test_iam_permissions instance_path(name), permissions
177
- end
155
+ instances.test_iam_permissions resource: instance_path(name),
156
+ permissions: permissions
178
157
  end
179
158
 
180
159
  def list_instance_configs token: nil, max: nil
181
- call_options = nil
182
- call_options = Google::Gax::CallOptions.new page_token: token if token
183
-
184
- execute do
185
- paged_enum = instances.list_instance_configs project_path,
186
- page_size: max,
187
- options: call_options
188
-
189
- paged_enum.page.response
190
- end
160
+ paged_enum = instances.list_instance_configs \
161
+ parent: project_path, page_size: max, page_token: token
162
+ paged_enum.response
191
163
  end
192
164
 
193
165
  def get_instance_config name
194
- execute do
195
- instances.get_instance_config instance_config_path(name)
196
- end
166
+ instances.get_instance_config name: instance_config_path(name)
197
167
  end
198
168
 
199
169
  def list_databases instance_id, token: nil, max: nil
200
- call_options = nil
201
- call_options = Google::Gax::CallOptions.new page_token: token if token
202
-
203
- execute do
204
- paged_enum = databases.list_databases instance_path(instance_id),
205
- page_size: max,
206
- options: call_options
207
-
208
- paged_enum.page.response
209
- end
170
+ paged_enum = databases.list_databases \
171
+ parent: instance_path(instance_id),
172
+ page_size: max,
173
+ page_token: token
174
+ paged_enum.response
210
175
  end
211
176
 
212
177
  def get_database instance_id, database_id
213
- execute do
214
- databases.get_database database_path(instance_id, database_id)
215
- end
178
+ databases.get_database name: database_path(instance_id, database_id)
216
179
  end
217
180
 
218
181
  def create_database instance_id, database_id, statements: []
219
- execute do
220
- databases.create_database \
221
- instance_path(instance_id),
222
- "CREATE DATABASE `#{database_id}`",
223
- extra_statements: Array(statements)
224
- end
182
+ databases.create_database \
183
+ parent: instance_path(instance_id),
184
+ create_statement: "CREATE DATABASE `#{database_id}`",
185
+ extra_statements: Array(statements)
225
186
  end
226
187
 
227
188
  def drop_database instance_id, database_id
228
- execute do
229
- databases.drop_database database_path(instance_id, database_id)
230
- end
189
+ databases.drop_database \
190
+ database: database_path(instance_id, database_id)
231
191
  end
232
192
 
233
193
  def get_database_ddl instance_id, database_id
234
- execute do
235
- databases.get_database_ddl database_path(instance_id, database_id)
236
- end
194
+ databases.get_database_ddl \
195
+ database: database_path(instance_id, database_id)
237
196
  end
238
197
 
239
198
  def update_database_ddl instance_id, database_id, statements: [],
240
199
  operation_id: nil
241
- execute do
242
- databases.update_database_ddl \
243
- database_path(instance_id, database_id),
244
- Array(statements),
245
- operation_id: operation_id
246
- end
200
+ databases.update_database_ddl \
201
+ database: database_path(instance_id, database_id),
202
+ statements: Array(statements),
203
+ operation_id: operation_id
247
204
  end
248
205
 
249
206
  def get_database_policy instance_id, database_id
250
- execute do
251
- databases.get_iam_policy database_path(instance_id, database_id)
252
- end
207
+ databases.get_iam_policy \
208
+ resource: database_path(instance_id, database_id)
253
209
  end
254
210
 
255
211
  def set_database_policy instance_id, database_id, new_policy
256
- execute do
257
- databases.set_iam_policy \
258
- database_path(instance_id, database_id), new_policy
259
- end
212
+ databases.set_iam_policy \
213
+ resource: database_path(instance_id, database_id),
214
+ policy: new_policy
260
215
  end
261
216
 
262
217
  def test_database_permissions instance_id, database_id, permissions
263
- execute do
264
- databases.test_iam_permissions \
265
- database_path(instance_id, database_id), permissions
266
- end
218
+ databases.test_iam_permissions \
219
+ resource: database_path(instance_id, database_id),
220
+ permissions: permissions
267
221
  end
268
222
 
269
223
  def get_session session_name
270
224
  opts = default_options_from_session session_name
271
- execute do
272
- service.get_session session_name, options: opts
273
- end
225
+ service.get_session({ name: session_name }, opts)
274
226
  end
275
227
 
276
228
  def create_session database_name, labels: nil
277
229
  opts = default_options_from_session database_name
278
- session = Google::Spanner::V1::Session.new labels: labels if labels
279
- execute do
280
- service.create_session database_name, session: session,
281
- options: opts
282
- end
230
+ session = V1::Session.new labels: labels if labels
231
+ service.create_session(
232
+ { database: database_name, session: session }, opts
233
+ )
283
234
  end
284
235
 
285
236
  def batch_create_sessions database_name, session_count, labels: nil
286
237
  opts = default_options_from_session database_name
287
- session = Google::Spanner::V1::Session.new labels: labels if labels
288
- execute do
289
- # The response may have fewer sessions than requested in the RPC.
290
- service.batch_create_sessions database_name,
291
- session_count,
292
- session_template: session,
293
- options: opts
294
- end
238
+ session = V1::Session.new labels: labels if labels
239
+ # The response may have fewer sessions than requested in the RPC.
240
+ request = {
241
+ database: database_name,
242
+ session_count: session_count,
243
+ session_template: session
244
+ }
245
+ service.batch_create_sessions request, opts
295
246
  end
296
247
 
297
248
  def delete_session session_name
298
249
  opts = default_options_from_session session_name
299
- execute do
300
- service.delete_session session_name, options: opts
301
- end
250
+ service.delete_session({ name: session_name }, opts)
302
251
  end
303
252
 
304
253
  def execute_streaming_sql session_name, sql, transaction: nil,
@@ -306,29 +255,31 @@ module Google
306
255
  partition_token: nil, seqno: nil,
307
256
  query_options: nil
308
257
  opts = default_options_from_session session_name
309
- execute do
310
- service.execute_streaming_sql \
311
- session_name, sql, transaction: transaction,
312
- params: params,
313
- param_types: types,
314
- resume_token: resume_token,
315
- partition_token: partition_token,
316
- seqno: seqno,
317
- query_options: query_options,
318
- options: opts
319
- end
258
+ request = {
259
+ session: session_name,
260
+ sql: sql,
261
+ transaction: transaction,
262
+ params: params,
263
+ param_types: types,
264
+ resume_token: resume_token,
265
+ partition_token: partition_token,
266
+ seqno: seqno,
267
+ query_options: query_options
268
+ }
269
+ service.execute_streaming_sql request, opts
320
270
  end
321
271
 
322
272
  def execute_batch_dml session_name, transaction, statements, seqno
323
273
  opts = default_options_from_session session_name
324
274
  statements = statements.map(&:to_grpc)
325
- results = execute do
326
- service.execute_batch_dml session_name,
327
- transaction,
328
- statements,
329
- seqno,
330
- options: opts
331
- end
275
+ request = {
276
+ session: session_name,
277
+ transaction: transaction,
278
+ statements: statements,
279
+ seqno: seqno
280
+ }
281
+ results = service.execute_batch_dml request, opts
282
+
332
283
  if results.status.code.zero?
333
284
  results.result_sets.map { |rs| rs.stats.row_count_exact }
334
285
  else
@@ -344,13 +295,13 @@ module Google
344
295
  index: nil, transaction: nil, limit: nil,
345
296
  resume_token: nil, partition_token: nil
346
297
  opts = default_options_from_session session_name
347
- execute do
348
- service.streaming_read \
349
- session_name, table_name, columns, keys,
350
- transaction: transaction, index: index, limit: limit,
351
- resume_token: resume_token, partition_token: partition_token,
352
- options: opts
353
- end
298
+ request = {
299
+ session: session_name, table: table_name, columns: columns,
300
+ key_set: keys, transaction: transaction, index: index,
301
+ limit: limit, resume_token: resume_token,
302
+ partition_token: partition_token
303
+ }
304
+ service.streaming_read request, opts
354
305
  end
355
306
 
356
307
  def partition_read session_name, table_name, columns, transaction,
@@ -360,13 +311,12 @@ module Google
360
311
  max_partitions
361
312
 
362
313
  opts = default_options_from_session session_name
363
-
364
- execute do
365
- service.partition_read \
366
- session_name, table_name, keys,
367
- transaction: transaction, index: index, columns: columns,
368
- partition_options: partition_opts, options: opts
369
- end
314
+ request = {
315
+ session: session_name, table: table_name, key_set: keys,
316
+ transaction: transaction, index: index, columns: columns,
317
+ partition_options: partition_opts
318
+ }
319
+ service.partition_read request, opts
370
320
  end
371
321
 
372
322
  def partition_query session_name, sql, transaction, params: nil,
@@ -376,53 +326,48 @@ module Google
376
326
  max_partitions
377
327
 
378
328
  opts = default_options_from_session session_name
379
-
380
- execute do
381
- service.partition_query \
382
- session_name, sql,
383
- transaction: transaction,
384
- params: params, param_types: types,
385
- partition_options: partition_opts, options: opts
386
- end
329
+ request = {
330
+ session: session_name, sql: sql, transaction: transaction,
331
+ params: params, param_types: types,
332
+ partition_options: partition_opts
333
+ }
334
+ service.partition_query request, opts
387
335
  end
388
336
 
389
337
  def commit session_name, mutations = [], transaction_id: nil
390
338
  tx_opts = nil
391
339
  if transaction_id.nil?
392
- tx_opts = Google::Spanner::V1::TransactionOptions.new(
393
- read_write: Google::Spanner::V1::TransactionOptions::ReadWrite.new
340
+ tx_opts = V1::TransactionOptions.new(
341
+ read_write: V1::TransactionOptions::ReadWrite.new
394
342
  )
395
343
  end
396
344
  opts = default_options_from_session session_name
397
- execute do
398
- service.commit \
399
- session_name, mutations,
400
- transaction_id: transaction_id, single_use_transaction: tx_opts,
401
- options: opts
402
- end
345
+ request = {
346
+ session: session_name, transaction_id: transaction_id,
347
+ single_use_transaction: tx_opts, mutations: mutations
348
+ }
349
+ service.commit request, opts
403
350
  end
404
351
 
405
352
  def rollback session_name, transaction_id
406
353
  opts = default_options_from_session session_name
407
- execute do
408
- service.rollback session_name, transaction_id, options: opts
409
- end
354
+ request = { session: session_name, transaction_id: transaction_id }
355
+ service.rollback request, opts
410
356
  end
411
357
 
412
358
  def begin_transaction session_name
413
- tx_opts = Google::Spanner::V1::TransactionOptions.new(
414
- read_write: Google::Spanner::V1::TransactionOptions::ReadWrite.new
359
+ tx_opts = V1::TransactionOptions.new(
360
+ read_write: V1::TransactionOptions::ReadWrite.new
415
361
  )
416
362
  opts = default_options_from_session session_name
417
- execute do
418
- service.begin_transaction session_name, tx_opts, options: opts
419
- end
363
+ request = { session: session_name, options: tx_opts }
364
+ service.begin_transaction request, opts
420
365
  end
421
366
 
422
367
  def create_snapshot session_name, strong: nil, timestamp: nil,
423
368
  staleness: nil
424
- tx_opts = Google::Spanner::V1::TransactionOptions.new(
425
- read_only: Google::Spanner::V1::TransactionOptions::ReadOnly.new(
369
+ tx_opts = V1::TransactionOptions.new(
370
+ read_only: V1::TransactionOptions::ReadOnly.new(
426
371
  {
427
372
  strong: strong,
428
373
  read_timestamp: Convert.time_to_timestamp(timestamp),
@@ -432,20 +377,17 @@ module Google
432
377
  )
433
378
  )
434
379
  opts = default_options_from_session session_name
435
- execute do
436
- service.begin_transaction session_name, tx_opts, options: opts
437
- end
380
+ request = { session: session_name, options: tx_opts }
381
+ service.begin_transaction request, opts
438
382
  end
439
383
 
440
384
  def create_pdml session_name
441
- tx_opts = Google::Spanner::V1::TransactionOptions.new(
442
- partitioned_dml: \
443
- Google::Spanner::V1::TransactionOptions::PartitionedDml.new
385
+ tx_opts = V1::TransactionOptions.new(
386
+ partitioned_dml: V1::TransactionOptions::PartitionedDml.new
444
387
  )
445
388
  opts = default_options_from_session session_name
446
- execute do
447
- service.begin_transaction session_name, tx_opts, options: opts
448
- end
389
+ request = { session: session_name, options: tx_opts }
390
+ service.begin_transaction request, opts
449
391
  end
450
392
 
451
393
  def create_backup instance_id, database_id, backup_id, expire_time
@@ -453,70 +395,61 @@ module Google
453
395
  database: database_path(instance_id, database_id),
454
396
  expire_time: expire_time
455
397
  }
456
- execute do
457
- databases.create_backup \
458
- instance_path(instance_id),
459
- backup_id,
460
- backup
461
- end
398
+ databases.create_backup parent: instance_path(instance_id),
399
+ backup_id: backup_id,
400
+ backup: backup
462
401
  end
463
402
 
464
403
  def get_backup instance_id, backup_id
465
- execute do
466
- databases.get_backup backup_path(instance_id, backup_id)
467
- end
404
+ databases.get_backup name: backup_path(instance_id, backup_id)
468
405
  end
469
406
 
470
407
  def update_backup backup, update_mask
471
- execute do
472
- databases.update_backup backup, update_mask
473
- end
408
+ databases.update_backup backup: backup, update_mask: update_mask
474
409
  end
475
410
 
476
411
  def delete_backup instance_id, backup_id
477
- execute do
478
- databases.delete_backup backup_path(instance_id, backup_id)
479
- end
480
- end
481
-
482
- def list_backups instance_id, filter: nil, page_size: nil
483
- execute do
484
- databases.list_backups \
485
- instance_path(instance_id),
486
- filter,
487
- page_size: page_size
488
- end
489
- end
490
-
491
- def list_database_operations instance_id, filter: nil, page_size: nil
492
- execute do
493
- databases.list_database_operations \
494
- instance_path(instance_id),
495
- filter,
496
- page_size: page_size
497
- end
412
+ databases.delete_backup name: backup_path(instance_id, backup_id)
413
+ end
414
+
415
+ def list_backups instance_id,
416
+ filter: nil, page_size: nil, page_token: nil
417
+ databases.list_backups parent: instance_path(instance_id),
418
+ filter: filter,
419
+ page_size: page_size,
420
+ page_token: page_token
421
+ end
422
+
423
+ def list_database_operations instance_id,
424
+ filter: nil,
425
+ page_size: nil,
426
+ page_token: nil
427
+ databases.list_database_operations(
428
+ parent: instance_path(instance_id),
429
+ filter: filter,
430
+ page_size: page_size,
431
+ page_token: page_token
432
+ )
498
433
  end
499
434
 
500
- def list_backup_operations instance_id, filter: nil, page_size: nil
501
- execute do
502
- databases.list_backup_operations \
503
- instance_path(instance_id),
504
- filter,
505
- page_size: page_size
506
- end
435
+ def list_backup_operations instance_id,
436
+ filter: nil, page_size: nil,
437
+ page_token: nil
438
+ databases.list_backup_operations(
439
+ parent: instance_path(instance_id),
440
+ filter: filter,
441
+ page_size: page_size,
442
+ page_token: page_token
443
+ )
507
444
  end
508
445
 
509
- def restore_database \
510
- backup_instance_id,
511
- backup_id,
512
- database_instance_id,
513
- database_id
514
- execute do
515
- databases.restore_database \
516
- instance_path(database_instance_id),
517
- database_id,
518
- backup: backup_path(backup_instance_id, backup_id)
519
- end
446
+ def restore_database backup_instance_id, backup_id,
447
+ database_instance_id, database_id
448
+ databases.restore_database(
449
+ parent: instance_path(database_instance_id),
450
+ database_id: database_id,
451
+ backup: backup_path(backup_instance_id, backup_id)
452
+ )
520
453
  end
521
454
 
522
455
  def inspect
@@ -525,16 +458,6 @@ module Google
525
458
 
526
459
  protected
527
460
 
528
- def service_address
529
- return nil if host.nil?
530
- URI.parse("//#{host}").host
531
- end
532
-
533
- def service_port
534
- return nil if host.nil?
535
- URI.parse("//#{host}").port
536
- end
537
-
538
461
  def lib_name_with_prefix
539
462
  return "gccl" if [nil, "gccl"].include? lib_name
540
463
 
@@ -545,13 +468,12 @@ module Google
545
468
 
546
469
  def default_options_from_session session_name
547
470
  default_prefix = session_name.split("/sessions/").first
548
- Google::Gax::CallOptions.new kwargs: \
549
- { "google-cloud-resource-prefix" => default_prefix }
471
+ { metadata: { "google-cloud-resource-prefix" => default_prefix } }
550
472
  end
551
473
 
552
474
  def partition_options partition_size_bytes, max_partitions
553
475
  return nil unless partition_size_bytes || max_partitions
554
- partition_opts = Google::Spanner::V1::PartitionOptions.new
476
+ partition_opts = V1::PartitionOptions.new
555
477
  if partition_size_bytes
556
478
  partition_opts.partition_size_bytes = partition_size_bytes
557
479
  end
@@ -560,48 +482,38 @@ module Google
560
482
  end
561
483
 
562
484
  def project_path
563
- Admin::Instance::V1::InstanceAdminClient.project_path project
485
+ Admin::Instance::V1::InstanceAdmin::Paths.project_path \
486
+ project: project
564
487
  end
565
488
 
566
489
  def instance_path name
567
490
  return name if name.to_s.include? "/"
568
- Admin::Instance::V1::InstanceAdminClient.instance_path(
569
- project, name
570
- )
491
+
492
+ Admin::Instance::V1::InstanceAdmin::Paths.instance_path \
493
+ project: project, instance: name
571
494
  end
572
495
 
573
496
  def instance_config_path name
574
497
  return name if name.to_s.include? "/"
575
- Admin::Instance::V1::InstanceAdminClient.instance_config_path(
576
- project, name.to_s
577
- )
498
+
499
+ Admin::Instance::V1::InstanceAdmin::Paths.instance_config_path \
500
+ project: project, instance_config: name
578
501
  end
579
502
 
580
503
  def database_path instance_id, database_id
581
- Admin::Database::V1::DatabaseAdminClient.database_path(
582
- project, instance_id, database_id
583
- )
504
+ Admin::Database::V1::DatabaseAdmin::Paths.database_path \
505
+ project: project, instance: instance_id, database: database_id
584
506
  end
585
507
 
586
508
  def session_path instance_id, database_id, session_id
587
- V1::SpannerClient.session_path(
588
- project, instance_id, database_id, session_id
589
- )
509
+ V1::Spanner::Paths.session_path \
510
+ project: project, instance: instance_id, database: database_id,
511
+ session: session_id
590
512
  end
591
513
 
592
514
  def backup_path instance_id, backup_id
593
- Admin::Database::V1::DatabaseAdminClient.backup_path(
594
- project, instance_id, backup_id
595
- )
596
- end
597
-
598
- def execute
599
- yield
600
- rescue Google::Gax::GaxError => e
601
- # GaxError wraps BadStatus, but exposes it as #cause
602
- raise Google::Cloud::Error.from_error(e.cause)
603
- rescue GRPC::BadStatus => e
604
- raise Google::Cloud::Error.from_error(e)
515
+ Admin::Database::V1::DatabaseAdmin::Paths.backup_path \
516
+ project: project, instance: instance_id, backup: backup_id
605
517
  end
606
518
  end
607
519
  end