Class: Google::Cloud::Firestore::V1::Firestore::Client

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

Overview

Client for the Firestore service.

The Cloud Firestore service.

Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL document database that simplifies storing, syncing, and querying data for your mobile, web, and IoT apps at global scale. Its client libraries provide live synchronization and offline support, while its security features and integrations with Firebase and Google Cloud Platform accelerate building truly serverless apps.

Defined Under Namespace

Classes: Configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Create a new Firestore client object.

Examples:


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

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

Yields:

  • (config)

    Configure the Firestore client.

Yield Parameters:



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 204

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/firestore/v1/firestore_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

  @firestore_stub = ::Gapic::ServiceStub.new(
    ::Google::Cloud::Firestore::V1::Firestore::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
  )

  @location_client = Google::Cloud::Location::Locations::Client.new do |config|
    config.credentials = credentials
    config.quota_project = @quota_project_id
    config.endpoint = @firestore_stub.endpoint
    config.universe_domain = @firestore_stub.universe_domain
  end
end

Instance Attribute Details

#location_clientGoogle::Cloud::Location::Locations::Client (readonly)

Get the associated client for mix-in of the Locations.

Returns:

  • (Google::Cloud::Location::Locations::Client)


256
257
258
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 256

def location_client
  @location_client
end

Class Method Details

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

Configure the Firestore Client class.

See Configuration for a description of the configuration fields.

Examples:


# Modify the configuration for all Firestore clients
::Google::Cloud::Firestore::V1::Firestore::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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 65

def self.configure
  @configure ||= begin
    namespace = ["Google", "Cloud", "Firestore", "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.get_document.timeout = 60.0
    default_config.rpcs.get_document.retry_policy = {
      initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [8, 14, 13, 4]
    }

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

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

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

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

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

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

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

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

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

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

    default_config.rpcs.write.timeout = 86_400.0

    default_config.rpcs.listen.timeout = 86_400.0
    default_config.rpcs.listen.retry_policy = {
      initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [8, 14, 13, 4]
    }

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

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

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

    default_config
  end
  yield @configure if block_given?
  @configure
end

Instance Method Details

#batch_get_documents(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::BatchGetDocumentsResponse> #batch_get_documents(database: nil, documents: nil, mask: nil, transaction: nil, new_transaction: nil, read_time: nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::BatchGetDocumentsResponse>

Gets multiple documents.

Documents returned by this method are not guaranteed to be returned in the same order that they were requested.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

# Call the batch_get_documents method to start streaming.
output = client.batch_get_documents request

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::Firestore::V1::BatchGetDocumentsResponse
output.each do |current_response|
  p current_response
end

Overloads:

  • #batch_get_documents(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::BatchGetDocumentsResponse>

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

    Parameters:

    • request (::Google::Cloud::Firestore::V1::BatchGetDocumentsRequest, ::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.

  • #batch_get_documents(database: nil, documents: nil, mask: nil, transaction: nil, new_transaction: nil, read_time: nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::BatchGetDocumentsResponse>

    Pass arguments to batch_get_documents 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:

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

      Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

    • documents (::Array<::String>) (defaults to: nil)

      The names of the documents to retrieve. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}. The request will fail if any of the document is not a child resource of the given database. Duplicate names will be elided.

    • mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) (defaults to: nil)

      The fields to return. If not set, returns all fields.

      If a document has a field that is not present in this mask, that field will not be returned in the response.

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

      Reads documents in a transaction.

    • new_transaction (::Google::Cloud::Firestore::V1::TransactionOptions, ::Hash) (defaults to: nil)

      Starts a new transaction and reads the documents. Defaults to a read-only transaction. The new transaction ID will be returned as the first response in the stream.

    • read_time (::Google::Protobuf::Timestamp, ::Hash) (defaults to: nil)

      Reads documents as they were at the given time.

      This must be a microsecond precision timestamp within the past one hour, or if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp within the past 7 days.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 771

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::V1::BatchGetDocumentsRequest

  # 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.batch_get_documents..to_h

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

  header_params = {}
  if request.database
    header_params["database"] = request.database
  end

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

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

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

  @firestore_stub.call_rpc :batch_get_documents, 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

