Class: Google::Cloud::Datastore::V1::Datastore::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/datastore/v1/datastore/client.rb

Overview

Client for the Datastore service.

Each RPC normalizes the partition IDs of the keys in its input entities, and always returns entities with keys with normalized partition IDs. This applies to all keys and entities, including those in values, except keys with both an empty path and an empty or unset partition ID. Normalization of input keys sets the project ID (if not already set) to the project ID from the request.

Defined Under Namespace

Classes: Configuration

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|config| ... } ⇒ Client

Create a new Datastore client object.

Examples:


# Create a client using the default configuration
client = ::Google::Cloud::Datastore::V1::Datastore::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::Datastore::V1::Datastore::Client.new do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the Datastore client.

Yield Parameters:



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 155

def initialize
  # These require statements are intentionally placed here to initialize
  # the gRPC module only when it's required.
  # See https://github.com/googleapis/toolkit/issues/446
  require "gapic/grpc"
  require "google/datastore/v1/datastore_services_pb"

  # Create the configuration object
  @config = Configuration.new Client.configure

  # Yield the configuration if needed
  yield @config if block_given?

  # Create credentials
  credentials = @config.credentials
  # Use self-signed JWT if the endpoint is unchanged from default,
  # but only if the default endpoint does not have a region prefix.
  enable_self_signed_jwt = @config.endpoint.nil? ||
                           (@config.endpoint == Configuration::DEFAULT_ENDPOINT &&
                           !@config.endpoint.split(".").first.include?("-"))
  credentials ||= Credentials.default scope: @config.scope,
                                      enable_self_signed_jwt: enable_self_signed_jwt
  if credentials.is_a?(::String) || credentials.is_a?(::Hash)
    credentials = Credentials.new credentials, scope: @config.scope
  end
  @quota_project_id = @config.quota_project
  @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id

  @datastore_stub = ::Gapic::ServiceStub.new(
    ::Google::Cloud::Datastore::V1::Datastore::Stub,
    credentials: credentials,
    endpoint: @config.endpoint,
    endpoint_template: DEFAULT_ENDPOINT_TEMPLATE,
    universe_domain: @config.universe_domain,
    channel_args: @config.channel_args,
    interceptors: @config.interceptors,
    channel_pool_config: @config.channel_pool,
    logger: @config.logger
  )

  @datastore_stub.stub_logger&.info do |entry|
    entry.set_system_name
    entry.set_service
    entry.message = "Created client for #{entry.service}"
    entry.set_credentials_fields credentials
    entry.set "customEndpoint", @config.endpoint if @config.endpoint
    entry.set "defaultTimeout", @config.timeout if @config.timeout
    entry.set "quotaProject", @quota_project_id if @quota_project_id
  end
end

Class Method Details

.configure {|config| ... } ⇒ Client::Configuration

Configure the Datastore Client class.

See Configuration for a description of the configuration fields.

Examples:


# Modify the configuration for all Datastore clients
::Google::Cloud::Datastore::V1::Datastore::Client.configure do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 65

def self.configure
  @configure ||= begin
    namespace = ["Google", "Cloud", "Datastore", "V1"]
    parent_config = while namespace.any?
                      parent_name = namespace.join "::"
                      parent_const = const_get parent_name
                      break parent_const.configure if parent_const.respond_to? :configure
                      namespace.pop
                    end
    default_config = Client::Configuration.new parent_config

    default_config.rpcs.lookup.timeout = 60.0
    default_config.rpcs.lookup.retry_policy = {
      initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4]
    }

    default_config.rpcs.run_query.timeout = 60.0
    default_config.rpcs.run_query.retry_policy = {
      initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4]
    }

    default_config.rpcs.run_aggregation_query.timeout = 60.0
    default_config.rpcs.run_aggregation_query.retry_policy = {
      initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4]
    }

    default_config.rpcs.begin_transaction.timeout = 60.0

    default_config.rpcs.commit.timeout = 60.0

    default_config.rpcs.rollback.timeout = 60.0

    default_config.rpcs.allocate_ids.timeout = 60.0

    default_config.rpcs.reserve_ids.timeout = 60.0
    default_config.rpcs.reserve_ids.retry_policy = {
      initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4]
    }

    default_config
  end
  yield @configure if block_given?
  @configure
