class Google::Cloud::Datastore::V1::Datastore::Client

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.

Attributes

datastore_stub[R]

@private

Public Class Methods

configure() { |configure| ... } click to toggle source

Configure the Datastore Client class.

See {::Google::Cloud::Datastore::V1::Datastore::Client::Configuration} for a description of the configuration fields.

@example

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

@yield [config] Configure the Client client. @yieldparam config [Client::Configuration]

@return [Client::Configuration]

# File lib/google/cloud/datastore/v1/datastore/client.rb, line 59
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.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
new() { |config| ... } click to toggle source

Create a new Datastore client object.

@example

# 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

@yield [config] Configure the Datastore client. @yieldparam config [Client::Configuration]

# File lib/google/cloud/datastore/v1/datastore/client.rb, line 135
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 == Client.configure.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,
    channel_args: @config.channel_args,
    interceptors: @config.interceptors
  )
end

Public Instance Methods

allocate_ids(request, options = nil) { |response, operation| ... } click to toggle source

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

@overload allocate_ids(request, options = nil)

Pass arguments to `allocate_ids` via a request object, either of type
{::Google::Cloud::Datastore::V1::AllocateIdsRequest} or an equivalent Hash.

@param 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.
@param options [::Gapic::CallOptions, ::Hash]
  Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

@overload allocate_ids(project_id: nil, keys: nil)

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).

@param project_id [::String]
  Required. The ID of the project against which to make the request.
@param keys [::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>]
  Required. A list of keys with incomplete key paths for which to allocate IDs.
  No key may be reserved/read-only.

@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Datastore::V1::AllocateIdsResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]

@return [::Google::Cloud::Datastore::V1::AllocateIdsResponse]

@raise [::Google::Cloud::Error] if the RPC is aborted.

# File lib/google/cloud/datastore/v1/datastore/client.rb, line 587
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
  metadata = @config.rpcs.allocate_ids.metadata.to_h

  # Set x-goog-api-client and x-goog-user-project headers
  metadata[:"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
  metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "project_id" => request.project_id
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  metadata[:"x-goog-request-params"] ||= request_params_header

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

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

  @datastore_stub.call_rpc :allocate_ids, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end
begin_transaction(request, options = nil) { |response, operation| ... } click to toggle source

Begins a new transaction.

@overload begin_transaction(request, options = nil)

Pass arguments to `begin_transaction` via a request object, either of type
{::Google::Cloud::Datastore::V1::BeginTransactionRequest} or an equivalent Hash.

@param 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.
@param options [::Gapic::CallOptions, ::Hash]
  Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

@overload begin_transaction(project_id: nil, transaction_options: nil)

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).

@param project_id [::String]
  Required. The ID of the project against which to make the request.
@param transaction_options [::Google::Cloud::Datastore::V1::TransactionOptions, ::Hash]
  Options for a new transaction.

@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Datastore::V1::BeginTransactionResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]

@return [::Google::Cloud::Datastore::V1::BeginTransactionResponse]

@raise [::Google::Cloud::Error] if the RPC is aborted.

# File lib/google/cloud/datastore/v1/datastore/client.rb, line 355
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
  metadata = @config.rpcs.begin_transaction.metadata.to_h

  # Set x-goog-api-client and x-goog-user-project headers
  metadata[:"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
  metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "project_id" => request.project_id
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  metadata[:"x-goog-request-params"] ||= request_params_header

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

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

  @datastore_stub.call_rpc :begin_transaction, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end
commit(request, options = nil) { |response, operation| ... } click to toggle source

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

@overload commit(request, options = nil)

Pass arguments to `commit` via a request object, either of type
{::Google::Cloud::Datastore::V1::CommitRequest} or an equivalent Hash.

@param 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.
@param options [::Gapic::CallOptions, ::Hash]
  Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

@overload commit(project_id: nil, mode: nil, transaction: nil, mutations: nil)

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).

@param project_id [::String]
  Required. The ID of the project against which to make the request.
@param mode [::Google::Cloud::Datastore::V1::CommitRequest::Mode]
  The type of commit to perform. Defaults to `TRANSACTIONAL`.
@param transaction [::String]
  The identifier of the transaction associated with the commit. A
  transaction identifier is returned by a call to
  {::Google::Cloud::Datastore::V1::Datastore::Client#begin_transaction Datastore.BeginTransaction}.
@param mutations [::Array<::Google::Cloud::Datastore::V1::Mutation, ::Hash>]
  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.

@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Datastore::V1::CommitResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]

@return [::Google::Cloud::Datastore::V1::CommitResponse]

@raise [::Google::Cloud::Error] if the RPC is aborted.

# File lib/google/cloud/datastore/v1/datastore/client.rb, line 444
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
  metadata = @config.rpcs.commit.metadata.to_h

  # Set x-goog-api-client and x-goog-user-project headers
  metadata[:"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
  metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "project_id" => request.project_id
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  metadata[:"x-goog-request-params"] ||= request_params_header

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

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

  @datastore_stub.call_rpc :commit, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end
configure() { |config| ... } click to toggle source

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 {Client.configure}.

See {::Google::Cloud::Datastore::V1::Datastore::Client::Configuration} for a description of the configuration fields.

@yield [config] Configure the Client client. @yieldparam config [Client::Configuration]

@return [Client::Configuration]

# File lib/google/cloud/datastore/v1/datastore/client.rb, line 114
def configure
  yield @config if block_given?
  @config
end
lookup(request, options = nil) { |response, operation| ... } click to toggle source

Looks up entities by key.

@overload lookup(request, options = nil)

Pass arguments to `lookup` via a request object, either of type
{::Google::Cloud::Datastore::V1::LookupRequest} or an equivalent Hash.

@param 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.
@param options [::Gapic::CallOptions, ::Hash]
  Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

@overload lookup(project_id: nil, read_options: nil, keys: nil)

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).