#batch_write(request, options = nil) ⇒ ::Google::Cloud::Firestore::V1::BatchWriteResponse #batch_write(database: nil, writes: nil, labels: nil) ⇒ ::Google::Cloud::Firestore::V1::BatchWriteResponse

Applies a batch of write operations.

The BatchWrite method does not apply the write operations atomically and can apply them out of order. Method does not allow more than one write per document. Each write succeeds or fails independently. See the BatchWriteResponse for the success status of each write.

If you require an atomically applied set of writes, use Commit instead.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

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

# The returned object is of type Google::Cloud::Firestore::V1::BatchWriteResponse.
p result

Overloads:

  • #batch_write(request, options = nil) ⇒ ::Google::Cloud::Firestore::V1::BatchWriteResponse

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

    Parameters:

    • request (::Google::Cloud::Firestore::V1::BatchWriteRequest, ::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.

  • #batch_write(database: nil, writes: nil, labels: nil) ⇒ ::Google::Cloud::Firestore::V1::BatchWriteResponse

    Pass arguments to batch_write 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:

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

      Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

    • writes (::Array<::Google::Cloud::Firestore::V1::Write, ::Hash>) (defaults to: nil)

      The writes to apply.

      Method does not apply writes atomically and does not guarantee ordering. Each write succeeds or fails independently. You cannot write to the same document more than once per request.

    • labels (::Hash{::String => ::String}) (defaults to: nil)

      Labels associated with this batch write.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 1775

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::V1::BatchWriteRequest

  # 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.batch_write..to_h

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

  header_params = {}
  if request.database
    header_params["database"] = request.database
  end

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

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

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

  @firestore_stub.call_rpc :batch_write, 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) ⇒ ::Google::Cloud::Firestore::V1::BeginTransactionResponse #begin_transaction(database: nil, options: nil) ⇒ ::Google::Cloud::Firestore::V1::BeginTransactionResponse

Starts a new transaction.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

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

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

Overloads:

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

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

    Parameters:

    • request (::Google::Cloud::Firestore::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(database: nil, options: nil) ⇒ ::Google::Cloud::Firestore::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:

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

      Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

    • options (::Google::Cloud::Firestore::V1::TransactionOptions, ::Hash) (defaults to: nil)

      The options for the transaction. Defaults to a read-write transaction.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 860

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::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 and x-goog-user-project 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::Firestore::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.database
    header_params["database"] = request.database
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"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

  @firestore_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) ⇒ ::Google::Cloud::Firestore::V1::CommitResponse #commit(database: nil, writes: nil, transaction: nil) ⇒ ::Google::Cloud::Firestore::V1::CommitResponse

Commits a transaction, while optionally updating documents.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

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

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

Overloads:

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

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

    Parameters:

    • request (::Google::Cloud::Firestore::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(database: nil, writes: nil, transaction: nil) ⇒ ::Google::Cloud::Firestore::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:

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

      Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

    • writes (::Array<::Google::Cloud::Firestore::V1::Write, ::Hash>) (defaults to: nil)

      The writes to apply.

      Always executed atomically and in order.

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

      If set, applies all writes in this transaction, and commits it.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 952

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::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 and x-goog-user-project 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::Firestore::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.database
    header_params["database"] = request.database
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"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

  @firestore_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| ... } ⇒ Client::Configuration

Configure the Firestore 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:



174
175
176
177
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 174

def configure
  yield @config if block_given?
  @config
end

#create_document(request, options = nil) ⇒ ::Google::Cloud::Firestore::V1::Document #create_document(parent: nil, collection_id: nil, document_id: nil, document: nil, mask: nil) ⇒ ::Google::Cloud::Firestore::V1::Document

Creates a new document.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

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

# The returned object is of type Google::Cloud::Firestore::V1::Document.
p result