end

Instance Method Details

#allocate_ids(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::AllocateIdsResponse #allocate_ids(project_id: nil, database_id: nil, keys: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::AllocateIdsResponse

Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.

Examples:

Basic example

require "google/cloud/datastore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Datastore::V1::Datastore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Datastore::V1::AllocateIdsRequest.new

# Call the allocate_ids method.
result = client.allocate_ids request

# The returned object is of type Google::Cloud::Datastore::V1::AllocateIdsResponse.
p result

Overloads:

  • #allocate_ids(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::AllocateIdsResponse

    Pass arguments to allocate_ids via a request object, either of type AllocateIdsRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Datastore::V1::AllocateIdsRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #allocate_ids(project_id: nil, database_id: nil, keys: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::AllocateIdsResponse

    Pass arguments to allocate_ids via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • project_id (::String) (defaults to: nil)

      Required. The ID of the project against which to make the request.

    • database_id (::String) (defaults to: nil)

      The ID of the database against which to make the request.

      '(default)' is not allowed; please use empty string '' to refer the default database.

    • keys (::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>) (defaults to: nil)

      Required. A list of keys with incomplete key paths for which to allocate IDs. No key may be reserved/read-only.

    • request_options (::Google::Cloud::Datastore::V1::RequestOptions, ::Hash) (defaults to: nil)

      Optional. The options for this request.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 930