@param project_id [::String]
  Required. The ID of the project against which to make the request.
@param read_options [::Google::Cloud::Datastore::V1::ReadOptions, ::Hash]
  The options for this lookup request.
@param keys [::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>]
  Required. Keys of entities to look up.

@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Datastore::V1::LookupResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]

@return [::Google::Cloud::Datastore::V1::LookupResponse]

@raise [::Google::Cloud::Error] if the RPC is aborted.

# File lib/google/cloud/datastore/v1/datastore/client.rb, line 206
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
  metadata = @config.rpcs.lookup.metadata.to_h

  # Set x-goog-api-client and x-goog-user-project headers
  metadata[:"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
  metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "project_id" => request.project_id
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  metadata[:"x-goog-request-params"] ||= request_params_header

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

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

  @datastore_stub.call_rpc :lookup, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end
reserve_ids(request, options = nil) { |response, operation| ... } click to toggle source

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

@overload reserve_ids(request, options = nil)

Pass arguments to `reserve_ids` via a request object, either of type
{::Google::Cloud::Datastore::V1::ReserveIdsRequest} or an equivalent Hash.

@param 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.
@param options [::Gapic::CallOptions, ::Hash]
  Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

@overload reserve_ids(project_id: nil, database_id: nil, keys: nil)

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).

@param project_id [::String]
  Required. The ID of the project against which to make the request.
@param database_id [::String]
  If not empty, the ID of the database against which to make the request.
@param keys [::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>]
  Required. A list of keys with complete key paths whose numeric IDs should not be
  auto-allocated.

@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Datastore::V1::ReserveIdsResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]

@return [::Google::Cloud::Datastore::V1::ReserveIdsResponse]

@raise [::Google::Cloud::Error] if the RPC is aborted.

# File lib/google/cloud/datastore/v1/datastore/client.rb, line 661
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
  metadata = @config.rpcs.reserve_ids.metadata.to_h

  # Set x-goog-api-client and x-goog-user-project headers
  metadata[:"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
  metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "project_id" => request.project_id
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  metadata[:"x-goog-request-params"] ||= request_params_header

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

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

  @datastore_stub.call_rpc :reserve_ids, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end
rollback(request, options = nil) { |response, operation| ... } click to toggle source

Rolls back a transaction.

@overload rollback(request, options = nil)

Pass arguments to `rollback` via a request object, either of type
{::Google::Cloud::Datastore::V1::RollbackRequest} or an equivalent Hash.

@param 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.
@param options [::Gapic::CallOptions, ::Hash]
  Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

@overload rollback(project_id: nil, transaction: nil)

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).

@param project_id [::String]
  Required. The ID of the project against which to make the request.
@param transaction [::String]
  Required. The transaction identifier, returned by a call to
  {::Google::Cloud::Datastore::V1::Datastore::Client#begin_transaction Datastore.BeginTransaction}.

@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Datastore::V1::RollbackResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]

@return [::Google::Cloud::Datastore::V1::RollbackResponse]

@raise [::Google::Cloud::Error] if the RPC is aborted.

# File lib/google/cloud/datastore/v1/datastore/client.rb, line 515
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
  metadata = @config.rpcs.rollback.metadata.to_h

  # Set x-goog-api-client and x-goog-user-project headers
  metadata[:"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
  metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "project_id" => request.project_id
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  metadata[:"x-goog-request-params"] ||= request_params_header

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

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

  @datastore_stub.call_rpc :rollback, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end
run_query(request, options = nil) { |response, operation| ... } click to toggle source

Queries for entities.

@overload run_query(request, options = nil)

Pass arguments to `run_query` via a request object, either of type
{::Google::Cloud::Datastore::V1::RunQueryRequest} or an equivalent Hash.

@param 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.
@param options [::Gapic::CallOptions, ::Hash]
  Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

@overload run_query(project_id: nil, partition_id: nil, read_options: nil, query: nil, gql_query: nil)

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).

@param project_id [::String]
  Required. The ID of the project against which to make the request.
@param partition_id [::Google::Cloud::Datastore::V1::PartitionId, ::Hash]
  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.
@param read_options [::Google::Cloud::Datastore::V1::ReadOptions, ::Hash]
  The options for this query.
@param query [::Google::Cloud::Datastore::V1::Query, ::Hash]
  The query to run.
@param gql_query [::Google::Cloud::Datastore::V1::GqlQuery, ::Hash]
  The GQL query to run.

@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Datastore::V1::RunQueryResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]

@return [::Google::Cloud::Datastore::V1::RunQueryResponse]

@raise [::Google::Cloud::Error] if the RPC is aborted.

# File lib/google/cloud/datastore/v1/datastore/client.rb, line 285
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
  metadata = @config.rpcs.run_query.metadata.to_h

  # Set x-goog-api-client and x-goog-user-project headers
  metadata[:"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
  metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "project_id" => request.project_id
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  metadata[:"x-goog-request-params"] ||= request_params_header

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

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

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