Overloads:

  • #create_document(request, options = nil) ⇒ ::Google::Cloud::Firestore::V1::Document

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

    Parameters:

    • request (::Google::Cloud::Firestore::V1::CreateDocumentRequest, ::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.

  • #create_document(parent: nil, collection_id: nil, document_id: nil, document: nil, mask: nil) ⇒ ::Google::Cloud::Firestore::V1::Document

    Pass arguments to create_document 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:

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

      Required. The parent resource. For example: projects/{project_id}/databases/{database_id}/documents or projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}

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

      Required. The collection ID, relative to parent, to list. For example: chatrooms.

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

      The client-assigned document ID to use for this document.

      Optional. If not specified, an ID will be assigned by the service.

    • document (::Google::Cloud::Firestore::V1::Document, ::Hash) (defaults to: nil)

      Required. The document to create. name must not be set.

    • mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) (defaults to: nil)

      The fields to return. If not set, returns all fields.

      If the document has a field that is not present in this mask, that field will not be returned in the response.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 1876

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::V1::CreateDocumentRequest

  # 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.create_document..to_h

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

  header_params = {}
  if request.parent
    header_params["parent"] = request.parent
  end
  if request.collection_id
    header_params["collection_id"] = request.collection_id
  end

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

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

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

  @firestore_stub.call_rpc :create_document, 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

#delete_document(request, options = nil) ⇒ ::Google::Protobuf::Empty #delete_document(name: nil, current_document: nil) ⇒ ::Google::Protobuf::Empty

Deletes a document.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

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

# The returned object is of type Google::Protobuf::Empty.
p result

Overloads:

  • #delete_document(request, options = nil) ⇒ ::Google::Protobuf::Empty

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

    Parameters:

    • request (::Google::Cloud::Firestore::V1::DeleteDocumentRequest, ::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.

  • #delete_document(name: nil, current_document: nil) ⇒ ::Google::Protobuf::Empty

    Pass arguments to delete_document 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:

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

      Required. The resource name of the Document to delete. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}.

    • current_document (::Google::Cloud::Firestore::V1::Precondition, ::Hash) (defaults to: nil)

      An optional precondition on the document. The request will fail if this is set and not met by the target document.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 656

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::V1::DeleteDocumentRequest

  # 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.delete_document..to_h

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

  header_params = {}
  if request.name
    header_params["name"] = request.name
  end

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

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

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

  @firestore_stub.call_rpc :delete_document, 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

#get_document(request, options = nil) ⇒ ::Google::Cloud::Firestore::V1::Document #get_document(name: nil, mask: nil, transaction: nil, read_time: nil) ⇒ ::Google::Cloud::Firestore::V1::Document

Gets a single document.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

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

# The returned object is of type Google::Cloud::Firestore::V1::Document.
p result

Overloads:

  • #get_document(request, options = nil) ⇒ ::Google::Cloud::Firestore::V1::Document

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

    Parameters:

    • request (::Google::Cloud::Firestore::V1::GetDocumentRequest, ::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.

  • #get_document(name: nil, mask: nil, transaction: nil, read_time: nil) ⇒ ::Google::Cloud::Firestore::V1::Document

    Pass arguments to get_document 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:

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

      Required. The resource name of the Document to get. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}.

    • mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) (defaults to: nil)

      The fields to return. If not set, returns all fields.

      If the document has a field that is not present in this mask, that field will not be returned in the response.

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

      Reads the document in a transaction.

    • read_time (::Google::Protobuf::Timestamp, ::Hash) (defaults to: nil)

      Reads the version of the document at the given time.

      This must be a microsecond precision timestamp within the past one hour, or if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp within the past 7 days.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 318

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::V1::GetDocumentRequest

  # 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.get_document..to_h

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

  header_params = {}
  if request.name
    header_params["name"] = request.name
  end

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

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

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

  @firestore_stub.call_rpc :get_document, 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

#list_collection_ids(request, options = nil) ⇒ ::Google::Cloud::Firestore::V1::ListCollectionIdsResponse #list_collection_ids(parent: nil, page_size: nil, page_token: nil, read_time: nil) ⇒ ::Google::Cloud::Firestore::V1::ListCollectionIdsResponse

Lists all the collection IDs underneath a document.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

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

# The returned object is of type Google::Cloud::Firestore::V1::ListCollectionIdsResponse.
p result

