google-cloud-spanner 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/lib/google-cloud-spanner.rb +106 -0
  3. data/lib/google/cloud/spanner.rb +382 -0
  4. data/lib/google/cloud/spanner/admin/database/v1.rb +17 -0
  5. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +703 -0
  6. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +73 -0
  7. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/policy.rb +139 -0
  8. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/any.rb +114 -0
  9. data/lib/google/cloud/spanner/admin/database/v1/doc/google/rpc/status.rb +83 -0
  10. data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +188 -0
  11. data/lib/google/cloud/spanner/admin/instance/v1.rb +17 -0
  12. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/policy.rb +139 -0
  13. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/any.rb +114 -0
  14. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/field_mask.rb +223 -0
  15. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/rpc/status.rb +83 -0
  16. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +268 -0
  17. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +868 -0
  18. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +78 -0
  19. data/lib/google/cloud/spanner/client.rb +1034 -0
  20. data/lib/google/cloud/spanner/commit.rb +351 -0
  21. data/lib/google/cloud/spanner/convert.rb +311 -0
  22. data/lib/google/cloud/spanner/credentials.rb +32 -0
  23. data/lib/google/cloud/spanner/data.rb +199 -0
  24. data/lib/google/cloud/spanner/database.rb +377 -0
  25. data/lib/google/cloud/spanner/database/job.rb +179 -0
  26. data/lib/google/cloud/spanner/database/list.rb +171 -0
  27. data/lib/google/cloud/spanner/errors.rb +73 -0
  28. data/lib/google/cloud/spanner/fields.rb +252 -0
  29. data/lib/google/cloud/spanner/instance.rb +472 -0
  30. data/lib/google/cloud/spanner/instance/config.rb +99 -0
  31. data/lib/google/cloud/spanner/instance/config/list.rb +171 -0
  32. data/lib/google/cloud/spanner/instance/job.rb +197 -0
  33. data/lib/google/cloud/spanner/instance/list.rb +167 -0
  34. data/lib/google/cloud/spanner/policy.rb +201 -0
  35. data/lib/google/cloud/spanner/pool.rb +279 -0
  36. data/lib/google/cloud/spanner/project.rb +480 -0
  37. data/lib/google/cloud/spanner/range.rb +99 -0
  38. data/lib/google/cloud/spanner/results.rb +280 -0
  39. data/lib/google/cloud/spanner/service.rb +458 -0
  40. data/lib/google/cloud/spanner/session.rb +565 -0
  41. data/lib/google/cloud/spanner/snapshot.rb +260 -0
  42. data/lib/google/cloud/spanner/transaction.rb +533 -0
  43. data/lib/google/cloud/spanner/v1.rb +17 -0
  44. data/lib/google/cloud/spanner/v1/doc/google/protobuf/duration.rb +77 -0
  45. data/lib/google/cloud/spanner/v1/doc/google/protobuf/struct.rb +73 -0
  46. data/lib/google/cloud/spanner/v1/doc/google/protobuf/timestamp.rb +81 -0
  47. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/keys.rb +148 -0
  48. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +80 -0
  49. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/query_plan.rb +120 -0
  50. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/result_set.rb +175 -0
  51. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +206 -0
  52. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/transaction.rb +351 -0
  53. data/lib/google/cloud/spanner/v1/spanner_client.rb +850 -0
  54. data/lib/google/cloud/spanner/v1/spanner_client_config.json +78 -0
  55. data/lib/google/cloud/spanner/version.rb +22 -0
  56. data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +85 -0
  57. data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +95 -0
  58. data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_pb.rb +106 -0
  59. data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +180 -0
  60. data/lib/google/spanner/v1/keys_pb.rb +33 -0
  61. data/lib/google/spanner/v1/mutation_pb.rb +38 -0
  62. data/lib/google/spanner/v1/query_plan_pb.rb +47 -0
  63. data/lib/google/spanner/v1/result_set_pb.rb +43 -0
  64. data/lib/google/spanner/v1/spanner_pb.rb +90 -0
  65. data/lib/google/spanner/v1/spanner_services_pb.rb +131 -0
  66. data/lib/google/spanner/v1/transaction_pb.rb +51 -0
  67. data/lib/google/spanner/v1/type_pb.rb +43 -0
  68. metadata +309 -0
