google-cloud-spanner 1.16.2 → 2.4.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 +4 -4
- data/AUTHENTICATION.md +1 -1
- data/CHANGELOG.md +66 -0
- data/CONTRIBUTING.md +1 -1
- data/lib/google-cloud-spanner.rb +11 -13
- data/lib/google/cloud/spanner.rb +13 -13
- data/lib/google/cloud/spanner/admin/database/credentials.rb +2 -2
- data/lib/google/cloud/spanner/admin/instance/credentials.rb +2 -2
- data/lib/google/cloud/spanner/backup.rb +9 -1
- data/lib/google/cloud/spanner/backup/job.rb +2 -2
- data/lib/google/cloud/spanner/backup/job/list.rb +2 -2
- data/lib/google/cloud/spanner/backup/list.rb +1 -2
- data/lib/google/cloud/spanner/backup/restore/job.rb +2 -2
- data/lib/google/cloud/spanner/batch_client.rb +2 -2
- data/lib/google/cloud/spanner/batch_snapshot.rb +120 -23
- data/lib/google/cloud/spanner/batch_update.rb +1 -1
- data/lib/google/cloud/spanner/client.rb +388 -47
- data/lib/google/cloud/spanner/commit.rb +14 -14
- data/lib/google/cloud/spanner/commit_response.rb +87 -0
- data/lib/google/cloud/spanner/commit_response/commit_stats.rb +51 -0
- data/lib/google/cloud/spanner/convert.rb +16 -7
- data/lib/google/cloud/spanner/credentials.rb +2 -2
- data/lib/google/cloud/spanner/data.rb +2 -2
- data/lib/google/cloud/spanner/database.rb +47 -25
- data/lib/google/cloud/spanner/database/backup_info.rb +13 -4
- data/lib/google/cloud/spanner/database/job.rb +3 -3
- data/lib/google/cloud/spanner/database/job/list.rb +2 -2
- data/lib/google/cloud/spanner/database/list.rb +1 -1
- data/lib/google/cloud/spanner/database/restore_info.rb +1 -1
- data/lib/google/cloud/spanner/fields.rb +8 -8
- data/lib/google/cloud/spanner/instance.rb +5 -12
- data/lib/google/cloud/spanner/instance/config.rb +1 -1
- data/lib/google/cloud/spanner/instance/config/list.rb +1 -1
- data/lib/google/cloud/spanner/instance/job.rb +2 -2
- data/lib/google/cloud/spanner/instance/list.rb +1 -1
- data/lib/google/cloud/spanner/partition.rb +4 -4
- data/lib/google/cloud/spanner/policy.rb +2 -2
- data/lib/google/cloud/spanner/results.rb +103 -24
- data/lib/google/cloud/spanner/service.rb +369 -350
- data/lib/google/cloud/spanner/session.rb +370 -39
- data/lib/google/cloud/spanner/snapshot.rb +60 -6
- data/lib/google/cloud/spanner/transaction.rb +116 -10
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +20 -107
- data/lib/google/cloud/spanner/admin/database.rb +0 -149
- data/lib/google/cloud/spanner/admin/database/v1.rb +0 -147
- data/lib/google/cloud/spanner/admin/database/v1/credentials.rb +0 -46
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +0 -1513
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +0 -111
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/iam_policy.rb +0 -64
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/options.rb +0 -33
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/policy.rb +0 -151
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/longrunning/operations.rb +0 -51
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/backup.rb +0 -325
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +0 -368
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/type/expr.rb +0 -45
- data/lib/google/cloud/spanner/admin/instance.rb +0 -164
- data/lib/google/cloud/spanner/admin/instance/v1.rb +0 -162
- data/lib/google/cloud/spanner/admin/instance/v1/credentials.rb +0 -46
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/iam_policy.rb +0 -64
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/options.rb +0 -33
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/policy.rb +0 -151
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/longrunning/operations.rb +0 -51
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +0 -334
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/type/expr.rb +0 -45
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +0 -975
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +0 -76
- data/lib/google/cloud/spanner/v1.rb +0 -16
- data/lib/google/cloud/spanner/v1/credentials.rb +0 -42
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/duration.rb +0 -91
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/struct.rb +0 -74
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/spanner/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/keys.rb +0 -150
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +0 -95
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/query_plan.rb +0 -121
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/result_set.rb +0 -190
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +0 -570
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/transaction.rb +0 -432
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/type.rb +0 -112
- data/lib/google/cloud/spanner/v1/spanner_client.rb +0 -1485
- data/lib/google/cloud/spanner/v1/spanner_client_config.json +0 -121
- data/lib/google/spanner/admin/database/v1/backup_pb.rb +0 -98
- data/lib/google/spanner/admin/database/v1/common_pb.rb +0 -28
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +0 -141
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +0 -169
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_pb.rb +0 -125
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +0 -181
- data/lib/google/spanner/v1/keys_pb.rb +0 -34
- data/lib/google/spanner/v1/mutation_pb.rb +0 -39
- data/lib/google/spanner/v1/query_plan_pb.rb +0 -48
- data/lib/google/spanner/v1/result_set_pb.rb +0 -48
- data/lib/google/spanner/v1/spanner_pb.rb +0 -179
- data/lib/google/spanner/v1/spanner_services_pb.rb +0 -179
- data/lib/google/spanner/v1/transaction_pb.rb +0 -56
- data/lib/google/spanner/v1/type_pb.rb +0 -44
|
@@ -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, :
|
|
33
|
-
:
|
|
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,
|
|
38
|
-
|
|
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
|
|
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::
|
|
68
|
-
credentials
|
|
69
|
-
timeout
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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::
|
|
83
|
-
credentials
|
|
84
|
-
timeout
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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::
|
|
98
|
-
credentials
|
|
99
|
-
timeout
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
|
|
@@ -110,225 +105,239 @@ module Google
|
|
|
110
105
|
credentials == :this_channel_is_insecure
|
|
111
106
|
end
|
|
112
107
|
|
|
113
|
-
def list_instances token: nil, max: nil
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
paged_enum.page.response
|
|
123
|
-
end
|
|
108
|
+
def list_instances token: nil, max: nil, call_options: nil
|
|
109
|
+
opts = default_options call_options: call_options
|
|
110
|
+
request = {
|
|
111
|
+
parent: project_path,
|
|
112
|
+
page_size: max,
|
|
113
|
+
page_token: token
|
|
114
|
+
}
|
|
115
|
+
paged_enum = instances.list_instances request, opts
|
|
116
|
+
paged_enum.response
|
|
124
117
|
end
|
|
125
118
|
|
|
126
|
-
def get_instance name
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
def get_instance name, call_options: nil
|
|
120
|
+
opts = default_options call_options: call_options
|
|
121
|
+
request = { name: instance_path(name) }
|
|
122
|
+
instances.get_instance request, opts
|
|
130
123
|
end
|
|
131
124
|
|
|
132
125
|
def create_instance instance_id, name: nil, config: nil, nodes: nil,
|
|
133
|
-
labels: nil
|
|
126
|
+
labels: nil, call_options: nil
|
|
127
|
+
opts = default_options call_options: call_options
|
|
134
128
|
labels = Hash[labels.map { |k, v| [String(k), String(v)] }] if labels
|
|
135
129
|
|
|
136
|
-
create_obj =
|
|
130
|
+
create_obj = Admin::Instance::V1::Instance.new({
|
|
137
131
|
display_name: name, config: instance_config_path(config),
|
|
138
132
|
node_count: nodes, labels: labels
|
|
139
133
|
}.delete_if { |_, v| v.nil? })
|
|
140
134
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
135
|
+
request = {
|
|
136
|
+
parent: project_path,
|
|
137
|
+
instance_id: instance_id,
|
|
138
|
+
instance: create_obj
|
|
139
|
+
}
|
|
140
|
+
instances.create_instance request, opts
|
|
144
141
|
end
|
|
145
142
|
|
|
146
|
-
def update_instance
|
|
143
|
+
def update_instance instance, call_options: nil
|
|
144
|
+
opts = default_options call_options: call_options
|
|
147
145
|
mask = Google::Protobuf::FieldMask.new(
|
|
148
146
|
paths: %w[display_name node_count labels]
|
|
149
147
|
)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
instances.update_instance instance_obj, mask
|
|
153
|
-
end
|
|
148
|
+
request = { instance: instance, field_mask: mask }
|
|
149
|
+
instances.update_instance request, opts
|
|
154
150
|
end
|
|
155
151
|
|
|
156
|
-
def delete_instance name
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
152
|
+
def delete_instance name, call_options: nil
|
|
153
|
+
opts = default_options call_options: call_options
|
|
154
|
+
request = { name: instance_path(name) }
|
|
155
|
+
instances.delete_instance request, opts
|
|
160
156
|
end
|
|
161
157
|
|
|
162
|
-
def get_instance_policy name
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
158
|
+
def get_instance_policy name, call_options: nil
|
|
159
|
+
opts = default_options call_options: call_options
|
|
160
|
+
request = { resource: instance_path(name) }
|
|
161
|
+
instances.get_iam_policy request, opts
|
|
166
162
|
end
|
|
167
163
|
|
|
168
|
-
def set_instance_policy name, new_policy
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
164
|
+
def set_instance_policy name, new_policy, call_options: nil
|
|
165
|
+
opts = default_options call_options: call_options
|
|
166
|
+
request = {
|
|
167
|
+
resource: instance_path(name),
|
|
168
|
+
policy: new_policy
|
|
169
|
+
}
|
|
170
|
+
instances.set_iam_policy request, opts
|
|
172
171
|
end
|
|
173
172
|
|
|
174
|
-
def test_instance_permissions name, permissions
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
173
|
+
def test_instance_permissions name, permissions, call_options: nil
|
|
174
|
+
opts = default_options call_options: call_options
|
|
175
|
+
request = {
|
|
176
|
+
resource: instance_path(name),
|
|
177
|
+
permissions: permissions
|
|
178
|
+
}
|
|
179
|
+
instances.test_iam_permissions request, opts
|
|
178
180
|
end
|
|
179
181
|
|
|
180
|
-
def list_instance_configs token: nil, max: nil
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
|
182
|
+
def list_instance_configs token: nil, max: nil, call_options: nil
|
|
183
|
+
opts = default_options call_options: call_options
|
|
184
|
+
request = { parent: project_path, page_size: max, page_token: token }
|
|
185
|
+
paged_enum = instances.list_instance_configs request, opts
|
|
186
|
+
paged_enum.response
|
|
191
187
|
end
|
|
192
188
|
|
|
193
|
-
def get_instance_config name
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
189
|
+
def get_instance_config name, call_options: nil
|
|
190
|
+
opts = default_options call_options: call_options
|
|
191
|
+
request = { name: instance_config_path(name) }
|
|
192
|
+
instances.get_instance_config request, opts
|
|
197
193
|
end
|
|
198
194
|
|
|
199
|
-
def list_databases instance_id, token: nil, max: nil
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
paged_enum.page.response
|
|
209
|
-
end
|
|
195
|
+
def list_databases instance_id, token: nil, max: nil, call_options: nil
|
|
196
|
+
opts = default_options call_options: call_options
|
|
197
|
+
request = {
|
|
198
|
+
parent: instance_path(instance_id),
|
|
199
|
+
page_size: max,
|
|
200
|
+
page_token: token
|
|
201
|
+
}
|
|
202
|
+
paged_enum = databases.list_databases request, opts
|
|
203
|
+
paged_enum.response
|
|
210
204
|
end
|
|
211
205
|
|
|
212
|
-
def get_database instance_id, database_id
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
206
|
+
def get_database instance_id, database_id, call_options: nil
|
|
207
|
+
opts = default_options call_options: call_options
|
|
208
|
+
request = { name: database_path(instance_id, database_id) }
|
|
209
|
+
databases.get_database request, opts
|
|
216
210
|
end
|
|
217
211
|
|
|
218
|
-
def create_database instance_id, database_id, statements: []
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
212
|
+
def create_database instance_id, database_id, statements: [],
|
|
213
|
+
call_options: nil
|
|
214
|
+
opts = default_options call_options: call_options
|
|
215
|
+
request = {
|
|
216
|
+
parent: instance_path(instance_id),
|
|
217
|
+
create_statement: "CREATE DATABASE `#{database_id}`",
|
|
218
|
+
extra_statements: Array(statements)
|
|
219
|
+
}
|
|
220
|
+
databases.create_database request, opts
|
|
225
221
|
end
|
|
226
222
|
|
|
227
|
-
def drop_database instance_id, database_id
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
223
|
+
def drop_database instance_id, database_id, call_options: nil
|
|
224
|
+
opts = default_options call_options: call_options
|
|
225
|
+
request = { database: database_path(instance_id, database_id) }
|
|
226
|
+
databases.drop_database request, opts
|
|
231
227
|
end
|
|
232
228
|
|
|
233
|
-
def get_database_ddl instance_id, database_id
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
229
|
+
def get_database_ddl instance_id, database_id, call_options: nil
|
|
230
|
+
opts = default_options call_options: call_options
|
|
231
|
+
request = { database: database_path(instance_id, database_id) }
|
|
232
|
+
databases.get_database_ddl request, opts
|
|
237
233
|
end
|
|
238
234
|
|
|
239
235
|
def update_database_ddl instance_id, database_id, statements: [],
|
|
240
|
-
operation_id: nil
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
236
|
+
operation_id: nil, call_options: nil
|
|
237
|
+
opts = default_options call_options: call_options
|
|
238
|
+
request = {
|
|
239
|
+
database: database_path(instance_id, database_id),
|
|
240
|
+
statements: Array(statements),
|
|
241
|
+
operation_id: operation_id
|
|
242
|
+
}
|
|
243
|
+
databases.update_database_ddl request, opts
|
|
247
244
|
end
|
|
248
245
|
|
|
249
|
-
def get_database_policy instance_id, database_id
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
246
|
+
def get_database_policy instance_id, database_id, call_options: nil
|
|
247
|
+
opts = default_options call_options: call_options
|
|
248
|
+
request = { resource: database_path(instance_id, database_id) }
|
|
249
|
+
databases.get_iam_policy request, opts
|
|
253
250
|
end
|
|
254
251
|
|
|
255
|
-
def set_database_policy instance_id, database_id, new_policy
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
252
|
+
def set_database_policy instance_id, database_id, new_policy,
|
|
253
|
+
call_options: nil
|
|
254
|
+
opts = default_options call_options: call_options
|
|
255
|
+
request = {
|
|
256
|
+
resource: database_path(instance_id, database_id),
|
|
257
|
+
policy: new_policy
|
|
258
|
+
}
|
|
259
|
+
databases.set_iam_policy request, opts
|
|
260
260
|
end
|
|
261
261
|
|
|
262
|
-
def test_database_permissions instance_id, database_id, permissions
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
262
|
+
def test_database_permissions instance_id, database_id, permissions,
|
|
263
|
+
call_options: nil
|
|
264
|
+
opts = default_options call_options: call_options
|
|
265
|
+
request = {
|
|
266
|
+
resource: database_path(instance_id, database_id),
|
|
267
|
+
permissions: permissions
|
|
268
|
+
}
|
|
269
|
+
databases.test_iam_permissions request, opts
|
|
267
270
|
end
|
|
268
271
|
|
|
269
|
-
def get_session session_name
|
|
270
|
-
opts =
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
end
|
|
272
|
+
def get_session session_name, call_options: nil
|
|
273
|
+
opts = default_options session_name: session_name,
|
|
274
|
+
call_options: call_options
|
|
275
|
+
service.get_session({ name: session_name }, opts)
|
|
274
276
|
end
|
|
275
277
|
|
|
276
|
-
def create_session database_name, labels: nil
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
278
|
+
def create_session database_name, labels: nil,
|
|
279
|
+
call_options: nil
|
|
280
|
+
opts = default_options session_name: database_name,
|
|
281
|
+
call_options: call_options
|
|
282
|
+
session = V1::Session.new labels: labels if labels
|
|
283
|
+
service.create_session(
|
|
284
|
+
{ database: database_name, session: session }, opts
|
|
285
|
+
)
|
|
283
286
|
end
|
|
284
287
|
|
|
285
|
-
def batch_create_sessions database_name, session_count, labels: nil
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
288
|
+
def batch_create_sessions database_name, session_count, labels: nil,
|
|
289
|
+
call_options: nil
|
|
290
|
+
opts = default_options session_name: database_name,
|
|
291
|
+
call_options: call_options
|
|
292
|
+
session = V1::Session.new labels: labels if labels
|
|
293
|
+
# The response may have fewer sessions than requested in the RPC.
|
|
294
|
+
request = {
|
|
295
|
+
database: database_name,
|
|
296
|
+
session_count: session_count,
|
|
297
|
+
session_template: session
|
|
298
|
+
}
|
|
299
|
+
service.batch_create_sessions request, opts
|
|
295
300
|
end
|
|
296
301
|
|
|
297
|
-
def delete_session session_name
|
|
298
|
-
opts =
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
end
|
|
302
|
+
def delete_session session_name, call_options: nil
|
|
303
|
+
opts = default_options session_name: session_name,
|
|
304
|
+
call_options: call_options
|
|
305
|
+
service.delete_session({ name: session_name }, opts)
|
|
302
306
|
end
|
|
303
307
|
|
|
304
308
|
def execute_streaming_sql session_name, sql, transaction: nil,
|
|
305
309
|
params: nil, types: nil, resume_token: nil,
|
|
306
310
|
partition_token: nil, seqno: nil,
|
|
307
|
-
query_options: nil
|
|
308
|
-
opts =
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
311
|
+
query_options: nil, call_options: nil
|
|
312
|
+
opts = default_options session_name: session_name,
|
|
313
|
+
call_options: call_options
|
|
314
|
+
request = {
|
|
315
|
+
session: session_name,
|
|
316
|
+
sql: sql,
|
|
317
|
+
transaction: transaction,
|
|
318
|
+
params: params,
|
|
319
|
+
param_types: types,
|
|
320
|
+
resume_token: resume_token,
|
|
321
|
+
partition_token: partition_token,
|
|
322
|
+
seqno: seqno,
|
|
323
|
+
query_options: query_options
|
|
324
|
+
}
|
|
325
|
+
service.execute_streaming_sql request, opts
|
|
320
326
|
end
|
|
321
327
|
|
|
322
|
-
def execute_batch_dml session_name, transaction, statements, seqno
|
|
323
|
-
|
|
328
|
+
def execute_batch_dml session_name, transaction, statements, seqno,
|
|
329
|
+
call_options: nil
|
|
330
|
+
opts = default_options session_name: session_name,
|
|
331
|
+
call_options: call_options
|
|
324
332
|
statements = statements.map(&:to_grpc)
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
333
|
+
request = {
|
|
334
|
+
session: session_name,
|
|
335
|
+
transaction: transaction,
|
|
336
|
+
statements: statements,
|
|
337
|
+
seqno: seqno
|
|
338
|
+
}
|
|
339
|
+
results = service.execute_batch_dml request, opts
|
|
340
|
+
|
|
332
341
|
if results.status.code.zero?
|
|
333
342
|
results.result_sets.map { |rs| rs.stats.row_count_exact }
|
|
334
343
|
else
|
|
@@ -342,87 +351,94 @@ module Google
|
|
|
342
351
|
|
|
343
352
|
def streaming_read_table session_name, table_name, columns, keys: nil,
|
|
344
353
|
index: nil, transaction: nil, limit: nil,
|
|
345
|
-
resume_token: nil, partition_token: nil
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
+
resume_token: nil, partition_token: nil,
|
|
355
|
+
call_options: nil
|
|
356
|
+
opts = default_options session_name: session_name,
|
|
357
|
+
call_options: call_options
|
|
358
|
+
request = {
|
|
359
|
+
session: session_name, table: table_name, columns: columns,
|
|
360
|
+
key_set: keys, transaction: transaction, index: index,
|
|
361
|
+
limit: limit, resume_token: resume_token,
|
|
362
|
+
partition_token: partition_token
|
|
363
|
+
}
|
|
364
|
+
service.streaming_read request, opts
|
|
354
365
|
end
|
|
355
366
|
|
|
356
367
|
def partition_read session_name, table_name, columns, transaction,
|
|
357
368
|
keys: nil, index: nil, partition_size_bytes: nil,
|
|
358
|
-
max_partitions: nil
|
|
369
|
+
max_partitions: nil, call_options: nil
|
|
359
370
|
partition_opts = partition_options partition_size_bytes,
|
|
360
371
|
max_partitions
|
|
361
372
|
|
|
362
|
-
opts =
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
373
|
+
opts = default_options session_name: session_name,
|
|
374
|
+
call_options: call_options
|
|
375
|
+
request = {
|
|
376
|
+
session: session_name, table: table_name, key_set: keys,
|
|
377
|
+
transaction: transaction, index: index, columns: columns,
|
|
378
|
+
partition_options: partition_opts
|
|
379
|
+
}
|
|
380
|
+
service.partition_read request, opts
|
|
370
381
|
end
|
|
371
382
|
|
|
372
383
|
def partition_query session_name, sql, transaction, params: nil,
|
|
373
384
|
types: nil, partition_size_bytes: nil,
|
|
374
|
-
max_partitions: nil
|
|
385
|
+
max_partitions: nil, call_options: nil
|
|
375
386
|
partition_opts = partition_options partition_size_bytes,
|
|
376
387
|
max_partitions
|
|
377
388
|
|
|
378
|
-
opts =
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
end
|
|
389
|
+
opts = default_options session_name: session_name,
|
|
390
|
+
call_options: call_options
|
|
391
|
+
request = {
|
|
392
|
+
session: session_name, sql: sql, transaction: transaction,
|
|
393
|
+
params: params, param_types: types,
|
|
394
|
+
partition_options: partition_opts
|
|
395
|
+
}
|
|
396
|
+
service.partition_query request, opts
|
|
387
397
|
end
|
|
388
398
|
|
|
389
|
-
def commit session_name, mutations = [], transaction_id: nil
|
|
399
|
+
def commit session_name, mutations = [], transaction_id: nil,
|
|
400
|
+
commit_options: nil, call_options: nil
|
|
390
401
|
tx_opts = nil
|
|
391
402
|
if transaction_id.nil?
|
|
392
|
-
tx_opts =
|
|
393
|
-
read_write:
|
|
403
|
+
tx_opts = V1::TransactionOptions.new(
|
|
404
|
+
read_write: V1::TransactionOptions::ReadWrite.new
|
|
394
405
|
)
|
|
395
406
|
end
|
|
396
|
-
opts =
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
407
|
+
opts = default_options session_name: session_name,
|
|
408
|
+
call_options: call_options
|
|
409
|
+
request = {
|
|
410
|
+
session: session_name, transaction_id: transaction_id,
|
|
411
|
+
single_use_transaction: tx_opts, mutations: mutations
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if commit_options
|
|
415
|
+
request[:return_commit_stats] = commit_options[:return_commit_stats]
|
|
402
416
|
end
|
|
417
|
+
|
|
418
|
+
service.commit request, opts
|
|
403
419
|
end
|
|
404
420
|
|
|
405
|
-
def rollback session_name, transaction_id
|
|
406
|
-
opts =
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
421
|
+
def rollback session_name, transaction_id, call_options: nil
|
|
422
|
+
opts = default_options session_name: session_name,
|
|
423
|
+
call_options: call_options
|
|
424
|
+
request = { session: session_name, transaction_id: transaction_id }
|
|
425
|
+
service.rollback request, opts
|
|
410
426
|
end
|
|
411
427
|
|
|
412
|
-
def begin_transaction session_name
|
|
413
|
-
tx_opts =
|
|
414
|
-
read_write:
|
|
428
|
+
def begin_transaction session_name, call_options: nil
|
|
429
|
+
tx_opts = V1::TransactionOptions.new(
|
|
430
|
+
read_write: V1::TransactionOptions::ReadWrite.new
|
|
415
431
|
)
|
|
416
|
-
opts =
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
432
|
+
opts = default_options session_name: session_name,
|
|
433
|
+
call_options: call_options
|
|
434
|
+
request = { session: session_name, options: tx_opts }
|
|
435
|
+
service.begin_transaction request, opts
|
|
420
436
|
end
|
|
421
437
|
|
|
422
438
|
def create_snapshot session_name, strong: nil, timestamp: nil,
|
|
423
|
-
staleness: nil
|
|
424
|
-
tx_opts =
|
|
425
|
-
read_only:
|
|
439
|
+
staleness: nil, call_options: nil
|
|
440
|
+
tx_opts = V1::TransactionOptions.new(
|
|
441
|
+
read_only: V1::TransactionOptions::ReadOnly.new(
|
|
426
442
|
{
|
|
427
443
|
strong: strong,
|
|
428
444
|
read_timestamp: Convert.time_to_timestamp(timestamp),
|
|
@@ -431,92 +447,108 @@ module Google
|
|
|
431
447
|
}.delete_if { |_, v| v.nil? }
|
|
432
448
|
)
|
|
433
449
|
)
|
|
434
|
-
opts =
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
450
|
+
opts = default_options session_name: session_name,
|
|
451
|
+
call_options: call_options
|
|
452
|
+
request = { session: session_name, options: tx_opts }
|
|
453
|
+
service.begin_transaction request, opts
|
|
438
454
|
end
|
|
439
455
|
|
|
440
|
-
def create_pdml session_name
|
|
441
|
-
tx_opts =
|
|
442
|
-
partitioned_dml:
|
|
443
|
-
Google::Spanner::V1::TransactionOptions::PartitionedDml.new
|
|
456
|
+
def create_pdml session_name, call_options: nil
|
|
457
|
+
tx_opts = V1::TransactionOptions.new(
|
|
458
|
+
partitioned_dml: V1::TransactionOptions::PartitionedDml.new
|
|
444
459
|
)
|
|
445
|
-
opts =
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
460
|
+
opts = default_options session_name: session_name,
|
|
461
|
+
call_options: call_options
|
|
462
|
+
request = { session: session_name, options: tx_opts }
|
|
463
|
+
service.begin_transaction request, opts
|
|
449
464
|
end
|
|
450
465
|
|
|
451
|
-
def create_backup instance_id, database_id, backup_id, expire_time
|
|
466
|
+
def create_backup instance_id, database_id, backup_id, expire_time,
|
|
467
|
+
version_time, call_options: nil
|
|
468
|
+
opts = default_options call_options: call_options
|
|
452
469
|
backup = {
|
|
453
470
|
database: database_path(instance_id, database_id),
|
|
454
|
-
expire_time: expire_time
|
|
471
|
+
expire_time: expire_time,
|
|
472
|
+
version_time: version_time
|
|
455
473
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
end
|
|
463
|
-
|
|
464
|
-
def get_backup instance_id, backup_id
|
|
465
|
-
execute do
|
|
466
|
-
databases.get_backup backup_path(instance_id, backup_id)
|
|
467
|
-
end
|
|
468
|
-
end
|
|
469
|
-
|
|
470
|
-
def update_backup backup, update_mask
|
|
471
|
-
execute do
|
|
472
|
-
databases.update_backup backup, update_mask
|
|
473
|
-
end
|
|
474
|
+
request = {
|
|
475
|
+
parent: instance_path(instance_id),
|
|
476
|
+
backup_id: backup_id,
|
|
477
|
+
backup: backup
|
|
478
|
+
}
|
|
479
|
+
databases.create_backup request, opts
|
|
474
480
|
end
|
|
475
481
|
|
|
476
|
-
def
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
482
|
+
def get_backup instance_id, backup_id, call_options: nil
|
|
483
|
+
opts = default_options call_options: call_options
|
|
484
|
+
request = { name: backup_path(instance_id, backup_id) }
|
|
485
|
+
databases.get_backup request, opts
|
|
480
486
|
end
|
|
481
487
|
|
|
482
|
-
def
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
filter,
|
|
487
|
-
page_size: page_size
|
|
488
|
-
end
|
|
488
|
+
def update_backup backup, update_mask, call_options: nil
|
|
489
|
+
opts = default_options call_options: call_options
|
|
490
|
+
request = { backup: backup, update_mask: update_mask }
|
|
491
|
+
databases.update_backup request, opts
|
|
489
492
|
end
|
|
490
493
|
|
|
491
|
-
def
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
filter,
|
|
496
|
-
page_size: page_size
|
|
497
|
-
end
|
|
494
|
+
def delete_backup instance_id, backup_id, call_options: nil
|
|
495
|
+
opts = default_options call_options: call_options
|
|
496
|
+
request = { name: backup_path(instance_id, backup_id) }
|
|
497
|
+
databases.delete_backup request, opts
|
|
498
498
|
end
|
|
499
499
|
|
|
500
|
-
def
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
500
|
+
def list_backups instance_id,
|
|
501
|
+
filter: nil, page_size: nil, page_token: nil,
|
|
502
|
+
call_options: nil
|
|
503
|
+
opts = default_options call_options: call_options
|
|
504
|
+
request = {
|
|
505
|
+
parent: instance_path(instance_id),
|
|
506
|
+
filter: filter,
|
|
507
|
+
page_size: page_size,
|
|
508
|
+
page_token: page_token
|
|
509
|
+
}
|
|
510
|
+
databases.list_backups request, opts
|
|
511
|
+
end
|
|
512
|
+
|
|
513
|
+
def list_database_operations instance_id,
|
|
514
|
+
filter: nil,
|
|
515
|
+
page_size: nil,
|
|
516
|
+
page_token: nil,
|
|
517
|
+
call_options: nil
|
|
518
|
+
opts = default_options call_options: call_options
|
|
519
|
+
request = {
|
|
520
|
+
parent: instance_path(instance_id),
|
|
521
|
+
filter: filter,
|
|
522
|
+
page_size: page_size,
|
|
523
|
+
page_token: page_token
|
|
524
|
+
}
|
|
525
|
+
databases.list_database_operations request, opts
|
|
526
|
+
end
|
|
527
|
+
|
|
528
|
+
def list_backup_operations instance_id,
|
|
529
|
+
filter: nil, page_size: nil,
|
|
530
|
+
page_token: nil,
|
|
531
|
+
call_options: nil
|
|
532
|
+
opts = default_options call_options: call_options
|
|
533
|
+
request = {
|
|
534
|
+
parent: instance_path(instance_id),
|
|
535
|
+
filter: filter,
|
|
536
|
+
page_size: page_size,
|
|
537
|
+
page_token: page_token
|
|
538
|
+
}
|
|
539
|
+
databases.list_backup_operations request, opts
|
|
507
540
|
end
|
|
508
541
|
|
|
509
|
-
def restore_database
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
end
|
|
542
|
+
def restore_database backup_instance_id, backup_id,
|
|
543
|
+
database_instance_id, database_id,
|
|
544
|
+
call_options: nil
|
|
545
|
+
opts = default_options call_options: call_options
|
|
546
|
+
request = {
|
|
547
|
+
parent: instance_path(database_instance_id),
|
|
548
|
+
database_id: database_id,
|
|
549
|
+
backup: backup_path(backup_instance_id, backup_id)
|
|
550
|
+
}
|
|
551
|
+
databases.restore_database request, opts
|
|
520
552
|
end
|
|
521
553
|
|
|
522
554
|
def inspect
|
|
@@ -525,16 +557,6 @@ module Google
|
|
|
525
557
|
|
|
526
558
|
protected
|
|
527
559
|
|
|
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
560
|
def lib_name_with_prefix
|
|
539
561
|
return "gccl" if [nil, "gccl"].include? lib_name
|
|
540
562
|
|
|
@@ -543,15 +565,22 @@ module Google
|
|
|
543
565
|
value << " gccl"
|
|
544
566
|
end
|
|
545
567
|
|
|
546
|
-
def
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
568
|
+
def default_options session_name: nil, call_options: nil
|
|
569
|
+
opts = {}
|
|
570
|
+
if session_name
|
|
571
|
+
default_prefix = session_name.split("/sessions/").first
|
|
572
|
+
opts[:metadata] = { "google-cloud-resource-prefix" => default_prefix }
|
|
573
|
+
end
|
|
574
|
+
if call_options
|
|
575
|
+
opts[:timeout] = call_options[:timeout] if call_options[:timeout]
|
|
576
|
+
opts[:retry_policy] = call_options[:retry_policy] if call_options[:retry_policy]
|
|
577
|
+
end
|
|
578
|
+
return opts unless opts.empty?
|
|
550
579
|
end
|
|
551
580
|
|
|
552
581
|
def partition_options partition_size_bytes, max_partitions
|
|
553
582
|
return nil unless partition_size_bytes || max_partitions
|
|
554
|
-
partition_opts =
|
|
583
|
+
partition_opts = V1::PartitionOptions.new
|
|
555
584
|
if partition_size_bytes
|
|
556
585
|
partition_opts.partition_size_bytes = partition_size_bytes
|
|
557
586
|
end
|
|
@@ -560,48 +589,38 @@ module Google
|
|
|
560
589
|
end
|
|
561
590
|
|
|
562
591
|
def project_path
|
|
563
|
-
Admin::Instance::V1::
|
|
592
|
+
Admin::Instance::V1::InstanceAdmin::Paths.project_path \
|
|
593
|
+
project: project
|
|
564
594
|
end
|
|
565
595
|
|
|
566
596
|
def instance_path name
|
|
567
597
|
return name if name.to_s.include? "/"
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
598
|
+
|
|
599
|
+
Admin::Instance::V1::InstanceAdmin::Paths.instance_path \
|
|
600
|
+
project: project, instance: name
|
|
571
601
|
end
|
|
572
602
|
|
|
573
603
|
def instance_config_path name
|
|
574
604
|
return name if name.to_s.include? "/"
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
605
|
+
|
|
606
|
+
Admin::Instance::V1::InstanceAdmin::Paths.instance_config_path \
|
|
607
|
+
project: project, instance_config: name
|
|
578
608
|
end
|
|
579
609
|
|
|
580
610
|
def database_path instance_id, database_id
|
|
581
|
-
Admin::Database::V1::
|
|
582
|
-
project, instance_id, database_id
|
|
583
|
-
)
|
|
611
|
+
Admin::Database::V1::DatabaseAdmin::Paths.database_path \
|
|
612
|
+
project: project, instance: instance_id, database: database_id
|
|
584
613
|
end
|
|
585
614
|
|
|
586
615
|
def session_path instance_id, database_id, session_id
|
|
587
|
-
V1::
|
|
588
|
-
project, instance_id, database_id,
|
|
589
|
-
|
|
616
|
+
V1::Spanner::Paths.session_path \
|
|
617
|
+
project: project, instance: instance_id, database: database_id,
|
|
618
|
+
session: session_id
|
|
590
619
|
end
|
|
591
620
|
|
|
592
621
|
def backup_path instance_id, backup_id
|
|
593
|
-
Admin::Database::V1::
|
|
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)
|
|
622
|
+
Admin::Database::V1::DatabaseAdmin::Paths.backup_path \
|
|
623
|
+
project: project, instance: instance_id, backup: backup_id
|
|
605
624
|
end
|
|
606
625
|
end
|
|
607
626
|
end
|