Overloads:

  • #list_collection_ids(request, options = nil) ⇒ ::Google::Cloud::Firestore::V1::ListCollectionIdsResponse

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

    Parameters:

    • request (::Google::Cloud::Firestore::V1::ListCollectionIdsRequest, ::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.

  • #list_collection_ids(parent: nil, page_size: nil, page_token: nil, read_time: nil) ⇒ ::Google::Cloud::Firestore::V1::ListCollectionIdsResponse

    Pass arguments to list_collection_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:

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

      Required. The parent document. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}. For example: projects/my-project/databases/my-database/documents/chatrooms/my-chatroom

    • page_size (::Integer) (defaults to: nil)

      The maximum number of results to return.

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

      A page token. Must be a value from ListCollectionIdsResponse.

    • read_time (::Google::Protobuf::Timestamp, ::Hash) (defaults to: nil)

      Reads documents as they were at the given time.

      This must be a microsecond precision timestamp within the past one hour, or if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp within the past 7 days.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 1672

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::V1::ListCollectionIdsRequest

  # 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.list_collection_ids..to_h

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

  header_params = {}
  if request.parent
    header_params["parent"] = request.parent
  end

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

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

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

  @firestore_stub.call_rpc :list_collection_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

#list_documents(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Document> #list_documents(parent: nil, collection_id: nil, page_size: nil, page_token: nil, order_by: nil, mask: nil, transaction: nil, read_time: nil, show_missing: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Document>

Lists documents.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

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

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Cloud::Firestore::V1::Document.
  p item
end

Overloads:

  • #list_documents(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Document>

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

    Parameters:

    • request (::Google::Cloud::Firestore::V1::ListDocumentsRequest, ::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.

  • #list_documents(parent: nil, collection_id: nil, page_size: nil, page_token: nil, order_by: nil, mask: nil, transaction: nil, read_time: nil, show_missing: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Document>

    Pass arguments to list_documents 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:

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

      Required. The parent resource name. In the format: projects/{project_id}/databases/{database_id}/documents or projects/{project_id}/databases/{database_id}/documents/{document_path}.

      For example: projects/my-project/databases/my-database/documents or projects/my-project/databases/my-database/documents/chatrooms/my-chatroom

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

      Optional. The collection ID, relative to parent, to list.

      For example: chatrooms or messages.

      This is optional, and when not provided, Firestore will list documents from all collections under the provided parent.

    • page_size (::Integer) (defaults to: nil)

      Optional. The maximum number of documents to return in a single response.

      Firestore may return fewer than this value.

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

      Optional. A page token, received from a previous ListDocuments response.

      Provide this to retrieve the subsequent page. When paginating, all other parameters (with the exception of page_size) must match the values set in the request that generated the page token.

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

      Optional. The optional ordering of the documents to return.

      For example: priority desc, __name__ desc.

      This mirrors the ORDER BY used in Firestore queries but in a string representation. When absent, documents are ordered based on __name__ ASC.

    • mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) (defaults to: nil)

      Optional. The fields to return. If not set, returns all fields.

      If a document has a field that is not present in this mask, that field will not be returned in the response.

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

      Perform the read as part of an already active transaction.

    • read_time (::Google::Protobuf::Timestamp, ::Hash) (defaults to: nil)

      Perform the read at the provided time.

      This must be a microsecond precision timestamp within the past one hour, or if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp within the past 7 days.

    • show_missing (::Boolean) (defaults to: nil)

      If the list should show missing documents.

      A document is missing if it does not exist, but there are sub-documents nested underneath it. When true, such missing documents will be returned with a key but will not have fields, create_time, or update_time set.

      Requests with show_missing may not specify where or order_by.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 461

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::V1::ListDocumentsRequest

  # 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.list_documents..to_h

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

  header_params = {}
  if request.parent
    header_params["parent"] = request.parent
  end
  if request.collection_id
    header_params["collection_id"] = request.collection_id
  end

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

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

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

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

#listen(request, options = nil) {|response, operation| ... } ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::ListenResponse>

Listens to changes. This method is only available via gRPC or WebChannel (not REST).

Examples:

Basic example

require "google/cloud/firestore/v1"

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

# Create an input stream.
input = Gapic::StreamInput.new

# Call the listen method to start streaming.
output = client.listen input

