google-cloud-datastore-v1 0.1.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.
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ # This gem does not autoload during Bundler.require. To load this gem,
20
+ # issue explicit require statements for the packages desired, e.g.:
21
+ # require "google/cloud/datastore/v1"
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "google/cloud/datastore/v1/datastore"
20
+ require "google/cloud/datastore/v1/version"
21
+
22
+ module Google
23
+ module Cloud
24
+ module Datastore
25
+ ##
26
+ # To load this package, including all its services, and instantiate a client:
27
+ #
28
+ # require "google/cloud/datastore/v1"
29
+ # client = ::Google::Cloud::Datastore::V1::Datastore::Client.new
30
+ #
31
+ module V1
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "gapic/common"
20
+ require "gapic/config"
21
+ require "gapic/config/method"
22
+
23
+ require "google/cloud/datastore/v1/version"
24
+
25
+ require "google/cloud/datastore/v1/datastore/credentials"
26
+ require "google/cloud/datastore/v1/datastore/client"
27
+
28
+ module Google
29
+ module Cloud
30
+ module Datastore
31
+ module V1
32
+ ##
33
+ # Each RPC normalizes the partition IDs of the keys in its input entities,
34
+ # and always returns entities with keys with normalized partition IDs.
35
+ # This applies to all keys and entities, including those in values, except keys
36
+ # with both an empty path and an empty or unset partition ID. Normalization of
37
+ # input keys sets the project ID (if not already set) to the project ID from
38
+ # the request.
39
+ #
40
+ # To load this service and instantiate a client:
41
+ #
42
+ # require "google/cloud/datastore/v1/datastore"
43
+ # client = ::Google::Cloud::Datastore::V1::Datastore::Client.new
44
+ #
45
+ module Datastore
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ helper_path = ::File.join __dir__, "datastore", "helpers.rb"
53
+ require "google/cloud/datastore/v1/datastore/helpers" if ::File.file? helper_path
@@ -0,0 +1,893 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "google/cloud/errors"
20
+ require "google/datastore/v1/datastore_pb"
21
+
22
+ module Google
23
+ module Cloud
24
+ module Datastore
25
+ module V1
26
+ module Datastore
27
+ ##
28
+ # Client for the Datastore service.
29
+ #
30
+ # Each RPC normalizes the partition IDs of the keys in its input entities,
31
+ # and always returns entities with keys with normalized partition IDs.
32
+ # This applies to all keys and entities, including those in values, except keys
33
+ # with both an empty path and an empty or unset partition ID. Normalization of
34
+ # input keys sets the project ID (if not already set) to the project ID from
35
+ # the request.
36
+ #
37
+ class Client
38
+ # @private
39
+ attr_reader :datastore_stub
40
+
41
+ ##
42
+ # Configure the Datastore Client class.
43
+ #
44
+ # See {::Google::Cloud::Datastore::V1::Datastore::Client::Configuration}
45
+ # for a description of the configuration fields.
46
+ #
47
+ # ## Example
48
+ #
49
+ # To modify the configuration for all Datastore clients:
50
+ #
51
+ # ::Google::Cloud::Datastore::V1::Datastore::Client.configure do |config|
52
+ # config.timeout = 10.0
53
+ # end
54
+ #
55
+ # @yield [config] Configure the Client client.
56
+ # @yieldparam config [Client::Configuration]
57
+ #
58
+ # @return [Client::Configuration]
59
+ #
60
+ def self.configure
61
+ @configure ||= begin
62
+ namespace = ["Google", "Cloud", "Datastore", "V1"]
63
+ parent_config = while namespace.any?
64
+ parent_name = namespace.join "::"
65
+ parent_const = const_get parent_name
66
+ break parent_const.configure if parent_const&.respond_to? :configure
67
+ namespace.pop
68
+ end
69
+ default_config = Client::Configuration.new parent_config
70
+
71
+ default_config.rpcs.lookup.timeout = 60.0
72
+ default_config.rpcs.lookup.retry_policy = {
73
+ initial_delay: 0.1,
74
+ max_delay: 60.0,
75
+ multiplier: 1.3,
76
+ retry_codes: ["UNAVAILABLE", "DEADLINE_EXCEEDED"]
77
+ }
78
+
79
+ default_config.rpcs.run_query.timeout = 60.0
80
+ default_config.rpcs.run_query.retry_policy = {
81
+ initial_delay: 0.1,
82
+ max_delay: 60.0,
83
+ multiplier: 1.3,
84
+ retry_codes: ["UNAVAILABLE", "DEADLINE_EXCEEDED"]
85
+ }
86
+
87
+ default_config.rpcs.begin_transaction.timeout = 60.0
88
+
89
+ default_config.rpcs.commit.timeout = 60.0
90
+
91
+ default_config.rpcs.rollback.timeout = 60.0
92
+
93
+ default_config.rpcs.allocate_ids.timeout = 60.0
94
+
95
+ default_config.rpcs.reserve_ids.timeout = 60.0
96
+ default_config.rpcs.reserve_ids.retry_policy = {
97
+ initial_delay: 0.1,
98
+ max_delay: 60.0,
99
+ multiplier: 1.3,
100
+ retry_codes: ["UNAVAILABLE", "DEADLINE_EXCEEDED"]
101
+ }
102
+
103
+ default_config
104
+ end
105
+ yield @configure if block_given?
106
+ @configure
107
+ end
108
+
109
+ ##
110
+ # Configure the Datastore Client instance.
111
+ #
112
+ # The configuration is set to the derived mode, meaning that values can be changed,
113
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
114
+ # should be made on {Client.configure}.
115
+ #
116
+ # See {::Google::Cloud::Datastore::V1::Datastore::Client::Configuration}
117
+ # for a description of the configuration fields.
118
+ #
119
+ # @yield [config] Configure the Client client.
120
+ # @yieldparam config [Client::Configuration]
121
+ #
122
+ # @return [Client::Configuration]
123
+ #
124
+ def configure
125
+ yield @config if block_given?
126
+ @config
127
+ end
128
+
129
+ ##
130
+ # Create a new Datastore client object.
131
+ #
132
+ # ## Examples
133
+ #
134
+ # To create a new Datastore client with the default
135
+ # configuration:
136
+ #
137
+ # client = ::Google::Cloud::Datastore::V1::Datastore::Client.new
138
+ #
139
+ # To create a new Datastore client with a custom
140
+ # configuration:
141
+ #
142
+ # client = ::Google::Cloud::Datastore::V1::Datastore::Client.new do |config|
143
+ # config.timeout = 10.0
144
+ # end
145
+ #
146
+ # @yield [config] Configure the Datastore client.
147
+ # @yieldparam config [Client::Configuration]
148
+ #
149
+ def initialize
150
+ # These require statements are intentionally placed here to initialize
151
+ # the gRPC module only when it's required.
152
+ # See https://github.com/googleapis/toolkit/issues/446
153
+ require "gapic/grpc"
154
+ require "google/datastore/v1/datastore_services_pb"
155
+
156
+ # Create the configuration object
157
+ @config = Configuration.new Client.configure
158
+
159
+ # Yield the configuration if needed
160
+ yield @config if block_given?
161
+
162
+ # Create credentials
163
+ credentials = @config.credentials
164
+ credentials ||= Credentials.default scope: @config.scope
165
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
166
+ credentials = Credentials.new credentials, scope: @config.scope
167
+ end
168
+ @quota_project_id = @config.quota_project
169
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
170
+
171
+ @datastore_stub = ::Gapic::ServiceStub.new(
172
+ ::Google::Cloud::Datastore::V1::Datastore::Stub,
173
+ credentials: credentials,
174
+ endpoint: @config.endpoint,
175
+ channel_args: @config.channel_args,
176
+ interceptors: @config.interceptors
177
+ )
178
+ end
179
+
180
+ # Service calls
181
+
182
+ ##
183
+ # Looks up entities by key.
184
+ #
185
+ # @overload lookup(request, options = nil)
186
+ # Pass arguments to `lookup` via a request object, either of type
187
+ # {::Google::Cloud::Datastore::V1::LookupRequest} or an equivalent Hash.
188
+ #
189
+ # @param request [::Google::Cloud::Datastore::V1::LookupRequest, ::Hash]
190
+ # A request object representing the call parameters. Required. To specify no
191
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
192
+ # @param options [::Gapic::CallOptions, ::Hash]
193
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
194
+ #
195
+ # @overload lookup(project_id: nil, read_options: nil, keys: nil)
196
+ # Pass arguments to `lookup` via keyword arguments. Note that at
197
+ # least one keyword argument is required. To specify no parameters, or to keep all
198
+ # the default parameter values, pass an empty Hash as a request object (see above).
199
+ #
200
+ # @param project_id [::String]
201
+ # Required. The ID of the project against which to make the request.
202
+ # @param read_options [::Google::Cloud::Datastore::V1::ReadOptions, ::Hash]
203
+ # The options for this lookup request.
204
+ # @param keys [::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>]
205
+ # Required. Keys of entities to look up.
206
+ #
207
+ # @yield [response, operation] Access the result along with the RPC operation
208
+ # @yieldparam response [::Google::Cloud::Datastore::V1::LookupResponse]
209
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
210
+ #
211
+ # @return [::Google::Cloud::Datastore::V1::LookupResponse]
212
+ #
213
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
214
+ #
215
+ def lookup request, options = nil
216
+ raise ::ArgumentError, "request must be provided" if request.nil?
217
+
218
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::LookupRequest
219
+
220
+ # Converts hash and nil to an options object
221
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
222
+
223
+ # Customize the options with defaults
224
+ metadata = @config.rpcs.lookup.metadata.to_h
225
+
226
+ # Set x-goog-api-client and x-goog-user-project headers
227
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
228
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
229
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION
230
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
231
+
232
+ header_params = {
233
+ "project_id" => request.project_id
234
+ }
235
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
236
+ metadata[:"x-goog-request-params"] ||= request_params_header
237
+
238
+ options.apply_defaults timeout: @config.rpcs.lookup.timeout,
239
+ metadata: metadata,
240
+ retry_policy: @config.rpcs.lookup.retry_policy
241
+ options.apply_defaults metadata: @config.metadata,
242
+ retry_policy: @config.retry_policy
243
+
244
+ @datastore_stub.call_rpc :lookup, request, options: options do |response, operation|
245
+ yield response, operation if block_given?
246
+ return response
247
+ end
248
+ rescue ::GRPC::BadStatus => e
249
+ raise ::Google::Cloud::Error.from_error(e)
250
+ end
251
+
252
+ ##
253
+ # Queries for entities.
254
+ #
255
+ # @overload run_query(request, options = nil)
256
+ # Pass arguments to `run_query` via a request object, either of type
257
+ # {::Google::Cloud::Datastore::V1::RunQueryRequest} or an equivalent Hash.
258
+ #
259
+ # @param request [::Google::Cloud::Datastore::V1::RunQueryRequest, ::Hash]
260
+ # A request object representing the call parameters. Required. To specify no
261
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
262
+ # @param options [::Gapic::CallOptions, ::Hash]
263
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
264
+ #
265
+ # @overload run_query(project_id: nil, partition_id: nil, read_options: nil, query: nil, gql_query: nil)
266
+ # Pass arguments to `run_query` via keyword arguments. Note that at
267
+ # least one keyword argument is required. To specify no parameters, or to keep all
268
+ # the default parameter values, pass an empty Hash as a request object (see above).
269
+ #
270
+ # @param project_id [::String]
271
+ # Required. The ID of the project against which to make the request.
272
+ # @param partition_id [::Google::Cloud::Datastore::V1::PartitionId, ::Hash]
273
+ # Entities are partitioned into subsets, identified by a partition ID.
274
+ # Queries are scoped to a single partition.
275
+ # This partition ID is normalized with the standard default context
276
+ # partition ID.
277
+ # @param read_options [::Google::Cloud::Datastore::V1::ReadOptions, ::Hash]
278
+ # The options for this query.
279
+ # @param query [::Google::Cloud::Datastore::V1::Query, ::Hash]
280
+ # The query to run.
281
+ # @param gql_query [::Google::Cloud::Datastore::V1::GqlQuery, ::Hash]
282
+ # The GQL query to run.
283
+ #
284
+ # @yield [response, operation] Access the result along with the RPC operation
285
+ # @yieldparam response [::Google::Cloud::Datastore::V1::RunQueryResponse]
286
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
287
+ #
288
+ # @return [::Google::Cloud::Datastore::V1::RunQueryResponse]
289
+ #
290
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
291
+ #
292
+ def run_query request, options = nil
293
+ raise ::ArgumentError, "request must be provided" if request.nil?
294
+
295
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::RunQueryRequest
296
+
297
+ # Converts hash and nil to an options object
298
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
299
+
300
+ # Customize the options with defaults
301
+ metadata = @config.rpcs.run_query.metadata.to_h
302
+
303
+ # Set x-goog-api-client and x-goog-user-project headers
304
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
305
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
306
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION
307
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
308
+
309
+ header_params = {
310
+ "project_id" => request.project_id
311
+ }
312
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
313
+ metadata[:"x-goog-request-params"] ||= request_params_header
314
+
315
+ options.apply_defaults timeout: @config.rpcs.run_query.timeout,
316
+ metadata: metadata,
317
+ retry_policy: @config.rpcs.run_query.retry_policy
318
+ options.apply_defaults metadata: @config.metadata,
319
+ retry_policy: @config.retry_policy
320
+
321
+ @datastore_stub.call_rpc :run_query, request, options: options do |response, operation|
322
+ yield response, operation if block_given?
323
+ return response
324
+ end
325
+ rescue ::GRPC::BadStatus => e
326
+ raise ::Google::Cloud::Error.from_error(e)
327
+ end
328
+
329
+ ##
330
+ # Begins a new transaction.
331
+ #
332
+ # @overload begin_transaction(request, options = nil)
333
+ # Pass arguments to `begin_transaction` via a request object, either of type
334
+ # {::Google::Cloud::Datastore::V1::BeginTransactionRequest} or an equivalent Hash.
335
+ #
336
+ # @param request [::Google::Cloud::Datastore::V1::BeginTransactionRequest, ::Hash]
337
+ # A request object representing the call parameters. Required. To specify no
338
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
339
+ # @param options [::Gapic::CallOptions, ::Hash]
340
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
341
+ #
342
+ # @overload begin_transaction(project_id: nil, transaction_options: nil)
343
+ # Pass arguments to `begin_transaction` via keyword arguments. Note that at
344
+ # least one keyword argument is required. To specify no parameters, or to keep all
345
+ # the default parameter values, pass an empty Hash as a request object (see above).
346
+ #
347
+ # @param project_id [::String]
348
+ # Required. The ID of the project against which to make the request.
349
+ # @param transaction_options [::Google::Cloud::Datastore::V1::TransactionOptions, ::Hash]
350
+ # Options for a new transaction.
351
+ #
352
+ # @yield [response, operation] Access the result along with the RPC operation
353
+ # @yieldparam response [::Google::Cloud::Datastore::V1::BeginTransactionResponse]
354
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
355
+ #
356
+ # @return [::Google::Cloud::Datastore::V1::BeginTransactionResponse]
357
+ #
358
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
359
+ #
360
+ def begin_transaction request, options = nil
361
+ raise ::ArgumentError, "request must be provided" if request.nil?
362
+
363
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::BeginTransactionRequest
364
+
365
+ # Converts hash and nil to an options object
366
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
367
+
368
+ # Customize the options with defaults
369
+ metadata = @config.rpcs.begin_transaction.metadata.to_h
370
+
371
+ # Set x-goog-api-client and x-goog-user-project headers
372
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
373
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
374
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION
375
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
376
+
377
+ header_params = {
378
+ "project_id" => request.project_id
379
+ }
380
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
381
+ metadata[:"x-goog-request-params"] ||= request_params_header
382
+
383
+ options.apply_defaults timeout: @config.rpcs.begin_transaction.timeout,
384
+ metadata: metadata,
385
+ retry_policy: @config.rpcs.begin_transaction.retry_policy
386
+ options.apply_defaults metadata: @config.metadata,
387
+ retry_policy: @config.retry_policy
388
+
389
+ @datastore_stub.call_rpc :begin_transaction, request, options: options do |response, operation|
390
+ yield response, operation if block_given?
391
+ return response
392
+ end
393
+ rescue ::GRPC::BadStatus => e
394
+ raise ::Google::Cloud::Error.from_error(e)
395
+ end
396
+
397
+ ##
398
+ # Commits a transaction, optionally creating, deleting or modifying some
399
+ # entities.
400
+ #
401
+ # @overload commit(request, options = nil)
402
+ # Pass arguments to `commit` via a request object, either of type
403
+ # {::Google::Cloud::Datastore::V1::CommitRequest} or an equivalent Hash.
404
+ #
405
+ # @param request [::Google::Cloud::Datastore::V1::CommitRequest, ::Hash]
406
+ # A request object representing the call parameters. Required. To specify no
407
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
408
+ # @param options [::Gapic::CallOptions, ::Hash]
409
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
410
+ #
411
+ # @overload commit(project_id: nil, mode: nil, transaction: nil, mutations: nil)
412
+ # Pass arguments to `commit` via keyword arguments. Note that at
413
+ # least one keyword argument is required. To specify no parameters, or to keep all
414
+ # the default parameter values, pass an empty Hash as a request object (see above).
415
+ #
416
+ # @param project_id [::String]
417
+ # Required. The ID of the project against which to make the request.
418
+ # @param mode [::Google::Cloud::Datastore::V1::CommitRequest::Mode]
419
+ # The type of commit to perform. Defaults to `TRANSACTIONAL`.
420
+ # @param transaction [::String]
421
+ # The identifier of the transaction associated with the commit. A
422
+ # transaction identifier is returned by a call to
423
+ # {::Google::Cloud::Datastore::V1::Datastore::Client#begin_transaction Datastore.BeginTransaction}.
424
+ # @param mutations [::Array<::Google::Cloud::Datastore::V1::Mutation, ::Hash>]
425
+ # The mutations to perform.
426
+ #
427
+ # When mode is `TRANSACTIONAL`, mutations affecting a single entity are
428
+ # applied in order. The following sequences of mutations affecting a single
429
+ # entity are not permitted in a single `Commit` request:
430
+ #
431
+ # - `insert` followed by `insert`
432
+ # - `update` followed by `insert`
433
+ # - `upsert` followed by `insert`
434
+ # - `delete` followed by `update`
435
+ #
436
+ # When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single
437
+ # entity.
438
+ #
439
+ # @yield [response, operation] Access the result along with the RPC operation
440
+ # @yieldparam response [::Google::Cloud::Datastore::V1::CommitResponse]
441
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
442
+ #
443
+ # @return [::Google::Cloud::Datastore::V1::CommitResponse]
444
+ #
445
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
446
+ #
447
+ def commit request, options = nil
448
+ raise ::ArgumentError, "request must be provided" if request.nil?
449
+
450
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::CommitRequest
451
+
452
+ # Converts hash and nil to an options object
453
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
454
+
455
+ # Customize the options with defaults
456
+ metadata = @config.rpcs.commit.metadata.to_h
457
+
458
+ # Set x-goog-api-client and x-goog-user-project headers
459
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
460
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
461
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION
462
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
463
+
464
+ header_params = {
465
+ "project_id" => request.project_id
466
+ }
467
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
468
+ metadata[:"x-goog-request-params"] ||= request_params_header
469
+
470
+ options.apply_defaults timeout: @config.rpcs.commit.timeout,
471
+ metadata: metadata,
472
+ retry_policy: @config.rpcs.commit.retry_policy
473
+ options.apply_defaults metadata: @config.metadata,
474
+ retry_policy: @config.retry_policy
475
+
476
+ @datastore_stub.call_rpc :commit, request, options: options do |response, operation|
477
+ yield response, operation if block_given?
478
+ return response
479
+ end
480
+ rescue ::GRPC::BadStatus => e
481
+ raise ::Google::Cloud::Error.from_error(e)
482
+ end
483
+
484
+ ##
485
+ # Rolls back a transaction.
486
+ #
487
+ # @overload rollback(request, options = nil)
488
+ # Pass arguments to `rollback` via a request object, either of type
489
+ # {::Google::Cloud::Datastore::V1::RollbackRequest} or an equivalent Hash.
490
+ #
491
+ # @param request [::Google::Cloud::Datastore::V1::RollbackRequest, ::Hash]
492
+ # A request object representing the call parameters. Required. To specify no
493
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
494
+ # @param options [::Gapic::CallOptions, ::Hash]
495
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
496
+ #
497
+ # @overload rollback(project_id: nil, transaction: nil)
498
+ # Pass arguments to `rollback` via keyword arguments. Note that at
499
+ # least one keyword argument is required. To specify no parameters, or to keep all
500
+ # the default parameter values, pass an empty Hash as a request object (see above).
501
+ #
502
+ # @param project_id [::String]
503
+ # Required. The ID of the project against which to make the request.
504
+ # @param transaction [::String]
505
+ # Required. The transaction identifier, returned by a call to
506
+ # {::Google::Cloud::Datastore::V1::Datastore::Client#begin_transaction Datastore.BeginTransaction}.
507
+ #
508
+ # @yield [response, operation] Access the result along with the RPC operation
509
+ # @yieldparam response [::Google::Cloud::Datastore::V1::RollbackResponse]
510
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
511
+ #
512
+ # @return [::Google::Cloud::Datastore::V1::RollbackResponse]
513
+ #
514
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
515
+ #
516
+ def rollback request, options = nil
517
+ raise ::ArgumentError, "request must be provided" if request.nil?
518
+
519
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::RollbackRequest
520
+
521
+ # Converts hash and nil to an options object
522
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
523
+
524
+ # Customize the options with defaults
525
+ metadata = @config.rpcs.rollback.metadata.to_h
526
+
527
+ # Set x-goog-api-client and x-goog-user-project headers
528
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
529
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
530
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION
531
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
532
+
533
+ header_params = {
534
+ "project_id" => request.project_id
535
+ }
536
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
537
+ metadata[:"x-goog-request-params"] ||= request_params_header
538
+
539
+ options.apply_defaults timeout: @config.rpcs.rollback.timeout,
540
+ metadata: metadata,
541
+ retry_policy: @config.rpcs.rollback.retry_policy
542
+ options.apply_defaults metadata: @config.metadata,
543
+ retry_policy: @config.retry_policy
544
+
545
+ @datastore_stub.call_rpc :rollback, request, options: options do |response, operation|
546
+ yield response, operation if block_given?
547
+ return response
548
+ end
549
+ rescue ::GRPC::BadStatus => e
550
+ raise ::Google::Cloud::Error.from_error(e)
551
+ end
552
+
553
+ ##
554
+ # Allocates IDs for the given keys, which is useful for referencing an entity
555
+ # before it is inserted.
556
+ #
557
+ # @overload allocate_ids(request, options = nil)
558
+ # Pass arguments to `allocate_ids` via a request object, either of type
559
+ # {::Google::Cloud::Datastore::V1::AllocateIdsRequest} or an equivalent Hash.
560
+ #
561
+ # @param request [::Google::Cloud::Datastore::V1::AllocateIdsRequest, ::Hash]
562
+ # A request object representing the call parameters. Required. To specify no
563
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
564
+ # @param options [::Gapic::CallOptions, ::Hash]
565
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
566
+ #
567
+ # @overload allocate_ids(project_id: nil, keys: nil)
568
+ # Pass arguments to `allocate_ids` via keyword arguments. Note that at
569
+ # least one keyword argument is required. To specify no parameters, or to keep all
570
+ # the default parameter values, pass an empty Hash as a request object (see above).
571
+ #
572
+ # @param project_id [::String]
573
+ # Required. The ID of the project against which to make the request.
574
+ # @param keys [::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>]
575
+ # Required. A list of keys with incomplete key paths for which to allocate IDs.
576
+ # No key may be reserved/read-only.
577
+ #
578
+ # @yield [response, operation] Access the result along with the RPC operation
579
+ # @yieldparam response [::Google::Cloud::Datastore::V1::AllocateIdsResponse]
580
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
581
+ #
582
+ # @return [::Google::Cloud::Datastore::V1::AllocateIdsResponse]
583
+ #
584
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
585
+ #
586
+ def allocate_ids request, options = nil
587
+ raise ::ArgumentError, "request must be provided" if request.nil?
588
+
589
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::AllocateIdsRequest
590
+
591
+ # Converts hash and nil to an options object
592
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
593
+
594
+ # Customize the options with defaults
595
+ metadata = @config.rpcs.allocate_ids.metadata.to_h
596
+
597
+ # Set x-goog-api-client and x-goog-user-project headers
598
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
599
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
600
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION
601
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
602
+
603
+ header_params = {
604
+ "project_id" => request.project_id
605
+ }
606
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
607
+ metadata[:"x-goog-request-params"] ||= request_params_header
608
+
609
+ options.apply_defaults timeout: @config.rpcs.allocate_ids.timeout,
610
+ metadata: metadata,
611
+ retry_policy: @config.rpcs.allocate_ids.retry_policy
612
+ options.apply_defaults metadata: @config.metadata,
613
+ retry_policy: @config.retry_policy
614
+
615
+ @datastore_stub.call_rpc :allocate_ids, request, options: options do |response, operation|
616
+ yield response, operation if block_given?
617
+ return response
618
+ end
619
+ rescue ::GRPC::BadStatus => e
620
+ raise ::Google::Cloud::Error.from_error(e)
621
+ end
622
+
623
+ ##
624
+ # Prevents the supplied keys' IDs from being auto-allocated by Cloud
625
+ # Datastore.
626
+ #
627
+ # @overload reserve_ids(request, options = nil)
628
+ # Pass arguments to `reserve_ids` via a request object, either of type
629
+ # {::Google::Cloud::Datastore::V1::ReserveIdsRequest} or an equivalent Hash.
630
+ #
631
+ # @param request [::Google::Cloud::Datastore::V1::ReserveIdsRequest, ::Hash]
632
+ # A request object representing the call parameters. Required. To specify no
633
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
634
+ # @param options [::Gapic::CallOptions, ::Hash]
635
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
636
+ #
637
+ # @overload reserve_ids(project_id: nil, database_id: nil, keys: nil)
638
+ # Pass arguments to `reserve_ids` via keyword arguments. Note that at
639
+ # least one keyword argument is required. To specify no parameters, or to keep all
640
+ # the default parameter values, pass an empty Hash as a request object (see above).
641
+ #
642
+ # @param project_id [::String]
643
+ # Required. The ID of the project against which to make the request.
644
+ # @param database_id [::String]
645
+ # If not empty, the ID of the database against which to make the request.
646
+ # @param keys [::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>]
647
+ # Required. A list of keys with complete key paths whose numeric IDs should not be
648
+ # auto-allocated.
649
+ #
650
+ # @yield [response, operation] Access the result along with the RPC operation
651
+ # @yieldparam response [::Google::Cloud::Datastore::V1::ReserveIdsResponse]
652
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
653
+ #
654
+ # @return [::Google::Cloud::Datastore::V1::ReserveIdsResponse]
655
+ #
656
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
657
+ #
658
+ def reserve_ids request, options = nil
659
+ raise ::ArgumentError, "request must be provided" if request.nil?
660
+
661
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::ReserveIdsRequest
662
+
663
+ # Converts hash and nil to an options object
664
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
665
+
666
+ # Customize the options with defaults
667
+ metadata = @config.rpcs.reserve_ids.metadata.to_h
668
+
669
+ # Set x-goog-api-client and x-goog-user-project headers
670
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
671
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
672
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION
673
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
674
+
675
+ header_params = {
676
+ "project_id" => request.project_id
677
+ }
678
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
679
+ metadata[:"x-goog-request-params"] ||= request_params_header
680
+
681
+ options.apply_defaults timeout: @config.rpcs.reserve_ids.timeout,
682
+ metadata: metadata,
683
+ retry_policy: @config.rpcs.reserve_ids.retry_policy
684
+ options.apply_defaults metadata: @config.metadata,
685
+ retry_policy: @config.retry_policy
686
+
687
+ @datastore_stub.call_rpc :reserve_ids, request, options: options do |response, operation|
688
+ yield response, operation if block_given?
689
+ return response
690
+ end
691
+ rescue ::GRPC::BadStatus => e
692
+ raise ::Google::Cloud::Error.from_error(e)
693
+ end
694
+
695
+ ##
696
+ # Configuration class for the Datastore API.
697
+ #
698
+ # This class represents the configuration for Datastore,
699
+ # providing control over timeouts, retry behavior, logging, transport
700
+ # parameters, and other low-level controls. Certain parameters can also be
701
+ # applied individually to specific RPCs. See
702
+ # {::Google::Cloud::Datastore::V1::Datastore::Client::Configuration::Rpcs}
703
+ # for a list of RPCs that can be configured independently.
704
+ #
705
+ # Configuration can be applied globally to all clients, or to a single client
706
+ # on construction.
707
+ #
708
+ # # Examples
709
+ #
710
+ # To modify the global config, setting the timeout for lookup
711
+ # to 20 seconds, and all remaining timeouts to 10 seconds:
712
+ #
713
+ # ::Google::Cloud::Datastore::V1::Datastore::Client.configure do |config|
714
+ # config.timeout = 10.0
715
+ # config.rpcs.lookup.timeout = 20.0
716
+ # end
717
+ #
718
+ # To apply the above configuration only to a new client:
719
+ #
720
+ # client = ::Google::Cloud::Datastore::V1::Datastore::Client.new do |config|
721
+ # config.timeout = 10.0
722
+ # config.rpcs.lookup.timeout = 20.0
723
+ # end
724
+ #
725
+ # @!attribute [rw] endpoint
726
+ # The hostname or hostname:port of the service endpoint.
727
+ # Defaults to `"datastore.googleapis.com"`.
728
+ # @return [::String]
729
+ # @!attribute [rw] credentials
730
+ # Credentials to send with calls. You may provide any of the following types:
731
+ # * (`String`) The path to a service account key file in JSON format
732
+ # * (`Hash`) A service account key as a Hash
733
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
734
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
735
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
736
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
737
+ # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
738
+ # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
739
+ # * (`nil`) indicating no credentials
740
+ # @return [::Object]
741
+ # @!attribute [rw] scope
742
+ # The OAuth scopes
743
+ # @return [::Array<::String>]
744
+ # @!attribute [rw] lib_name
745
+ # The library name as recorded in instrumentation and logging
746
+ # @return [::String]
747
+ # @!attribute [rw] lib_version
748
+ # The library version as recorded in instrumentation and logging
749
+ # @return [::String]
750
+ # @!attribute [rw] channel_args
751
+ # Extra parameters passed to the gRPC channel. Note: this is ignored if a
752
+ # `GRPC::Core::Channel` object is provided as the credential.
753
+ # @return [::Hash]
754
+ # @!attribute [rw] interceptors
755
+ # An array of interceptors that are run before calls are executed.
756
+ # @return [::Array<::GRPC::ClientInterceptor>]
757
+ # @!attribute [rw] timeout
758
+ # The call timeout in seconds.
759
+ # @return [::Numeric]
760
+ # @!attribute [rw] metadata
761
+ # Additional gRPC headers to be sent with the call.
762
+ # @return [::Hash{::Symbol=>::String}]
763
+ # @!attribute [rw] retry_policy
764
+ # The retry policy. The value is a hash with the following keys:
765
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
766
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
767
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
768
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
769
+ # trigger a retry.
770
+ # @return [::Hash]
771
+ # @!attribute [rw] quota_project
772
+ # A separate project against which to charge quota.
773
+ # @return [::String]
774
+ #
775
+ class Configuration
776
+ extend ::Gapic::Config
777
+
778
+ config_attr :endpoint, "datastore.googleapis.com", ::String
779
+ config_attr :credentials, nil do |value|
780
+ allowed = [::String, ::Hash, ::Proc, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
781
+ allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
782
+ allowed.any? { |klass| klass === value }
783
+ end
784
+ config_attr :scope, nil, ::String, ::Array, nil
785
+ config_attr :lib_name, nil, ::String, nil
786
+ config_attr :lib_version, nil, ::String, nil
787
+ config_attr(:channel_args, { "grpc.service_config_disable_resolution"=>1 }, ::Hash, nil)
788
+ config_attr :interceptors, nil, ::Array, nil
789
+ config_attr :timeout, nil, ::Numeric, nil
790
+ config_attr :metadata, nil, ::Hash, nil
791
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
792
+ config_attr :quota_project, nil, ::String, nil
793
+
794
+ # @private
795
+ def initialize parent_config = nil
796
+ @parent_config = parent_config unless parent_config.nil?
797
+
798
+ yield self if block_given?
799
+ end
800
+
801
+ ##
802
+ # Configurations for individual RPCs
803
+ # @return [Rpcs]
804
+ #
805
+ def rpcs
806
+ @rpcs ||= begin
807
+ parent_rpcs = nil
808
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config&.respond_to?(:rpcs)
809
+ Rpcs.new parent_rpcs
810
+ end
811
+ end
812
+
813
+ ##
814
+ # Configuration RPC class for the Datastore API.
815
+ #
816
+ # Includes fields providing the configuration for each RPC in this service.
817
+ # Each configuration object is of type `Gapic::Config::Method` and includes
818
+ # the following configuration fields:
819
+ #
820
+ # * `timeout` (*type:* `Numeric`) - The call timeout in milliseconds
821
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
822
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
823
+ # include the following keys:
824
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
825
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
826
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
827
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
828
+ # trigger a retry.
829
+ #
830
+ class Rpcs
831
+ ##
832
+ # RPC-specific configuration for `lookup`
833
+ # @return [::Gapic::Config::Method]
834
+ #
835
+ attr_reader :lookup
836
+ ##
837
+ # RPC-specific configuration for `run_query`
838
+ # @return [::Gapic::Config::Method]
839
+ #
840
+ attr_reader :run_query
841
+ ##
842
+ # RPC-specific configuration for `begin_transaction`
843
+ # @return [::Gapic::Config::Method]
844
+ #
845
+ attr_reader :begin_transaction
846
+ ##
847
+ # RPC-specific configuration for `commit`
848
+ # @return [::Gapic::Config::Method]
849
+ #
850
+ attr_reader :commit
851
+ ##
852
+ # RPC-specific configuration for `rollback`
853
+ # @return [::Gapic::Config::Method]
854
+ #
855
+ attr_reader :rollback
856
+ ##
857
+ # RPC-specific configuration for `allocate_ids`
858
+ # @return [::Gapic::Config::Method]
859
+ #
860
+ attr_reader :allocate_ids
861
+ ##
862
+ # RPC-specific configuration for `reserve_ids`
863
+ # @return [::Gapic::Config::Method]
864
+ #
865
+ attr_reader :reserve_ids
866
+
867
+ # @private
868
+ def initialize parent_rpcs = nil
869
+ lookup_config = parent_rpcs&.lookup if parent_rpcs&.respond_to? :lookup
870
+ @lookup = ::Gapic::Config::Method.new lookup_config
871
+ run_query_config = parent_rpcs&.run_query if parent_rpcs&.respond_to? :run_query
872
+ @run_query = ::Gapic::Config::Method.new run_query_config
873
+ begin_transaction_config = parent_rpcs&.begin_transaction if parent_rpcs&.respond_to? :begin_transaction
874
+ @begin_transaction = ::Gapic::Config::Method.new begin_transaction_config
875
+ commit_config = parent_rpcs&.commit if parent_rpcs&.respond_to? :commit
876
+ @commit = ::Gapic::Config::Method.new commit_config
877
+ rollback_config = parent_rpcs&.rollback if parent_rpcs&.respond_to? :rollback
878
+ @rollback = ::Gapic::Config::Method.new rollback_config
879
+ allocate_ids_config = parent_rpcs&.allocate_ids if parent_rpcs&.respond_to? :allocate_ids
880
+ @allocate_ids = ::Gapic::Config::Method.new allocate_ids_config
881
+ reserve_ids_config = parent_rpcs&.reserve_ids if parent_rpcs&.respond_to? :reserve_ids
882
+ @reserve_ids = ::Gapic::Config::Method.new reserve_ids_config
883
+
884
+ yield self if block_given?
885
+ end
886
+ end
887
+ end
888
+ end
889
+ end
890
+ end
891
+ end
892
+ end
893
+ end