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.
- checksums.yaml +7 -0
- data/lib/google-cloud-spanner.rb +106 -0
- data/lib/google/cloud/spanner.rb +382 -0
- data/lib/google/cloud/spanner/admin/database/v1.rb +17 -0
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +703 -0
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +73 -0
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/policy.rb +139 -0
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/any.rb +114 -0
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/rpc/status.rb +83 -0
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +188 -0
- data/lib/google/cloud/spanner/admin/instance/v1.rb +17 -0
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/policy.rb +139 -0
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/any.rb +114 -0
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/field_mask.rb +223 -0
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/rpc/status.rb +83 -0
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +268 -0
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +868 -0
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +78 -0
- data/lib/google/cloud/spanner/client.rb +1034 -0
- data/lib/google/cloud/spanner/commit.rb +351 -0
- data/lib/google/cloud/spanner/convert.rb +311 -0
- data/lib/google/cloud/spanner/credentials.rb +32 -0
- data/lib/google/cloud/spanner/data.rb +199 -0
- data/lib/google/cloud/spanner/database.rb +377 -0
- data/lib/google/cloud/spanner/database/job.rb +179 -0
- data/lib/google/cloud/spanner/database/list.rb +171 -0
- data/lib/google/cloud/spanner/errors.rb +73 -0
- data/lib/google/cloud/spanner/fields.rb +252 -0
- data/lib/google/cloud/spanner/instance.rb +472 -0
- data/lib/google/cloud/spanner/instance/config.rb +99 -0
- data/lib/google/cloud/spanner/instance/config/list.rb +171 -0
- data/lib/google/cloud/spanner/instance/job.rb +197 -0
- data/lib/google/cloud/spanner/instance/list.rb +167 -0
- data/lib/google/cloud/spanner/policy.rb +201 -0
- data/lib/google/cloud/spanner/pool.rb +279 -0
- data/lib/google/cloud/spanner/project.rb +480 -0
- data/lib/google/cloud/spanner/range.rb +99 -0
- data/lib/google/cloud/spanner/results.rb +280 -0
- data/lib/google/cloud/spanner/service.rb +458 -0
- data/lib/google/cloud/spanner/session.rb +565 -0
- data/lib/google/cloud/spanner/snapshot.rb +260 -0
- data/lib/google/cloud/spanner/transaction.rb +533 -0
- data/lib/google/cloud/spanner/v1.rb +17 -0
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/duration.rb +77 -0
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/struct.rb +73 -0
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/timestamp.rb +81 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/keys.rb +148 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +80 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/query_plan.rb +120 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/result_set.rb +175 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +206 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/transaction.rb +351 -0
- data/lib/google/cloud/spanner/v1/spanner_client.rb +850 -0
- data/lib/google/cloud/spanner/v1/spanner_client_config.json +78 -0
- data/lib/google/cloud/spanner/version.rb +22 -0
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +85 -0
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +95 -0
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_pb.rb +106 -0
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +180 -0
- data/lib/google/spanner/v1/keys_pb.rb +33 -0
- data/lib/google/spanner/v1/mutation_pb.rb +38 -0
- data/lib/google/spanner/v1/query_plan_pb.rb +47 -0
- data/lib/google/spanner/v1/result_set_pb.rb +43 -0
- data/lib/google/spanner/v1/spanner_pb.rb +90 -0
- data/lib/google/spanner/v1/spanner_services_pb.rb +131 -0
- data/lib/google/spanner/v1/transaction_pb.rb +51 -0
- data/lib/google/spanner/v1/type_pb.rb +43 -0
- metadata +309 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
# Copyright 2016 Google Inc. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
require "google/cloud/spanner/admin/database/v1/database_admin_client"
|
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
# Copyright 2017, 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
|
+
# EDITING INSTRUCTIONS
|
|
16
|
+
# This file was generated from the file
|
|
17
|
+
# https://github.com/googleapis/googleapis/blob/master/google/spanner/admin/database/v1/spanner_database_admin.proto,
|
|
18
|
+
# and updates to that file get reflected here through a refresh process.
|
|
19
|
+
# For the short term, the refresh process will only be runnable by Google
|
|
20
|
+
# engineers.
|
|
21
|
+
#
|
|
22
|
+
# The only allowed edits are to method and file documentation. A 3-way
|
|
23
|
+
# merge preserves those additions if the generated source changes.
|
|
24
|
+
|
|
25
|
+
require "json"
|
|
26
|
+
require "pathname"
|
|
27
|
+
|
|
28
|
+
require "google/gax"
|
|
29
|
+
require "google/gax/operation"
|
|
30
|
+
require "google/longrunning/operations_client"
|
|
31
|
+
|
|
32
|
+
require "google/spanner/admin/database/v1/spanner_database_admin_pb"
|
|
33
|
+
|
|
34
|
+
module Google
|
|
35
|
+
module Cloud
|
|
36
|
+
module Spanner
|
|
37
|
+
module Admin
|
|
38
|
+
module Database
|
|
39
|
+
module V1
|
|
40
|
+
# Cloud Spanner Database Admin API
|
|
41
|
+
#
|
|
42
|
+
# The Cloud Spanner Database Admin API can be used to create, drop, and
|
|
43
|
+
# list databases. It also enables updating the schema of pre-existing
|
|
44
|
+
# databases.
|
|
45
|
+
#
|
|
46
|
+
# @!attribute [r] database_admin_stub
|
|
47
|
+
# @return [Google::Spanner::Admin::Database::V1::DatabaseAdmin::Stub]
|
|
48
|
+
class DatabaseAdminClient
|
|
49
|
+
attr_reader :database_admin_stub
|
|
50
|
+
|
|
51
|
+
# The default address of the service.
|
|
52
|
+
SERVICE_ADDRESS = "spanner.googleapis.com".freeze
|
|
53
|
+
|
|
54
|
+
# The default port of the service.
|
|
55
|
+
DEFAULT_SERVICE_PORT = 443
|
|
56
|
+
|
|
57
|
+
DEFAULT_TIMEOUT = 30
|
|
58
|
+
|
|
59
|
+
PAGE_DESCRIPTORS = {
|
|
60
|
+
"list_databases" => Google::Gax::PageDescriptor.new(
|
|
61
|
+
"page_token",
|
|
62
|
+
"next_page_token",
|
|
63
|
+
"databases")
|
|
64
|
+
}.freeze
|
|
65
|
+
|
|
66
|
+
private_constant :PAGE_DESCRIPTORS
|
|
67
|
+
|
|
68
|
+
# The scopes needed to make gRPC calls to all of the methods defined in
|
|
69
|
+
# this service.
|
|
70
|
+
ALL_SCOPES = [
|
|
71
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
|
72
|
+
"https://www.googleapis.com/auth/spanner.admin"
|
|
73
|
+
].freeze
|
|
74
|
+
|
|
75
|
+
INSTANCE_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
|
76
|
+
"projects/{project}/instances/{instance}"
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
private_constant :INSTANCE_PATH_TEMPLATE
|
|
80
|
+
|
|
81
|
+
DATABASE_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
|
82
|
+
"projects/{project}/instances/{instance}/databases/{database}"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
private_constant :DATABASE_PATH_TEMPLATE
|
|
86
|
+
|
|
87
|
+
# Returns a fully-qualified instance resource name string.
|
|
88
|
+
# @param project [String]
|
|
89
|
+
# @param instance [String]
|
|
90
|
+
# @return [String]
|
|
91
|
+
def self.instance_path project, instance
|
|
92
|
+
INSTANCE_PATH_TEMPLATE.render(
|
|
93
|
+
:"project" => project,
|
|
94
|
+
:"instance" => instance
|
|
95
|
+
)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Returns a fully-qualified database resource name string.
|
|
99
|
+
# @param project [String]
|
|
100
|
+
# @param instance [String]
|
|
101
|
+
# @param database [String]
|
|
102
|
+
# @return [String]
|
|
103
|
+
def self.database_path project, instance, database
|
|
104
|
+
DATABASE_PATH_TEMPLATE.render(
|
|
105
|
+
:"project" => project,
|
|
106
|
+
:"instance" => instance,
|
|
107
|
+
:"database" => database
|
|
108
|
+
)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Parses the project from a instance resource.
|
|
112
|
+
# @param instance_name [String]
|
|
113
|
+
# @return [String]
|
|
114
|
+
def self.match_project_from_instance_name instance_name
|
|
115
|
+
INSTANCE_PATH_TEMPLATE.match(instance_name)["project"]
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Parses the instance from a instance resource.
|
|
119
|
+
# @param instance_name [String]
|
|
120
|
+
# @return [String]
|
|
121
|
+
def self.match_instance_from_instance_name instance_name
|
|
122
|
+
INSTANCE_PATH_TEMPLATE.match(instance_name)["instance"]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Parses the project from a database resource.
|
|
126
|
+
# @param database_name [String]
|
|
127
|
+
# @return [String]
|
|
128
|
+
def self.match_project_from_database_name database_name
|
|
129
|
+
DATABASE_PATH_TEMPLATE.match(database_name)["project"]
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Parses the instance from a database resource.
|
|
133
|
+
# @param database_name [String]
|
|
134
|
+
# @return [String]
|
|
135
|
+
def self.match_instance_from_database_name database_name
|
|
136
|
+
DATABASE_PATH_TEMPLATE.match(database_name)["instance"]
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Parses the database from a database resource.
|
|
140
|
+
# @param database_name [String]
|
|
141
|
+
# @return [String]
|
|
142
|
+
def self.match_database_from_database_name database_name
|
|
143
|
+
DATABASE_PATH_TEMPLATE.match(database_name)["database"]
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# @param service_path [String]
|
|
147
|
+
# The domain name of the API remote host.
|
|
148
|
+
# @param port [Integer]
|
|
149
|
+
# The port on which to connect to the remote host.
|
|
150
|
+
# @param channel [Channel]
|
|
151
|
+
# A Channel object through which to make calls.
|
|
152
|
+
# @param chan_creds [Grpc::ChannelCredentials]
|
|
153
|
+
# A ChannelCredentials for the setting up the RPC client.
|
|
154
|
+
# @param client_config[Hash]
|
|
155
|
+
# A Hash for call options for each method. See
|
|
156
|
+
# Google::Gax#construct_settings for the structure of
|
|
157
|
+
# this data. Falls back to the default config if not specified
|
|
158
|
+
# or the specified config is missing data points.
|
|
159
|
+
# @param timeout [Numeric]
|
|
160
|
+
# The default timeout, in seconds, for calls made through this client.
|
|
161
|
+
def initialize \
|
|
162
|
+
service_path: SERVICE_ADDRESS,
|
|
163
|
+
port: DEFAULT_SERVICE_PORT,
|
|
164
|
+
channel: nil,
|
|
165
|
+
chan_creds: nil,
|
|
166
|
+
scopes: ALL_SCOPES,
|
|
167
|
+
client_config: {},
|
|
168
|
+
timeout: DEFAULT_TIMEOUT,
|
|
169
|
+
app_name: nil,
|
|
170
|
+
app_version: nil,
|
|
171
|
+
lib_name: nil,
|
|
172
|
+
lib_version: ""
|
|
173
|
+
# These require statements are intentionally placed here to initialize
|
|
174
|
+
# the gRPC module only when it's required.
|
|
175
|
+
# See https://github.com/googleapis/toolkit/issues/446
|
|
176
|
+
require "google/gax/grpc"
|
|
177
|
+
require "google/spanner/admin/database/v1/spanner_database_admin_services_pb"
|
|
178
|
+
|
|
179
|
+
@operations_client = Google::Longrunning::OperationsClient.new(
|
|
180
|
+
service_path: service_path,
|
|
181
|
+
port: port,
|
|
182
|
+
channel: channel,
|
|
183
|
+
chan_creds: chan_creds,
|
|
184
|
+
scopes: scopes,
|
|
185
|
+
client_config: client_config,
|
|
186
|
+
timeout: timeout,
|
|
187
|
+
app_name: app_name,
|
|
188
|
+
app_version: app_version,
|
|
189
|
+
lib_name: lib_name,
|
|
190
|
+
lib_version: lib_version,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
if app_name || app_version
|
|
194
|
+
warn "`app_name` and `app_version` are no longer being used in the request headers."
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
google_api_client = "gl-ruby/#{RUBY_VERSION}"
|
|
198
|
+
google_api_client << " #{lib_name}/#{lib_version}" if lib_name
|
|
199
|
+
google_api_client << " gapic/0.6.8 gax/#{Google::Gax::VERSION}"
|
|
200
|
+
google_api_client << " grpc/#{GRPC::VERSION}"
|
|
201
|
+
google_api_client.freeze
|
|
202
|
+
|
|
203
|
+
headers = { :"x-goog-api-client" => google_api_client }
|
|
204
|
+
client_config_file = Pathname.new(__dir__).join(
|
|
205
|
+
"database_admin_client_config.json"
|
|
206
|
+
)
|
|
207
|
+
defaults = client_config_file.open do |f|
|
|
208
|
+
Google::Gax.construct_settings(
|
|
209
|
+
"google.spanner.admin.database.v1.DatabaseAdmin",
|
|
210
|
+
JSON.parse(f.read),
|
|
211
|
+
client_config,
|
|
212
|
+
Google::Gax::Grpc::STATUS_CODE_NAMES,
|
|
213
|
+
timeout,
|
|
214
|
+
page_descriptors: PAGE_DESCRIPTORS,
|
|
215
|
+
errors: Google::Gax::Grpc::API_ERRORS,
|
|
216
|
+
kwargs: headers
|
|
217
|
+
)
|
|
218
|
+
end
|
|
219
|
+
@database_admin_stub = Google::Gax::Grpc.create_stub(
|
|
220
|
+
service_path,
|
|
221
|
+
port,
|
|
222
|
+
chan_creds: chan_creds,
|
|
223
|
+
channel: channel,
|
|
224
|
+
scopes: scopes,
|
|
225
|
+
&Google::Spanner::Admin::Database::V1::DatabaseAdmin::Stub.method(:new)
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
@list_databases = Google::Gax.create_api_call(
|
|
229
|
+
@database_admin_stub.method(:list_databases),
|
|
230
|
+
defaults["list_databases"]
|
|
231
|
+
)
|
|
232
|
+
@create_database = Google::Gax.create_api_call(
|
|
233
|
+
@database_admin_stub.method(:create_database),
|
|
234
|
+
defaults["create_database"]
|
|
235
|
+
)
|
|
236
|
+
@get_database = Google::Gax.create_api_call(
|
|
237
|
+
@database_admin_stub.method(:get_database),
|
|
238
|
+
defaults["get_database"]
|
|
239
|
+
)
|
|
240
|
+
@update_database_ddl = Google::Gax.create_api_call(
|
|
241
|
+
@database_admin_stub.method(:update_database_ddl),
|
|
242
|
+
defaults["update_database_ddl"]
|
|
243
|
+
)
|
|
244
|
+
@drop_database = Google::Gax.create_api_call(
|
|
245
|
+
@database_admin_stub.method(:drop_database),
|
|
246
|
+
defaults["drop_database"]
|
|
247
|
+
)
|
|
248
|
+
@get_database_ddl = Google::Gax.create_api_call(
|
|
249
|
+
@database_admin_stub.method(:get_database_ddl),
|
|
250
|
+
defaults["get_database_ddl"]
|
|
251
|
+
)
|
|
252
|
+
@set_iam_policy = Google::Gax.create_api_call(
|
|
253
|
+
@database_admin_stub.method(:set_iam_policy),
|
|
254
|
+
defaults["set_iam_policy"]
|
|
255
|
+
)
|
|
256
|
+
@get_iam_policy = Google::Gax.create_api_call(
|
|
257
|
+
@database_admin_stub.method(:get_iam_policy),
|
|
258
|
+
defaults["get_iam_policy"]
|
|
259
|
+
)
|
|
260
|
+
@test_iam_permissions = Google::Gax.create_api_call(
|
|
261
|
+
@database_admin_stub.method(:test_iam_permissions),
|
|
262
|
+
defaults["test_iam_permissions"]
|
|
263
|
+
)
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
# Service calls
|
|
267
|
+
|
|
268
|
+
# Lists Cloud Spanner databases.
|
|
269
|
+
#
|
|
270
|
+
# @param parent [String]
|
|
271
|
+
# Required. The instance whose databases should be listed.
|
|
272
|
+
# Values are of the form +projects/<project>/instances/<instance>+.
|
|
273
|
+
# @param page_size [Integer]
|
|
274
|
+
# The maximum number of resources contained in the underlying API
|
|
275
|
+
# response. If page streaming is performed per-resource, this
|
|
276
|
+
# parameter does not affect the return value. If page streaming is
|
|
277
|
+
# performed per-page, this determines the maximum number of
|
|
278
|
+
# resources in a page.
|
|
279
|
+
# @param options [Google::Gax::CallOptions]
|
|
280
|
+
# Overrides the default settings for this call, e.g, timeout,
|
|
281
|
+
# retries, etc.
|
|
282
|
+
# @return [Google::Gax::PagedEnumerable<Google::Spanner::Admin::Database::V1::Database>]
|
|
283
|
+
# An enumerable of Google::Spanner::Admin::Database::V1::Database instances.
|
|
284
|
+
# See Google::Gax::PagedEnumerable documentation for other
|
|
285
|
+
# operations such as per-page iteration or access to the response
|
|
286
|
+
# object.
|
|
287
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
|
288
|
+
# @example
|
|
289
|
+
# require "google/cloud/spanner/admin/database/v1/database_admin_client"
|
|
290
|
+
#
|
|
291
|
+
# DatabaseAdminClient = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient
|
|
292
|
+
#
|
|
293
|
+
# database_admin_client = DatabaseAdminClient.new
|
|
294
|
+
# formatted_parent = DatabaseAdminClient.instance_path("[PROJECT]", "[INSTANCE]")
|
|
295
|
+
#
|
|
296
|
+
# # Iterate over all results.
|
|
297
|
+
# database_admin_client.list_databases(formatted_parent).each do |element|
|
|
298
|
+
# # Process element.
|
|
299
|
+
# end
|
|
300
|
+
#
|
|
301
|
+
# # Or iterate over results one page at a time.
|
|
302
|
+
# database_admin_client.list_databases(formatted_parent).each_page do |page|
|
|
303
|
+
# # Process each page at a time.
|
|
304
|
+
# page.each do |element|
|
|
305
|
+
# # Process element.
|
|
306
|
+
# end
|
|
307
|
+
# end
|
|
308
|
+
|
|
309
|
+
def list_databases \
|
|
310
|
+
parent,
|
|
311
|
+
page_size: nil,
|
|
312
|
+
options: nil
|
|
313
|
+
req = Google::Spanner::Admin::Database::V1::ListDatabasesRequest.new({
|
|
314
|
+
parent: parent,
|
|
315
|
+
page_size: page_size
|
|
316
|
+
}.delete_if { |_, v| v.nil? })
|
|
317
|
+
@list_databases.call(req, options)
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
# Creates a new Cloud Spanner database and starts to prepare it for serving.
|
|
321
|
+
# The returned Long-running operation will
|
|
322
|
+
# have a name of the format +<database_name>/operations/<operation_id>+ and
|
|
323
|
+
# can be used to track preparation of the database. The
|
|
324
|
+
# Metadata field type is
|
|
325
|
+
# CreateDatabaseMetadata. The
|
|
326
|
+
# Response field type is
|
|
327
|
+
# Database, if successful.
|
|
328
|
+
#
|
|
329
|
+
# @param parent [String]
|
|
330
|
+
# Required. The name of the instance that will serve the new database.
|
|
331
|
+
# Values are of the form +projects/<project>/instances/<instance>+.
|
|
332
|
+
# @param create_statement [String]
|
|
333
|
+
# Required. A +CREATE DATABASE+ statement, which specifies the ID of the
|
|
334
|
+
# new database. The database ID must conform to the regular expression
|
|
335
|
+
# +[a-z][a-z0-9_\-]*[a-z0-9]+ and be between 2 and 30 characters in length.
|
|
336
|
+
# @param extra_statements [Array<String>]
|
|
337
|
+
# An optional list of DDL statements to run inside the newly created
|
|
338
|
+
# database. Statements can create tables, indexes, etc. These
|
|
339
|
+
# statements execute atomically with the creation of the database:
|
|
340
|
+
# if there is an error in any statement, the database is not created.
|
|
341
|
+
# @param options [Google::Gax::CallOptions]
|
|
342
|
+
# Overrides the default settings for this call, e.g, timeout,
|
|
343
|
+
# retries, etc.
|
|
344
|
+
# @return [Google::Gax::Operation]
|
|
345
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
|
346
|
+
# @example
|
|
347
|
+
# require "google/cloud/spanner/admin/database/v1/database_admin_client"
|
|
348
|
+
#
|
|
349
|
+
# DatabaseAdminClient = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient
|
|
350
|
+
#
|
|
351
|
+
# database_admin_client = DatabaseAdminClient.new
|
|
352
|
+
# formatted_parent = DatabaseAdminClient.instance_path("[PROJECT]", "[INSTANCE]")
|
|
353
|
+
# create_statement = ''
|
|
354
|
+
#
|
|
355
|
+
# # Register a callback during the method call.
|
|
356
|
+
# operation = database_admin_client.create_database(formatted_parent, create_statement) do |op|
|
|
357
|
+
# raise op.results.message if op.error?
|
|
358
|
+
# op_results = op.results
|
|
359
|
+
# # Process the results.
|
|
360
|
+
#
|
|
361
|
+
# metadata = op.metadata
|
|
362
|
+
# # Process the metadata.
|
|
363
|
+
# end
|
|
364
|
+
#
|
|
365
|
+
# # Or use the return value to register a callback.
|
|
366
|
+
# operation.on_done do |op|
|
|
367
|
+
# raise op.results.message if op.error?
|
|
368
|
+
# op_results = op.results
|
|
369
|
+
# # Process the results.
|
|
370
|
+
#
|
|
371
|
+
# metadata = op.metadata
|
|
372
|
+
# # Process the metadata.
|
|
373
|
+
# end
|
|
374
|
+
#
|
|
375
|
+
# # Manually reload the operation.
|
|
376
|
+
# operation.reload!
|
|
377
|
+
#
|
|
378
|
+
# # Or block until the operation completes, triggering callbacks on
|
|
379
|
+
# # completion.
|
|
380
|
+
# operation.wait_until_done!
|
|
381
|
+
|
|
382
|
+
def create_database \
|
|
383
|
+
parent,
|
|
384
|
+
create_statement,
|
|
385
|
+
extra_statements: nil,
|
|
386
|
+
options: nil
|
|
387
|
+
req = Google::Spanner::Admin::Database::V1::CreateDatabaseRequest.new({
|
|
388
|
+
parent: parent,
|
|
389
|
+
create_statement: create_statement,
|
|
390
|
+
extra_statements: extra_statements
|
|
391
|
+
}.delete_if { |_, v| v.nil? })
|
|
392
|
+
operation = Google::Gax::Operation.new(
|
|
393
|
+
@create_database.call(req, options),
|
|
394
|
+
@operations_client,
|
|
395
|
+
Google::Spanner::Admin::Database::V1::Database,
|
|
396
|
+
Google::Spanner::Admin::Database::V1::CreateDatabaseMetadata,
|
|
397
|
+
call_options: options
|
|
398
|
+
)
|
|
399
|
+
operation.on_done { |operation| yield(operation) } if block_given?
|
|
400
|
+
operation
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
# Gets the state of a Cloud Spanner database.
|
|
404
|
+
#
|
|
405
|
+
# @param name [String]
|
|
406
|
+
# Required. The name of the requested database. Values are of the form
|
|
407
|
+
# +projects/<project>/instances/<instance>/databases/<database>+.
|
|
408
|
+
# @param options [Google::Gax::CallOptions]
|
|
409
|
+
# Overrides the default settings for this call, e.g, timeout,
|
|
410
|
+
# retries, etc.
|
|
411
|
+
# @return [Google::Spanner::Admin::Database::V1::Database]
|
|
412
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
|
413
|
+
# @example
|
|
414
|
+
# require "google/cloud/spanner/admin/database/v1/database_admin_client"
|
|
415
|
+
#
|
|
416
|
+
# DatabaseAdminClient = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient
|
|
417
|
+
#
|
|
418
|
+
# database_admin_client = DatabaseAdminClient.new
|
|
419
|
+
# formatted_name = DatabaseAdminClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
|
420
|
+
# response = database_admin_client.get_database(formatted_name)
|
|
421
|
+
|
|
422
|
+
def get_database \
|
|
423
|
+
name,
|
|
424
|
+
options: nil
|
|
425
|
+
req = Google::Spanner::Admin::Database::V1::GetDatabaseRequest.new({
|
|
426
|
+
name: name
|
|
427
|
+
}.delete_if { |_, v| v.nil? })
|
|
428
|
+
@get_database.call(req, options)
|
|
429
|
+
end
|
|
430
|
+
|
|
431
|
+
# Updates the schema of a Cloud Spanner database by
|
|
432
|
+
# creating/altering/dropping tables, columns, indexes, etc. The returned
|
|
433
|
+
# Long-running operation will have a name of
|
|
434
|
+
# the format +<database_name>/operations/<operation_id>+ and can be used to
|
|
435
|
+
# track execution of the schema change(s). The
|
|
436
|
+
# Metadata field type is
|
|
437
|
+
# UpdateDatabaseDdlMetadata. The operation has no response.
|
|
438
|
+
#
|
|
439
|
+
# @param database [String]
|
|
440
|
+
# Required. The database to update.
|
|
441
|
+
# @param statements [Array<String>]
|
|
442
|
+
# DDL statements to be applied to the database.
|
|
443
|
+
# @param operation_id [String]
|
|
444
|
+
# If empty, the new update request is assigned an
|
|
445
|
+
# automatically-generated operation ID. Otherwise, +operation_id+
|
|
446
|
+
# is used to construct the name of the resulting
|
|
447
|
+
# Operation.
|
|
448
|
+
#
|
|
449
|
+
# Specifying an explicit operation ID simplifies determining
|
|
450
|
+
# whether the statements were executed in the event that the
|
|
451
|
+
# UpdateDatabaseDdl call is replayed,
|
|
452
|
+
# or the return value is otherwise lost: the Database and
|
|
453
|
+
# +operation_id+ fields can be combined to form the
|
|
454
|
+
# Name of the resulting
|
|
455
|
+
# Longrunning::Operation: +<database>/operations/<operation_id>+.
|
|
456
|
+
#
|
|
457
|
+
# +operation_id+ should be unique within the database, and must be
|
|
458
|
+
# a valid identifier: +[a-z][a-z0-9_]*+. Note that
|
|
459
|
+
# automatically-generated operation IDs always begin with an
|
|
460
|
+
# underscore. If the named operation already exists,
|
|
461
|
+
# UpdateDatabaseDdl returns
|
|
462
|
+
# +ALREADY_EXISTS+.
|
|
463
|
+
# @param options [Google::Gax::CallOptions]
|
|
464
|
+
# Overrides the default settings for this call, e.g, timeout,
|
|
465
|
+
# retries, etc.
|
|
466
|
+
# @return [Google::Gax::Operation]
|
|
467
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
|
468
|
+
# @example
|
|
469
|
+
# require "google/cloud/spanner/admin/database/v1/database_admin_client"
|
|
470
|
+
#
|
|
471
|
+
# DatabaseAdminClient = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient
|
|
472
|
+
#
|
|
473
|
+
# database_admin_client = DatabaseAdminClient.new
|
|
474
|
+
# formatted_database = DatabaseAdminClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
|
475
|
+
# statements = []
|
|
476
|
+
#
|
|
477
|
+
# # Register a callback during the method call.
|
|
478
|
+
# operation = database_admin_client.update_database_ddl(formatted_database, statements) do |op|
|
|
479
|
+
# raise op.results.message if op.error?
|
|
480
|
+
# op_results = op.results
|
|
481
|
+
# # Process the results.
|
|
482
|
+
#
|
|
483
|
+
# metadata = op.metadata
|
|
484
|
+
# # Process the metadata.
|
|
485
|
+
# end
|
|
486
|
+
#
|
|
487
|
+
# # Or use the return value to register a callback.
|
|
488
|
+
# operation.on_done do |op|
|
|
489
|
+
# raise op.results.message if op.error?
|
|
490
|
+
# op_results = op.results
|
|
491
|
+
# # Process the results.
|
|
492
|
+
#
|
|
493
|
+
# metadata = op.metadata
|
|
494
|
+
# # Process the metadata.
|
|
495
|
+
# end
|
|
496
|
+
#
|
|
497
|
+
# # Manually reload the operation.
|
|
498
|
+
# operation.reload!
|
|
499
|
+
#
|
|
500
|
+
# # Or block until the operation completes, triggering callbacks on
|
|
501
|
+
# # completion.
|
|
502
|
+
# operation.wait_until_done!
|
|
503
|
+
|
|
504
|
+
def update_database_ddl \
|
|
505
|
+
database,
|
|
506
|
+
statements,
|
|
507
|
+
operation_id: nil,
|
|
508
|
+
options: nil
|
|
509
|
+
req = Google::Spanner::Admin::Database::V1::UpdateDatabaseDdlRequest.new({
|
|
510
|
+
database: database,
|
|
511
|
+
statements: statements,
|
|
512
|
+
operation_id: operation_id
|
|
513
|
+
}.delete_if { |_, v| v.nil? })
|
|
514
|
+
operation = Google::Gax::Operation.new(
|
|
515
|
+
@update_database_ddl.call(req, options),
|
|
516
|
+
@operations_client,
|
|
517
|
+
Google::Protobuf::Empty,
|
|
518
|
+
Google::Spanner::Admin::Database::V1::UpdateDatabaseDdlMetadata,
|
|
519
|
+
call_options: options
|
|
520
|
+
)
|
|
521
|
+
operation.on_done { |operation| yield(operation) } if block_given?
|
|
522
|
+
operation
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
# Drops (aka deletes) a Cloud Spanner database.
|
|
526
|
+
#
|
|
527
|
+
# @param database [String]
|
|
528
|
+
# Required. The database to be dropped.
|
|
529
|
+
# @param options [Google::Gax::CallOptions]
|
|
530
|
+
# Overrides the default settings for this call, e.g, timeout,
|
|
531
|
+
# retries, etc.
|
|
532
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
|
533
|
+
# @example
|
|
534
|
+
# require "google/cloud/spanner/admin/database/v1/database_admin_client"
|
|
535
|
+
#
|
|
536
|
+
# DatabaseAdminClient = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient
|
|
537
|
+
#
|
|
538
|
+
# database_admin_client = DatabaseAdminClient.new
|
|
539
|
+
# formatted_database = DatabaseAdminClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
|
540
|
+
# database_admin_client.drop_database(formatted_database)
|
|
541
|
+
|
|
542
|
+
def drop_database \
|
|
543
|
+
database,
|
|
544
|
+
options: nil
|
|
545
|
+
req = Google::Spanner::Admin::Database::V1::DropDatabaseRequest.new({
|
|
546
|
+
database: database
|
|
547
|
+
}.delete_if { |_, v| v.nil? })
|
|
548
|
+
@drop_database.call(req, options)
|
|
549
|
+
nil
|
|
550
|
+
end
|
|
551
|
+
|
|
552
|
+
# Returns the schema of a Cloud Spanner database as a list of formatted
|
|
553
|
+
# DDL statements. This method does not show pending schema updates, those may
|
|
554
|
+
# be queried using the Operations API.
|
|
555
|
+
#
|
|
556
|
+
# @param database [String]
|
|
557
|
+
# Required. The database whose schema we wish to get.
|
|
558
|
+
# @param options [Google::Gax::CallOptions]
|
|
559
|
+
# Overrides the default settings for this call, e.g, timeout,
|
|
560
|
+
# retries, etc.
|
|
561
|
+
# @return [Google::Spanner::Admin::Database::V1::GetDatabaseDdlResponse]
|
|
562
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
|
563
|
+
# @example
|
|
564
|
+
# require "google/cloud/spanner/admin/database/v1/database_admin_client"
|
|
565
|
+
#
|
|
566
|
+
# DatabaseAdminClient = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient
|
|
567
|
+
#
|
|
568
|
+
# database_admin_client = DatabaseAdminClient.new
|
|
569
|
+
# formatted_database = DatabaseAdminClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
|
570
|
+
# response = database_admin_client.get_database_ddl(formatted_database)
|
|
571
|
+
|
|
572
|
+
def get_database_ddl \
|
|
573
|
+
database,
|
|
574
|
+
options: nil
|
|
575
|
+
req = Google::Spanner::Admin::Database::V1::GetDatabaseDdlRequest.new({
|
|
576
|
+
database: database
|
|
577
|
+
}.delete_if { |_, v| v.nil? })
|
|
578
|
+
@get_database_ddl.call(req, options)
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
# Sets the access control policy on a database resource. Replaces any
|
|
582
|
+
# existing policy.
|
|
583
|
+
#
|
|
584
|
+
# Authorization requires +spanner.databases.setIamPolicy+ permission on
|
|
585
|
+
# Resource.
|
|
586
|
+
#
|
|
587
|
+
# @param resource [String]
|
|
588
|
+
# REQUIRED: The resource for which the policy is being specified.
|
|
589
|
+
# +resource+ is usually specified as a path. For example, a Project
|
|
590
|
+
# resource is specified as +projects/{project}+.
|
|
591
|
+
# @param policy [Google::Iam::V1::Policy]
|
|
592
|
+
# REQUIRED: The complete policy to be applied to the +resource+. The size of
|
|
593
|
+
# the policy is limited to a few 10s of KB. An empty policy is a
|
|
594
|
+
# valid policy but certain Cloud Platform services (such as Projects)
|
|
595
|
+
# might reject them.
|
|
596
|
+
# @param options [Google::Gax::CallOptions]
|
|
597
|
+
# Overrides the default settings for this call, e.g, timeout,
|
|
598
|
+
# retries, etc.
|
|
599
|
+
# @return [Google::Iam::V1::Policy]
|
|
600
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
|
601
|
+
# @example
|
|
602
|
+
# require "google/cloud/spanner/admin/database/v1/database_admin_client"
|
|
603
|
+
#
|
|
604
|
+
# DatabaseAdminClient = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient
|
|
605
|
+
# Policy = Google::Iam::V1::Policy
|
|
606
|
+
#
|
|
607
|
+
# database_admin_client = DatabaseAdminClient.new
|
|
608
|
+
# formatted_resource = DatabaseAdminClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
|
609
|
+
# policy = Policy.new
|
|
610
|
+
# response = database_admin_client.set_iam_policy(formatted_resource, policy)
|
|
611
|
+
|
|
612
|
+
def set_iam_policy \
|
|
613
|
+
resource,
|
|
614
|
+
policy,
|
|
615
|
+
options: nil
|
|
616
|
+
req = Google::Iam::V1::SetIamPolicyRequest.new({
|
|
617
|
+
resource: resource,
|
|
618
|
+
policy: policy
|
|
619
|
+
}.delete_if { |_, v| v.nil? })
|
|
620
|
+
@set_iam_policy.call(req, options)
|
|
621
|
+
end
|
|
622
|
+
|
|
623
|
+
# Gets the access control policy for a database resource. Returns an empty
|
|
624
|
+
# policy if a database exists but does not have a policy set.
|
|
625
|
+
#
|
|
626
|
+
# Authorization requires +spanner.databases.getIamPolicy+ permission on
|
|
627
|
+
# Resource.
|
|
628
|
+
#
|
|
629
|
+
# @param resource [String]
|
|
630
|
+
# REQUIRED: The resource for which the policy is being requested.
|
|
631
|
+
# +resource+ is usually specified as a path. For example, a Project
|
|
632
|
+
# resource is specified as +projects/{project}+.
|
|
633
|
+
# @param options [Google::Gax::CallOptions]
|
|
634
|
+
# Overrides the default settings for this call, e.g, timeout,
|
|
635
|
+
# retries, etc.
|
|
636
|
+
# @return [Google::Iam::V1::Policy]
|
|
637
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
|
638
|
+
# @example
|
|
639
|
+
# require "google/cloud/spanner/admin/database/v1/database_admin_client"
|
|
640
|
+
#
|
|
641
|
+
# DatabaseAdminClient = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient
|
|
642
|
+
#
|
|
643
|
+
# database_admin_client = DatabaseAdminClient.new
|
|
644
|
+
# formatted_resource = DatabaseAdminClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
|
645
|
+
# response = database_admin_client.get_iam_policy(formatted_resource)
|
|
646
|
+
|
|
647
|
+
def get_iam_policy \
|
|
648
|
+
resource,
|
|
649
|
+
options: nil
|
|
650
|
+
req = Google::Iam::V1::GetIamPolicyRequest.new({
|
|
651
|
+
resource: resource
|
|
652
|
+
}.delete_if { |_, v| v.nil? })
|
|
653
|
+
@get_iam_policy.call(req, options)
|
|
654
|
+
end
|
|
655
|
+
|
|
656
|
+
# Returns permissions that the caller has on the specified database resource.
|
|
657
|
+
#
|
|
658
|
+
# Attempting this RPC on a non-existent Cloud Spanner database will result in
|
|
659
|
+
# a NOT_FOUND error if the user has +spanner.databases.list+ permission on
|
|
660
|
+
# the containing Cloud Spanner instance. Otherwise returns an empty set of
|
|
661
|
+
# permissions.
|
|
662
|
+
#
|
|
663
|
+
# @param resource [String]
|
|
664
|
+
# REQUIRED: The resource for which the policy detail is being requested.
|
|
665
|
+
# +resource+ is usually specified as a path. For example, a Project
|
|
666
|
+
# resource is specified as +projects/{project}+.
|
|
667
|
+
# @param permissions [Array<String>]
|
|
668
|
+
# The set of permissions to check for the +resource+. Permissions with
|
|
669
|
+
# wildcards (such as '*' or 'storage.*') are not allowed. For more
|
|
670
|
+
# information see
|
|
671
|
+
# {IAM Overview}[https://cloud.google.com/iam/docs/overview#permissions].
|
|
672
|
+
# @param options [Google::Gax::CallOptions]
|
|
673
|
+
# Overrides the default settings for this call, e.g, timeout,
|
|
674
|
+
# retries, etc.
|
|
675
|
+
# @return [Google::Iam::V1::TestIamPermissionsResponse]
|
|
676
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
|
677
|
+
# @example
|
|
678
|
+
# require "google/cloud/spanner/admin/database/v1/database_admin_client"
|
|
679
|
+
#
|
|
680
|
+
# DatabaseAdminClient = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient
|
|
681
|
+
#
|
|
682
|
+
# database_admin_client = DatabaseAdminClient.new
|
|
683
|
+
# formatted_resource = DatabaseAdminClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
|
684
|
+
# permissions = []
|
|
685
|
+
# response = database_admin_client.test_iam_permissions(formatted_resource, permissions)
|
|
686
|
+
|
|
687
|
+
def test_iam_permissions \
|
|
688
|
+
resource,
|
|
689
|
+
permissions,
|
|
690
|
+
options: nil
|
|
691
|
+
req = Google::Iam::V1::TestIamPermissionsRequest.new({
|
|
692
|
+
resource: resource,
|
|
693
|
+
permissions: permissions
|
|
694
|
+
}.delete_if { |_, v| v.nil? })
|
|
695
|
+
@test_iam_permissions.call(req, options)
|
|
696
|
+
end
|
|
697
|
+
end
|
|
698
|
+
end
|
|
699
|
+
end
|
|
700
|
+
end
|
|
701
|
+
end
|
|
702
|
+
end
|
|
703
|
+
end
|