# Send requests on the stream. For each request object, set fields by
# passing keyword arguments. Be sure to close the stream when done.
input << Google::Cloud::Firestore::V1::ListenRequest.new
input << Google::Cloud::Firestore::V1::ListenRequest.new
input.close

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::Firestore::V1::ListenResponse
output.each do |current_response|
  p current_response
end

Parameters:

  • request (::Gapic::StreamInput, ::Enumerable<::Google::Cloud::Firestore::V1::ListenRequest, ::Hash>)

    An enumerable of ListenRequest instances.

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

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

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 1576

def listen request, options = nil
  unless request.is_a? ::Enumerable
    raise ::ArgumentError, "request must be an Enumerable" unless request.respond_to? :to_enum
    request = request.to_enum
  end

  request = request.lazy.map do |req|
    ::Gapic::Protobuf.coerce req, to: ::Google::Cloud::Firestore::V1::ListenRequest
  end

  # 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.listen..to_h

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

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

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

  @firestore_stub.call_rpc :listen, 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

#partition_query(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Cursor> #partition_query(parent: nil, structured_query: nil, partition_count: nil, page_token: nil, page_size: nil, read_time: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Cursor>

Partitions a query by returning partition cursors that can be used to run the query in parallel. The returned partition cursors are split points that can be used by RunQuery as starting/end points for the query results.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

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

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Cloud::Firestore::V1::Cursor.
  p item
end

Overloads:

  • #partition_query(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Cursor>

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

    Parameters:

    • request (::Google::Cloud::Firestore::V1::PartitionQueryRequest, ::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.

  • #partition_query(parent: nil, structured_query: nil, partition_count: nil, page_token: nil, page_size: nil, read_time: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Cursor>

    Pass arguments to partition_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:

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

      Required. The parent resource name. In the format: projects/{project_id}/databases/{database_id}/documents. Document resource names are not supported; only database resource names can be specified.

    • structured_query (::Google::Cloud::Firestore::V1::StructuredQuery, ::Hash) (defaults to: nil)

      A structured query. Query must specify collection with all descendants and be ordered by name ascending. Other filters, order bys, limits, offsets, and start/end cursors are not supported.

    • partition_count (::Integer) (defaults to: nil)

      The desired maximum number of partition points. The partitions may be returned across multiple pages of results. The number must be positive. The actual number of partitions returned may be fewer.

      For example, this may be set to one fewer than the number of parallel queries to be run, or in running a data pipeline job, one fewer than the number of workers or compute instances available.

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

      The next_page_token value returned from a previous call to PartitionQuery that may be used to get an additional set of results. There are no ordering guarantees between sets of results. Thus, using multiple sets of results will require merging the different result sets.

      For example, two subsequent calls using a page_token may return:

      • cursor B, cursor M, cursor Q
      • cursor A, cursor U, cursor W

      To obtain a complete result set ordered with respect to the results of the query supplied to PartitionQuery, the results sets should be merged: cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W

    • page_size (::Integer) (defaults to: nil)

      The maximum number of partitions to return in this call, subject to partition_count.

      For example, if partition_count = 10 and page_size = 8, the first call to PartitionQuery will return up to 8 partitions and a next_page_token if more results exist. A second call to PartitionQuery will return up to 2 partitions, to complete the total of 10 specified in partition_count.

    • read_time (::Google::Protobuf::Timestamp, ::Hash) (defaults to: nil)

      Reads documents as they were at the given time.

      This must be a microsecond precision timestamp within the past one hour, or if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp within the past 7 days.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 1414

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::V1::PartitionQueryRequest

  # 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.partition_query..to_h

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

  header_params = {}
  if request.parent
    header_params["parent"] = request.parent
  end

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

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

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

  @firestore_stub.call_rpc :partition_query, request, options: options do |response, operation|
    response = ::Gapic::PagedEnumerable.new @firestore_stub, :partition_query, request, response, operation, options
    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) ⇒ ::Google::Protobuf::Empty #rollback(database: nil, transaction: nil) ⇒ ::Google::Protobuf::Empty

Rolls back a transaction.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

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

# The returned object is of type Google::Protobuf::Empty.
p result