@@ -0,0 +1,99 @@
1
+ # Copyright 2016 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ require "google/cloud/spanner/instance/config/list"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Spanner
21
+ class Instance
22
+ ##
23
+ # # Instance Config
24
+ #
25
+ # Represents a Cloud Spanner instance configuration. Instance
26
+ # configurations define the geographic placement of nodes and their
27
+ # replication.
28
+ #
29
+ # See {Google::Cloud::Spanner::Project#instance_configs} and
30
+ # {Google::Cloud::Spanner::Project#instance_config}.
31
+ #
32
+ # @example
33
+ # require "google/cloud/spanner"
34
+ #
35
+ # spanner = Google::Cloud::Spanner.new
36
+ #
37
+ # instance_configs = spanner.instance_configs
38
+ # instance_configs.each do |config|
39
+ # puts config.instance_config_id
40
+ # end
41
+ #
42
+ class Config
43
+ ##
44
+ # @private Creates a new Instance::Config instance.
45
+ def initialize grpc
46
+ @grpc = grpc
47
+ end
48
+
49
+ # The unique identifier for the project.
50
+ # @return [String]
51
+ def project_id
52
+ Admin::Instance::V1::InstanceAdminClient
53
+ .match_project_from_instance_config_name @grpc.name
54
+ end
55
+
56
+ ##
57
+ # A unique identifier for the instance configuration.
58
+ # @return [String]
59
+ def instance_config_id
60
+ Admin::Instance::V1::InstanceAdminClient
61
+ .match_instance_config_from_instance_config_name @grpc.name
62
+ end
63
+
64
+ ##
65
+ # The full path for the instance config resource. Values are of the
66
+ # form `projects/<project_id>/instanceConfigs/<instance_config_id>`.
67
+ # @return [String]
68
+ def path
69
+ @grpc.name
70
+ end
71
+
72
+ ##
73
+ # The name of this instance configuration as it appears in UIs.
74
+ # @return [String]
75
+ def name
76
+ @grpc.display_name
77
+ end
78
+ alias_method :display_name, :name
79
+
80
+ ##
81
+ # @private Creates a new Instance::Config instance from a
82
+ # Google::Spanner::Admin::Instance::V1::InstanceConfig.
83
+ def self.from_grpc grpc
84
+ new grpc
85
+ end
86
+
87
+ protected
88
+
89
+ ##
90
+ # @private Raise an error unless an active connection to the service
91
+ # is available.
92
+ def ensure_service!
93
+ fail "Must have active connection to service" unless service
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,171 @@
1
+ # Copyright 2016 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ require "delegate"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Spanner
21
+ class Instance
22
+ class Config
23
+ ##
24
+ # Instance::Config::List is a special case Array with additional
25
+ # values.
26
+ class List < DelegateClass(::Array)
27
+ ##
28
+ # If not empty, indicates that there are more records that match
29
+ # the request and this value should be passed to continue.
30
+ attr_accessor :token
31
+
32
+ ##
33
+ # @private Create a new Instance::Config::List with an array of
34
+ # Instance::Config instances.
35
+ def initialize arr = []
36
+ super arr
37
+ end
38
+
39
+ ##
40
+ # Whether there is a next page of instance configs.
41
+ #
42
+ # @return [Boolean]
43
+ #
44
+ # @example
45
+ # require "google/cloud/spanner"
46
+ #
47
+ # spanner = Google::Cloud::Spanner.new
48
+ #
49
+ # configs = spanner.instance_configs
50
+ # if configs.next?
51
+ # next_configs = configs.next
52
+ # end
53
+ def next?
54
+ !token.nil?
55
+ end
56
+
57
+ ##
58
+ # Retrieve the next page of instance configurations.
59
+ #
60
+ # @return [Instance::Config::List] The list of instance
61
+ # configurations.
62
+ #
63
+ # @example
64
+ # require "google/cloud/spanner"
65
+ #
66
+ # spanner = Google::Cloud::Spanner.new
67
+ #
68
+ # configs = spanner.instance_configs
69
+ # if configs.next?
70
+ # next_configs = configs.next
71
+ # end
72
+ def next
73
+ return nil unless next?
74
+ ensure_service!
75
+ options = { token: token, max: @max }
76
+ grpc = @service.list_instance_configs options
77
+ self.class.from_grpc grpc, @service, @max
78
+ end
79
+
80
+ ##
81
+ # Retrieves remaining results by repeatedly invoking {#next} until
82
+ # {#next?} returns `false`. Calls the given block once for each
83
+ # result, which is passed as the argument to the block.
84
+ #
85
+ # An Enumerator is returned if no block is given.
86
+ #
87
+ # This method will make repeated API calls until all remaining
88
+ # results are retrieved. (Unlike `#each`, for example, which merely
89
+ # iterates over the results returned by a single API call.) Use with
90
+ # caution.
91
+ #
92
+ # @param [Integer] request_limit The upper limit of API requests to
93
+ # make to load all configs. Default is no limit.
94
+ # @yield [config] The block for accessing each instance config.
95
+ # @yieldparam [Instance::Config] config The instance config object.
96
+ #
97
+ # @return [Enumerator]
98
+ #
99
+ # @example Iterating each instance config by passing a block:
100
+ # require "google/cloud/spanner"
101
+ #
102
+ # spanner = Google::Cloud::Spanner.new
103
+ #
104
+ # spanner.instance_configs.all do |config|
105
+ # puts config.instance_config_id
106
+ # end
107
+ #
108
+ # @example Using the enumerator by not passing a block:
109
+ # require "google/cloud/spanner"
110
+ #
111
+ # spanner = Google::Cloud::Spanner.new
112
+ #
113
+ # all_config_ids = spanner.instance_configs.all.map do |config|
114
+ # config.instance_config_id
115
+ # end
116
+ #
117
+ # @example Limit the number of API calls made:
118
+ # require "google/cloud/spanner"
119
+ #
120
+ # spanner = Google::Cloud::Spanner.new
121
+ #
122
+ # spanner.instance_configs.all(request_limit: 10) do |config|
123
+ # puts config.instance_config_id
124
+ # end
125
+ #
126
+ def all request_limit: nil
127
+ request_limit = request_limit.to_i if request_limit
128
+ unless block_given?
129
+ return enum_for(:all, request_limit: request_limit)
130
+ end
131
+ results = self
132
+ loop do
133
+ results.each { |r| yield r }
134
+ if request_limit
135
+ request_limit -= 1
136
+ break if request_limit < 0
137
+ end
138
+ break unless results.next?
139
+ results = results.next
140
+ end
141
+ end
142
+
143
+ ##
144
+ # @private New Instance::Config::List from a
145
+ # Google::Spanner::Admin::Instance::V1::ListInstanceConfigsResponse
146
+ # object.
147
+ def self.from_grpc grpc, service, max = nil
148
+ configs = List.new(Array(grpc.instance_configs).map do |config|
149
+ Instance::Config.from_grpc config
150
+ end)
151
+ token = grpc.next_page_token
152
+ token = nil if token == ""
153
+ configs.instance_variable_set :@token, token
154
+ configs.instance_variable_set :@service, service
155
+ configs.instance_variable_set :@max, max
156
+ configs
157
+ end
158
+
159
+ protected
160
+
161
+ ##
162
+ # Raise an error unless an active service is available.
163
+ def ensure_service!
164
+ fail "Must have active connection" unless @service
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,197 @@
1
+ # Copyright 2016 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module Google
17
+ module Cloud
18
+ module Spanner
19
+ class Instance
20
+ ##
21
+ # # Job
22
+ #
23
+ # A resource representing the long-running, asynchronous processing of
24
+ # an instance create or update operation. The job can be refreshed to
25
+ # retrieve the instance object once the operation has been completed.
26
+ #
27
+ # See {Project#create_instance} and {Instance#update}.
28
+ #
29
+ # @see https://cloud.google.com/spanner/reference/rpc/google.longrunning#google.longrunning.Operation
30
+ # Long-running Operation
31
+ #
32
+ # @example
33
+ # require "google/cloud/spanner"
34
+ #
35
+ # spanner = Google::Cloud::Spanner.new
36
+ #
37
+ # job = spanner.create_instance "my-new-instance",
38
+ # name: "My New Instance",
39
+ # config: "regional-us-central1",
40
+ # nodes: 5,
41
+ # labels: { production: :env }
42
+ #
43
+ # job.done? #=> false
44
+ # job.reload! # API call
45
+ # job.done? #=> true
46
+ # instance = job.instance
47
+ #
48
+ class Job
49
+ ##
50
+ # @private The Google::Gax::Operation gRPC object.
51
+ attr_accessor :grpc
52
+
53
+ ##
54
+ # @private The gRPC Service object.
55
+ attr_accessor :service
56
+
57
+ ##
58
+ # @private Creates a new Instance::Job instance.
59
+ def initialize
60
+ @grpc = nil
61
+ @service = nil
62
+ end
63
+
64
+ ##
65
+ # The instance that is the object of the operation.
66
+ #
67
+ # @return [Google::Cloud::Spanner::Instance, nil] The instance, or
68
+ # `nil` if the operation is not complete.
69
+ #
70
+ # @example
71
+ # require "google/cloud/spanner"
72
+ #
73
+ # spanner = Google::Cloud::Spanner.new
74
+ #
75
+ # job = spanner.create_instance "my-new-instance",
76
+ # name: "My New Instance",
77
+ # config: "regional-us-central1",
78
+ # nodes: 5,
79
+ # labels: { production: :env }
80
+ #
81
+ # job.done? #=> true
82
+ # instance = job.instance
83
+ #
84
+ def instance
85
+ return nil unless done?
86
+ return nil unless @grpc.grpc_op.result == :response
87
+ Instance.from_grpc @grpc.results, service
88
+ end
89
+
90
+ ##
91
+ # Checks if the processing of the instance operation is complete.
92
+ #
93
+ # @return [boolean] `true` when complete, `false` otherwise.
94
+ #
95
+ # @example
96
+ # require "google/cloud/spanner"
97
+ #
98
+ # spanner = Google::Cloud::Spanner.new
99
+ #
100
+ # job = spanner.create_instance "my-new-instance",
101
+ # name: "My New Instance",
102
+ # config: "regional-us-central1",
103
+ # nodes: 5,
104
+ # labels: { production: :env }
105
+ #
106
+ # job.done? #=> false
107
+ #
108
+ def done?
109
+ @grpc.done?
110
+ end
111
+
112
+ ##
113
+ # Checks if the processing of the instance operation has errored.
114
+ #
115
+ # @return [boolean] `true` when errored, `false` otherwise.
116
+ #
117
+ # @example
118
+ # require "google/cloud/spanner"
119
+ #
120
+ # spanner = Google::Cloud::Spanner.new
121
+ #
122
+ # job = spanner.create_instance "my-new-instance",
123
+ # name: "My New Instance",
124
+ # config: "regional-us-central1",
125
+ # nodes: 5,
126
+ # labels: { production: :env }
127
+ #
128
+ # job.error? #=> false
129
+ #
130
+ def error?
131
+ @grpc.error?
132
+ end
133
+
134
+ ##
135
+ # Reloads the job with current data from the long-running,
136
+ # asynchronous processing of an instance operation.
137
+ #
138
+ # @return [Google::Cloud::Spanner::Instance::Job] The same job
139
+ # instance.
140
+ #
141
+ # @example
142
+ # require "google/cloud/spanner"
143
+ #
144
+ # spanner = Google::Cloud::Spanner.new
145
+ #
146
+ # job = spanner.create_instance "my-new-instance",
147
+ # name: "My New Instance",
148
+ # config: "regional-us-central1",
149
+ # nodes: 5,
150
+ # labels: { production: :env }
151
+ #
152
+ # job.done? #=> false
153
+ # job.reload! # API call
154
+ # job.done? #=> true
155
+ #
156
+ def reload!
157
+ @grpc.reload!
158
+ self
159
+ end
160
+ alias_method :refresh!, :reload!
161
+
162
+ ##
163
+ # Reloads the job until the operation is complete. The delay between
164
+ # reloads will incrementally increase.
165
+ #
166
+ # @example
167
+ # require "google/cloud/spanner"
168
+ #
169
+ # spanner = Google::Cloud::Spanner.new
170
+ #
171
+ # job = spanner.create_instance "my-new-instance",
172
+ # name: "My New Instance",
173
+ # config: "regional-us-central1",
174
+ # nodes: 5,
175
+ # labels: { production: :env }
176
+ #
177
+ # job.done? #=> false
178
+ # job.wait_until_done!
179
+ # job.done? #=> true
180
+ #
181
+ def wait_until_done!
182
+ @grpc.wait_until_done!
183
+ end
184
+
185
+ ##
186
+ # @private New Instance::Job from a Google::Gax::Operation object.
187
+ def self.from_grpc grpc, service
188
+ new.tap do |job|
189
+ job.instance_variable_set :@grpc, grpc
190
+ job.instance_variable_set :@service, service
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end