def allocate_ids request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::AllocateIdsRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.allocate_ids..to_h

  # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Datastore::V1::VERSION
  [:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.project_id && !request.project_id.empty?
    header_params["project_id"] = request.project_id
  end
  if request.database_id && !request.database_id.empty?
    header_params["database_id"] = request.database_id
  end

  request_params_header = URI.encode_www_form header_params
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.allocate_ids.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.allocate_ids.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @datastore_stub.call_rpc :allocate_ids, request, options: options do |response, operation|
    yield response, operation if block_given?
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#begin_transaction(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::BeginTransactionResponse #begin_transaction(project_id: nil, database_id: nil, transaction_options: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::BeginTransactionResponse

Begins a new transaction.

Examples:

Basic example

require "google/cloud/datastore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Datastore::V1::Datastore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Datastore::V1::BeginTransactionRequest.new

# Call the begin_transaction method.
result = client.begin_transaction request

# The returned object is of type Google::Cloud::Datastore::V1::BeginTransactionResponse.
p result

Overloads:

  • #begin_transaction(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::BeginTransactionResponse

    Pass arguments to begin_transaction via a request object, either of type BeginTransactionRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Datastore::V1::BeginTransactionRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #begin_transaction(project_id: nil, database_id: nil, transaction_options: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::BeginTransactionResponse

    Pass arguments to begin_transaction via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • project_id (::String) (defaults to: nil)

      Required. The ID of the project against which to make the request.

    • database_id (::String) (defaults to: nil)

      The ID of the database against which to make the request.

      '(default)' is not allowed; please use empty string '' to refer the default database.

    • transaction_options (::Google::Cloud::Datastore::V1::TransactionOptions, ::Hash) (defaults to: nil)

      Options for a new transaction.

    • request_options (::Google::Cloud::Datastore::V1::RequestOptions, ::Hash) (defaults to: nil)

      Optional. The options for this request.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 608

def begin_transaction request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::BeginTransactionRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.begin_transaction..to_h

  # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Datastore::V1::VERSION
  [:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.project_id && !request.project_id.empty?
    header_params["project_id"] = request.project_id
  end
  if request.database_id && !request.database_id.empty?
    header_params["database_id"] = request.database_id
  end

  request_params_header = URI.encode_www_form header_params
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.begin_transaction.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.begin_transaction.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @datastore_stub.call_rpc :begin_transaction, request, options: options do |response, operation|
    yield response, operation if block_given?
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#commit(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::CommitResponse #commit(project_id: nil, database_id: nil, mode: nil, transaction: nil, single_use_transaction: nil, mutations: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::CommitResponse

Commits a transaction, optionally creating, deleting or modifying some entities.

Examples:

Basic example

require "google/cloud/datastore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Datastore::V1::Datastore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Datastore::V1::CommitRequest.new

# Call the commit method.
result = client.commit request

# The returned object is of type Google::Cloud::Datastore::V1::CommitResponse.
p result

Overloads:

  • #commit(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::CommitResponse

    Pass arguments to commit via a request object, either of type CommitRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Datastore::V1::CommitRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #commit(project_id: nil, database_id: nil, mode: nil, transaction: nil, single_use_transaction: nil, mutations: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::CommitResponse

    Pass arguments to commit via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • project_id (::String) (defaults to: nil)

      Required. The ID of the project against which to make the request.

    • database_id (::String) (defaults to: nil)

      The ID of the database against which to make the request.

      '(default)' is not allowed; please use empty string '' to refer the default database.

    • mode (::Google::Cloud::Datastore::V1::CommitRequest::Mode) (defaults to: nil)

      The type of commit to perform. Defaults to TRANSACTIONAL.

    • transaction (::String) (defaults to: nil)

      The identifier of the transaction associated with the commit. A transaction identifier is returned by a call to Datastore.BeginTransaction.

      Note: The following parameters are mutually exclusive: transaction, single_use_transaction. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.

    • single_use_transaction (::Google::Cloud::Datastore::V1::TransactionOptions, ::Hash) (defaults to: nil)

      Options for beginning a new transaction for this request. The transaction is committed when the request completes. If specified, TransactionOptions.mode must be TransactionOptions.ReadWrite.

      Note: The following parameters are mutually exclusive: single_use_transaction, transaction. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.

    • mutations (::Array<::Google::Cloud::Datastore::V1::Mutation, ::Hash>) (defaults to: nil)

      The mutations to perform.

      When mode is TRANSACTIONAL, mutations affecting a single entity are applied in order. The following sequences of mutations affecting a single entity are not permitted in a single Commit request:

      • insert followed by insert
      • update followed by insert
      • upsert followed by insert
      • delete followed by update

      When mode is NON_TRANSACTIONAL, no two mutations may affect a single entity.

    • request_options (::Google::Cloud::Datastore::V1::RequestOptions, ::Hash) (defaults to: nil)

      Optional. The options for this request.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 733

def commit request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::CommitRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.commit..to_h

  # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Datastore::V1::VERSION
  [:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.project_id && !request.project_id.empty?
    header_params["project_id"] = request.project_id
  end
  if request.database_id && !request.database_id.empty?
    header_params["database_id"] = request.database_id
  end

  request_params_header = URI.encode_www_form header_params
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.commit.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.commit.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @datastore_stub.call_rpc :commit, request, options: options do |response, operation|
    yield response, operation if block_given?
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#configure {|config| ... } ⇒ Client::Configuration

Configure the Datastore Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on configure.

See Configuration for a description of the configuration fields.

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



125
126
127
128
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 125

def configure
  yield @config if block_given?
  @config
end

#loggerLogger

The logger used for request/response debug logging.

Returns:

  • (Logger)


211
212
213
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 211

def logger
  @datastore_stub.logger
end

#lookup(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::LookupResponse #lookup(project_id: nil, database_id: nil, read_options: nil, keys: nil, property_mask: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::LookupResponse

Looks up entities by key.

Examples:

Basic example

require "google/cloud/datastore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Datastore::V1::Datastore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Datastore::V1::LookupRequest.new

# Call the lookup method.
result = client.lookup request

# The returned object is of type Google::Cloud::Datastore::V1::LookupResponse.
p result

Overloads:

  • #lookup(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::LookupResponse

    Pass arguments to lookup via a request object, either of type LookupRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Datastore::V1::LookupRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #lookup(project_id: nil, database_id: nil, read_options: nil, keys: nil, property_mask: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::LookupResponse

    Pass arguments to lookup via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • project_id (::String) (defaults to: nil)

      Required. The ID of the project against which to make the request.

    • database_id (::String) (defaults to: nil)

      The ID of the database against which to make the request.

      '(default)' is not allowed; please use empty string '' to refer the default database.

    • read_options (::Google::Cloud::Datastore::V1::ReadOptions, ::Hash) (defaults to: nil)

      The options for this lookup request.

    • keys (::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>) (defaults to: nil)

      Required. Keys of entities to look up.

    • property_mask (::Google::Cloud::Datastore::V1::PropertyMask, ::Hash) (defaults to: nil)

      The properties to return. Defaults to returning all properties.

      If this field is set and an entity has a property not referenced in the mask, it will be absent from [LookupResponse.found.entity.properties][].

      The entity's key is always returned.

    • request_options (::Google::Cloud::Datastore::V1::RequestOptions, ::Hash) (defaults to: nil)

      Optional. The options for this request.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 279

def lookup request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::LookupRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.lookup..to_h

  # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Datastore::V1::VERSION
  [:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.project_id && !request.project_id.empty?
    header_params["project_id"] = request.project_id
  end
  if request.database_id && !request.database_id.empty?
    header_params["database_id"] = request.database_id
  end

  request_params_header = URI.encode_www_form header_params
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.lookup.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.lookup.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @datastore_stub.call_rpc :lookup, request, options: options do |response, operation|
    yield response, operation if block_given?
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#reserve_ids(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::ReserveIdsResponse #reserve_ids(project_id: nil, database_id: nil, keys: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::ReserveIdsResponse

Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.

Examples:

Basic example

require "google/cloud/datastore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Datastore::V1::Datastore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Datastore::V1::ReserveIdsRequest.new

# Call the reserve_ids method.
result = client.reserve_ids request

# The returned object is of type Google::Cloud::Datastore::V1::ReserveIdsResponse.
p result

Overloads:

  • #reserve_ids(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::ReserveIdsResponse

    Pass arguments to reserve_ids via a request object, either of type ReserveIdsRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Datastore::V1::ReserveIdsRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #reserve_ids(project_id: nil, database_id: nil, keys: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::ReserveIdsResponse

    Pass arguments to reserve_ids via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • project_id (::String) (defaults to: nil)

      Required. The ID of the project against which to make the request.

    • database_id (::String) (defaults to: nil)

      The ID of the database against which to make the request.

      '(default)' is not allowed; please use empty string '' to refer the default database.

    • keys (::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>) (defaults to: nil)

      Required. A list of keys with complete key paths whose numeric IDs should not be auto-allocated.

    • request_options (::Google::Cloud::Datastore::V1::RequestOptions, ::Hash) (defaults to: nil)

      Optional. The options for this request.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 1029

def reserve_ids request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::ReserveIdsRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.reserve_ids..to_h

  # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Datastore::V1::VERSION
  [:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.project_id && !request.project_id.empty?
    header_params["project_id"] = request.project_id
  end
  if request.database_id && !request.database_id.empty?
    header_params["database_id"] = request.database_id
  end

  request_params_header = URI.encode_www_form header_params
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.reserve_ids.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.reserve_ids.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @datastore_stub.call_rpc :reserve_ids, request, options: options do |response, operation|
    yield response, operation if block_given?
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#rollback(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::RollbackResponse #rollback(project_id: nil, database_id: nil, transaction: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::RollbackResponse

Rolls back a transaction.

Examples:

Basic example

require "google/cloud/datastore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Datastore::V1::Datastore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Datastore::V1::RollbackRequest.new

# Call the rollback method.
result = client.rollback request

# The returned object is of type Google::Cloud::Datastore::V1::RollbackResponse.
p result

Overloads:

  • #rollback(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::RollbackResponse

    Pass arguments to rollback via a request object, either of type RollbackRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Datastore::V1::RollbackRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #rollback(project_id: nil, database_id: nil, transaction: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::RollbackResponse

    Pass arguments to rollback via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • project_id (::String) (defaults to: nil)

      Required. The ID of the project against which to make the request.

    • database_id (::String) (defaults to: nil)

      The ID of the database against which to make the request.

      '(default)' is not allowed; please use empty string '' to refer the default database.

    • transaction (::String) (defaults to: nil)

      Required. The transaction identifier, returned by a call to Datastore.BeginTransaction.

    • request_options (::Google::Cloud::Datastore::V1::RequestOptions, ::Hash) (defaults to: nil)

      Optional. The options for this request.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 831

def rollback request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::RollbackRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.rollback..to_h

  # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Datastore::V1::VERSION
  [:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.project_id && !request.project_id.empty?
    header_params["project_id"] = request.project_id
  end
  if request.database_id && !request.database_id.empty?
    header_params["database_id"] = request.database_id
  end

  request_params_header = URI.encode_www_form header_params
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.rollback.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.rollback.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @datastore_stub.call_rpc :rollback, request, options: options do |response, operation|
    yield response, operation if block_given?
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#run_aggregation_query(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::RunAggregationQueryResponse #run_aggregation_query(project_id: nil, database_id: nil, partition_id: nil, read_options: nil, aggregation_query: nil, gql_query: nil, explain_options: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::RunAggregationQueryResponse

Runs an aggregation query.

Examples:

Basic example

require "google/cloud/datastore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Datastore::V1::Datastore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Datastore::V1::RunAggregationQueryRequest.new

# Call the run_aggregation_query method.
result = client.run_aggregation_query request

# The returned object is of type Google::Cloud::Datastore::V1::RunAggregationQueryResponse.
p result

Overloads:

  • #run_aggregation_query(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::RunAggregationQueryResponse

    Pass arguments to run_aggregation_query via a request object, either of type RunAggregationQueryRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Datastore::V1::RunAggregationQueryRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #run_aggregation_query(project_id: nil, database_id: nil, partition_id: nil, read_options: nil, aggregation_query: nil, gql_query: nil, explain_options: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::RunAggregationQueryResponse

    Pass arguments to run_aggregation_query via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • project_id (::String) (defaults to: nil)

      Required. The ID of the project against which to make the request.

    • database_id (::String) (defaults to: nil)

      The ID of the database against which to make the request.

      '(default)' is not allowed; please use empty string '' to refer the default database.

    • partition_id (::Google::Cloud::Datastore::V1::PartitionId, ::Hash) (defaults to: nil)

      Entities are partitioned into subsets, identified by a partition ID. Queries are scoped to a single partition. This partition ID is normalized with the standard default context partition ID.

    • read_options (::Google::Cloud::Datastore::V1::ReadOptions, ::Hash) (defaults to: nil)

      The options for this query.

    • aggregation_query (::Google::Cloud::Datastore::V1::AggregationQuery, ::Hash) (defaults to: nil)

      The query to run.

      Note: The following parameters are mutually exclusive: aggregation_query, gql_query. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.

    • gql_query (::Google::Cloud::Datastore::V1::GqlQuery, ::Hash) (defaults to: nil)

      The GQL query to run. This query must be an aggregation query.

      Note: The following parameters are mutually exclusive: gql_query, aggregation_query. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.

    • explain_options (::Google::Cloud::Datastore::V1::ExplainOptions, ::Hash) (defaults to: nil)

      Optional. Explain options for the query. If set, additional query statistics will be returned. If not, only query results will be returned.

    • request_options (::Google::Cloud::Datastore::V1::RequestOptions, ::Hash) (defaults to: nil)

      Optional. The options for this request.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 511

def run_aggregation_query request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::RunAggregationQueryRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.run_aggregation_query..to_h

  # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Datastore::V1::VERSION
  [:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.project_id && !request.project_id.empty?
    header_params["project_id"] = request.project_id
  end
  if request.database_id && !request.database_id.empty?
    header_params["database_id"] = request.database_id
  end

  request_params_header = URI.encode_www_form header_params
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.run_aggregation_query.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.run_aggregation_query.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @datastore_stub.call_rpc :run_aggregation_query, request, options: options do |response, operation|
    yield response, operation if block_given?
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#run_query(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::RunQueryResponse #run_query(project_id: nil, database_id: nil, partition_id: nil, read_options: nil, query: nil, gql_query: nil, property_mask: nil, explain_options: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::RunQueryResponse

Queries for entities.

Examples:

Basic example

require "google/cloud/datastore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Datastore::V1::Datastore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Datastore::V1::RunQueryRequest.new

# Call the run_query method.
result = client.run_query request

# The returned object is of type Google::Cloud::Datastore::V1::RunQueryResponse.
p result

Overloads:

  • #run_query(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::RunQueryResponse

    Pass arguments to run_query via a request object, either of type RunQueryRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Datastore::V1::RunQueryRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #run_query(project_id: nil, database_id: nil, partition_id: nil, read_options: nil, query: nil, gql_query: nil, property_mask: nil, explain_options: nil, request_options: nil) ⇒ ::Google::Cloud::Datastore::V1::RunQueryResponse

    Pass arguments to run_query via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • project_id (::String) (defaults to: nil)

      Required. The ID of the project against which to make the request.

    • database_id (::String) (defaults to: nil)

      The ID of the database against which to make the request.

      '(default)' is not allowed; please use empty string '' to refer the default database.

    • partition_id (::Google::Cloud::Datastore::V1::PartitionId, ::Hash) (defaults to: nil)

      Entities are partitioned into subsets, identified by a partition ID. Queries are scoped to a single partition. This partition ID is normalized with the standard default context partition ID.

    • read_options (::Google::Cloud::Datastore::V1::ReadOptions, ::Hash) (defaults to: nil)

      The options for this query.

    • query (::Google::Cloud::Datastore::V1::Query, ::Hash) (defaults to: nil)

      The query to run.

      Note: The following parameters are mutually exclusive: query, gql_query. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.

    • gql_query (::Google::Cloud::Datastore::V1::GqlQuery, ::Hash) (defaults to: nil)

      The GQL query to run. This query must be a non-aggregation query.

      Note: The following parameters are mutually exclusive: gql_query, query. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.

    • property_mask (::Google::Cloud::Datastore::V1::PropertyMask, ::Hash) (defaults to: nil)

      The properties to return. This field must not be set for a projection query.

      See LookupRequest.property_mask.

    • explain_options (::Google::Cloud::Datastore::V1::ExplainOptions, ::Hash) (defaults to: nil)

      Optional. Explain options for the query. If set, additional query statistics will be returned. If not, only query results will be returned.

    • request_options (::Google::Cloud::Datastore::V1::RequestOptions, ::Hash) (defaults to: nil)

      Optional. The options for this request.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 398

def run_query request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::RunQueryRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.run_query..to_h

  # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Datastore::V1::VERSION
  [:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.project_id && !request.project_id.empty?
    header_params["project_id"] = request.project_id
  end
  if request.database_id && !request.database_id.empty?
    header_params["database_id"] = request.database_id
  end

  request_params_header = URI.encode_www_form header_params
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.run_query.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.run_query.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @datastore_stub.call_rpc :run_query, request, options: options do |response, operation|
    yield response, operation if block_given?
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#universe_domainString

The effective universe domain

Returns:

  • (String)


135
136
137
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 135

def universe_domain
  @datastore_stub.universe_domain
end