Overloads:

  • #rollback(request, options = nil) ⇒ ::Google::Protobuf::Empty

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

    Parameters:

    • request (::Google::Cloud::Firestore::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(database: nil, transaction: nil) ⇒ ::Google::Protobuf::Empty

    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:

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

      Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

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

      Required. The transaction to roll back.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



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
1072
1073
1074
1075
1076
1077
1078
1079
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 1040

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::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 and x-goog-user-project 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::Firestore::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.database
    header_params["database"] = request.database
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"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

  @firestore_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_aggregation_query(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::RunAggregationQueryResponse> #run_aggregation_query(parent: nil, structured_aggregation_query: nil, transaction: nil, new_transaction: nil, read_time: nil, explain_options: nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::RunAggregationQueryResponse>

Runs an aggregation query.

Rather than producing Document results like Firestore.RunQuery, this API allows running an aggregation to produce a series of AggregationResult server-side.

High-Level Example:

-- Return the number of documents in table given a filter.
SELECT COUNT(*) FROM ( SELECT * FROM k where a = true );

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

# Call the run_aggregation_query method to start streaming.
output = client.run_aggregation_query request

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::Firestore::V1::RunAggregationQueryResponse
output.each do |current_response|
  p current_response
end

Overloads:

  • #run_aggregation_query(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::RunAggregationQueryResponse>

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

    Parameters:

    • request (::Google::Cloud::Firestore::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(parent: nil, structured_aggregation_query: nil, transaction: nil, new_transaction: nil, read_time: nil, explain_options: nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::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:

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

      Required. The parent resource name. In the format: projects/{project_id}/databases/{database_id}/documents or projects/{project_id}/databases/{database_id}/documents/{document_path}. For example: projects/my-project/databases/my-database/documents or projects/my-project/databases/my-database/documents/chatrooms/my-chatroom

    • structured_aggregation_query (::Google::Cloud::Firestore::V1::StructuredAggregationQuery, ::Hash) (defaults to: nil)

      An aggregation query.

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

      Run the aggregation within an already active transaction.

      The value here is the opaque transaction ID to execute the query in.

    • new_transaction (::Google::Cloud::Firestore::V1::TransactionOptions, ::Hash) (defaults to: nil)

      Starts a new transaction as part of the query, defaulting to read-only.

      The new transaction ID will be returned as the first response in the stream.

    • read_time (::Google::Protobuf::Timestamp, ::Hash) (defaults to: nil)

      Executes the query at the given timestamp.

      This must be a microsecond precision timestamp within the past one hour, or if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp within the past 7 days.

    • explain_options (::Google::Cloud::Firestore::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.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 1278

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::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 and x-goog-user-project 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::Firestore::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.parent
    header_params["parent"] = request.parent
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"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

  @firestore_stub.call_rpc :run_aggregation_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

#run_query(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::RunQueryResponse> #run_query(parent: nil, structured_query: nil, transaction: nil, new_transaction: nil, read_time: nil, explain_options: nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::RunQueryResponse>

Runs a query.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

# Call the run_query method to start streaming.
output = client.run_query request

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::Firestore::V1::RunQueryResponse
output.each do |current_response|
  p current_response
end

Overloads:

  • #run_query(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::RunQueryResponse>

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

    Parameters:

    • request (::Google::Cloud::Firestore::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(parent: nil, structured_query: nil, transaction: nil, new_transaction: nil, read_time: nil, explain_options: nil) ⇒ ::Enumerable<::Google::Cloud::Firestore::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:

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

      Required. The parent resource name. In the format: projects/{project_id}/databases/{database_id}/documents or projects/{project_id}/databases/{database_id}/documents/{document_path}. For example: projects/my-project/databases/my-database/documents or projects/my-project/databases/my-database/documents/chatrooms/my-chatroom

    • structured_query (::Google::Cloud::Firestore::V1::StructuredQuery, ::Hash) (defaults to: nil)

      A structured query.

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

      Run the query within an already active transaction.

      The value here is the opaque transaction ID to execute the query in.

    • new_transaction (::Google::Cloud::Firestore::V1::TransactionOptions, ::Hash) (defaults to: nil)

      Starts a new transaction and reads the documents. Defaults to a read-only transaction. The new transaction ID will be returned as the first response in the stream.

    • read_time (::Google::Protobuf::Timestamp, ::Hash) (defaults to: nil)

      Reads documents as they were at the given time.

      This must be a microsecond precision timestamp within the past one hour, or if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp within the past 7 days.

    • explain_options (::Google::Cloud::Firestore::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.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 1153

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::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 and x-goog-user-project 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::Firestore::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.parent
    header_params["parent"] = request.parent
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"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

  @firestore_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

#universe_domainString

The effective universe domain

Returns:

  • (String)


184
185
186
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 184

def universe_domain
  @firestore_stub.universe_domain
end

#update_document(request, options = nil) ⇒ ::Google::Cloud::Firestore::V1::Document #update_document(document: nil, update_mask: nil, mask: nil, current_document: nil) ⇒ ::Google::Cloud::Firestore::V1::Document

Updates or inserts a document.

Examples:

Basic example

require "google/cloud/firestore/v1"

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

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

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

# The returned object is of type Google::Cloud::Firestore::V1::Document.
p result

Overloads:

  • #update_document(request, options = nil) ⇒ ::Google::Cloud::Firestore::V1::Document

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

    Parameters:

    • request (::Google::Cloud::Firestore::V1::UpdateDocumentRequest, ::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.

  • #update_document(document: nil, update_mask: nil, mask: nil, current_document: nil) ⇒ ::Google::Cloud::Firestore::V1::Document

    Pass arguments to update_document 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:

    • document (::Google::Cloud::Firestore::V1::Document, ::Hash) (defaults to: nil)

      Required. The updated document. Creates the document if it does not already exist.

    • update_mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) (defaults to: nil)

      The fields to update. None of the field paths in the mask may contain a reserved name.

      If the document exists on the server and has fields not referenced in the mask, they are left unchanged. Fields referenced in the mask, but not present in the input document, are deleted from the document on the server.

    • mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) (defaults to: nil)

      The fields to return. If not set, returns all fields.

      If the document has a field that is not present in this mask, that field will not be returned in the response.

    • current_document (::Google::Cloud::Firestore::V1::Precondition, ::Hash) (defaults to: nil)

      An optional precondition on the document. The request will fail if this is set and not met by the target document.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 567

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

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Firestore::V1::UpdateDocumentRequest

  # 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.update_document..to_h

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

  header_params = {}
  if request.document&.name
    header_params["document.name"] = request.document.name
  end

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

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

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

  @firestore_stub.call_rpc :update_document, 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

#write(request, options = nil) {|response, operation| ... } ⇒ ::Enumerable<::Google::Cloud::Firestore::V1::WriteResponse>

Streams batches of document updates and deletes, in order. This method is only available via gRPC or WebChannel (not REST).

Examples:

Basic example

require "google/cloud/firestore/v1"

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

# Create an input stream.
input = Gapic::StreamInput.new

# Call the write method to start streaming.
output = client.write input

# Send requests on the stream. For each request object, set fields by
# passing keyword arguments. Be sure to close the stream when done.
input << Google::Cloud::Firestore::V1::WriteRequest.new
input << Google::Cloud::Firestore::V1::WriteRequest.new
input.close

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::Firestore::V1::WriteResponse
output.each do |current_response|
  p current_response
end

Parameters:

  • request (::Gapic::StreamInput, ::Enumerable<::Google::Cloud::Firestore::V1::WriteRequest, ::Hash>)

    An enumerable of WriteRequest instances.

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

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

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

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

    if the RPC is aborted.



1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
# File 'lib/google/cloud/firestore/v1/firestore/client.rb', line 1497

def write request, options = nil
  unless request.is_a? ::Enumerable
    raise ::ArgumentError, "request must be an Enumerable" unless request.respond_to? :to_enum
    request = request.to_enum
  end

  request = request.lazy.map do |req|
    ::Gapic::Protobuf.coerce req, to: ::Google::Cloud::Firestore::V1::WriteRequest
  end

  # 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.write..to_h

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

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

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

  @firestore_stub.call_rpc :write, 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