Class: Google::Cloud::Firestore::V1beta1::FirestoreClient Deprecated
- Inherits:
-
Object
- Object
- Google::Cloud::Firestore::V1beta1::FirestoreClient
- Defined in:
- lib/google/cloud/firestore/v1beta1/firestore_client.rb
Overview
Use Google::Cloud::Firestore::V1::FirestoreClient instead.
The Cloud Firestore service.
This service exposes several types of comparable timestamps:
create_time
- The time at which a document was created. Changes only when a document is deleted, then re-created. Increases in a strict monotonic fashion.update_time
- The time at which a document was last updated. Changes every time a document is modified. Does not change when a write results in no modifications. Increases in a strict monotonic fashion.read_time
- The time at which a particular state was observed. Used to denote a consistent snapshot of the database or the time at which a Document was observed to not exist.commit_time
- The time at which the writes in a transaction were committed. Any read with an equal or greaterread_time
is guaranteed to see the effects of the transaction.
Constant Summary collapse
- SERVICE_ADDRESS =
The default address of the service.
"firestore.googleapis.com".freeze
- DEFAULT_SERVICE_PORT =
The default port of the service.
443
- GRPC_INTERCEPTORS =
The default set of gRPC interceptors.
[]
- DEFAULT_TIMEOUT =
30
- ALL_SCOPES =
The scopes needed to make gRPC calls to all of the methods defined in this service.
[ "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/datastore" ].freeze
Instance Method Summary collapse
-
#batch_get_documents(database, documents: nil, mask: nil, transaction: nil, new_transaction: nil, read_time: nil, options: nil) ⇒ Enumerable<Google::Firestore::V1beta1::BatchGetDocumentsResponse>
Gets multiple documents.
-
#begin_transaction(database, options_: nil, options: nil) {|result, operation| ... } ⇒ Google::Firestore::V1beta1::BeginTransactionResponse
Starts a new transaction.
-
#commit(database, writes: nil, transaction: nil, options: nil) {|result, operation| ... } ⇒ Google::Firestore::V1beta1::CommitResponse
Commits a transaction, while optionally updating documents.
-
#create_document(parent, collection_id, document, document_id: nil, mask: nil, options: nil) {|result, operation| ... } ⇒ Google::Firestore::V1beta1::Document
Creates a new document.
-
#delete_document(name, current_document: nil, options: nil) {|result, operation| ... } ⇒ Object
Deletes a document.
-
#get_document(name, mask: nil, transaction: nil, read_time: nil, options: nil) {|result, operation| ... } ⇒ Google::Firestore::V1beta1::Document
Gets a single document.
-
#initialize(credentials: nil, scopes: ALL_SCOPES, client_config: {}, timeout: DEFAULT_TIMEOUT, metadata: nil, service_address: nil, service_port: nil, exception_transformer: nil, lib_name: nil, lib_version: "") ⇒ FirestoreClient
constructor
A new instance of FirestoreClient.
-
#list_collection_ids(parent, page_size: nil, options: nil) {|result, operation| ... } ⇒ Google::Gax::PagedEnumerable<String>
Lists all the collection IDs underneath a document.
-
#list_documents(parent, collection_id, page_size: nil, order_by: nil, mask: nil, transaction: nil, read_time: nil, show_missing: nil, options: nil) {|result, operation| ... } ⇒ Google::Gax::PagedEnumerable<Google::Firestore::V1beta1::Document>
Lists documents.
-
#listen(reqs, options: nil) ⇒ Enumerable<Google::Firestore::V1beta1::ListenResponse>
Listens to changes.
-
#rollback(database, transaction, options: nil) {|result, operation| ... } ⇒ Object
Rolls back a transaction.
-
#run_query(parent, structured_query: nil, transaction: nil, new_transaction: nil, read_time: nil, options: nil) ⇒ Enumerable<Google::Firestore::V1beta1::RunQueryResponse>
Runs a query.
-
#update_document(document, update_mask: nil, mask: nil, current_document: nil, options: nil) {|result, operation| ... } ⇒ Google::Firestore::V1beta1::Document
Updates or inserts a document.
-
#write(reqs, options: nil) ⇒ Enumerable<Google::Firestore::V1beta1::WriteResponse>
Streams batches of document updates and deletes, in order.
Constructor Details
#initialize(credentials: nil, scopes: ALL_SCOPES, client_config: {}, timeout: DEFAULT_TIMEOUT, metadata: nil, service_address: nil, service_port: nil, exception_transformer: nil, lib_name: nil, lib_version: "") ⇒ FirestoreClient
Returns a new instance of FirestoreClient.
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 126 def initialize \ credentials: nil, scopes: ALL_SCOPES, client_config: {}, timeout: DEFAULT_TIMEOUT, metadata: nil, service_address: nil, service_port: nil, exception_transformer: nil, lib_name: nil, lib_version: "" # 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 "google/gax/grpc" require "google/firestore/v1beta1/firestore_services_pb" credentials ||= Google::Cloud::Firestore::V1beta1::Credentials.default if credentials.is_a?(String) || credentials.is_a?(Hash) updater_proc = Google::Cloud::Firestore::V1beta1::Credentials.new(credentials).updater_proc end if credentials.is_a?(GRPC::Core::Channel) channel = credentials end if credentials.is_a?(GRPC::Core::ChannelCredentials) chan_creds = credentials end if credentials.is_a?(Proc) updater_proc = credentials end if credentials.is_a?(Google::Auth::Credentials) updater_proc = credentials.updater_proc end package_version = Google::Cloud::Firestore::VERSION google_api_client = "gl-ruby/#{RUBY_VERSION}" google_api_client << " #{lib_name}/#{lib_version}" if lib_name google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}" google_api_client << " grpc/#{GRPC::VERSION}" google_api_client.freeze headers = { :"x-goog-api-client" => google_api_client } if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id headers[:"x-goog-user-project"] = credentials.quota_project_id end headers.merge!() unless .nil? client_config_file = Pathname.new(__dir__).join( "firestore_client_config.json" ) defaults = client_config_file.open do |f| Google::Gax.construct_settings( "google.firestore.v1beta1.Firestore", JSON.parse(f.read), client_config, Google::Gax::Grpc::STATUS_CODE_NAMES, timeout, page_descriptors: PAGE_DESCRIPTORS, errors: Google::Gax::Grpc::API_ERRORS, metadata: headers ) end # Allow overriding the service path/port in subclasses. service_path = service_address || self.class::SERVICE_ADDRESS port = service_port || self.class::DEFAULT_SERVICE_PORT interceptors = self.class::GRPC_INTERCEPTORS @firestore_stub = Google::Gax::Grpc.create_stub( service_path, port, chan_creds: chan_creds, channel: channel, updater_proc: updater_proc, scopes: scopes, interceptors: interceptors, &Google::Firestore::V1beta1::Firestore::Stub.method(:new) ) @delete_document = Google::Gax.create_api_call( @firestore_stub.method(:delete_document), defaults["delete_document"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'name' => request.name} end ) @batch_get_documents = Google::Gax.create_api_call( @firestore_stub.method(:batch_get_documents), defaults["batch_get_documents"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'database' => request.database} end ) @begin_transaction = Google::Gax.create_api_call( @firestore_stub.method(:begin_transaction), defaults["begin_transaction"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'database' => request.database} end ) @rollback = Google::Gax.create_api_call( @firestore_stub.method(:rollback), defaults["rollback"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'database' => request.database} end ) @run_query = Google::Gax.create_api_call( @firestore_stub.method(:run_query), defaults["run_query"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'parent' => request.parent} end ) @write = Google::Gax.create_api_call( @firestore_stub.method(:write), defaults["write"], exception_transformer: exception_transformer ) @listen = Google::Gax.create_api_call( @firestore_stub.method(:listen), defaults["listen"], exception_transformer: exception_transformer ) @list_collection_ids = Google::Gax.create_api_call( @firestore_stub.method(:list_collection_ids), defaults["list_collection_ids"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'parent' => request.parent} end ) @get_document = Google::Gax.create_api_call( @firestore_stub.method(:get_document), defaults["get_document"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'name' => request.name} end ) @list_documents = Google::Gax.create_api_call( @firestore_stub.method(:list_documents), defaults["list_documents"], exception_transformer: exception_transformer ) @create_document = Google::Gax.create_api_call( @firestore_stub.method(:create_document), defaults["create_document"], exception_transformer: exception_transformer ) @update_document = Google::Gax.create_api_call( @firestore_stub.method(:update_document), defaults["update_document"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'document.name' => request.document.name} end ) @commit = Google::Gax.create_api_call( @firestore_stub.method(:commit), defaults["commit"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'database' => request.database} end ) end |
Instance Method Details
#batch_get_documents(database, documents: nil, mask: nil, transaction: nil, new_transaction: nil, read_time: nil, options: nil) ⇒ Enumerable<Google::Firestore::V1beta1::BatchGetDocumentsResponse>
Gets multiple documents.
Documents returned by this method are not guaranteed to be returned in the same order that they were requested.
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 393 def batch_get_documents \ database, documents: nil, mask: nil, transaction: nil, new_transaction: nil, read_time: nil, options: nil req = { database: database, documents: documents, mask: mask, transaction: transaction, new_transaction: new_transaction, read_time: read_time }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::BatchGetDocumentsRequest) @batch_get_documents.call(req, ) end |
#begin_transaction(database, options_: nil, options: nil) {|result, operation| ... } ⇒ Google::Firestore::V1beta1::BeginTransactionResponse
Starts a new transaction.
440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 440 def begin_transaction \ database, options_: nil, options: nil, &block req = { database: database, options: }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::BeginTransactionRequest) @begin_transaction.call(req, , &block) end |
#commit(database, writes: nil, transaction: nil, options: nil) {|result, operation| ... } ⇒ Google::Firestore::V1beta1::CommitResponse
Commits a transaction, while optionally updating documents.
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 1003 def commit \ database, writes: nil, transaction: nil, options: nil, &block req = { database: database, writes: writes, transaction: transaction }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::CommitRequest) @commit.call(req, , &block) end |
#create_document(parent, collection_id, document, document_id: nil, mask: nil, options: nil) {|result, operation| ... } ⇒ Google::Firestore::V1beta1::Document
Creates a new document.
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 891 def create_document \ parent, collection_id, document, document_id: nil, mask: nil, options: nil, &block req = { parent: parent, collection_id: collection_id, document: document, document_id: document_id, mask: mask }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::CreateDocumentRequest) @create_document.call(req, , &block) end |
#delete_document(name, current_document: nil, options: nil) {|result, operation| ... } ⇒ Object
Deletes a document.
327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 327 def delete_document \ name, current_document: nil, options: nil, &block req = { name: name, current_document: current_document }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::DeleteDocumentRequest) @delete_document.call(req, , &block) nil end |
#get_document(name, mask: nil, transaction: nil, read_time: nil, options: nil) {|result, operation| ... } ⇒ Google::Firestore::V1beta1::Document
Gets a single document.
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 725 def get_document \ name, mask: nil, transaction: nil, read_time: nil, options: nil, &block req = { name: name, mask: mask, transaction: transaction, read_time: read_time }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::GetDocumentRequest) @get_document.call(req, , &block) end |
#list_collection_ids(parent, page_size: nil, options: nil) {|result, operation| ... } ⇒ Google::Gax::PagedEnumerable<String>
Lists all the collection IDs underneath a document.
676 677 678 679 680 681 682 683 684 685 686 687 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 676 def list_collection_ids \ parent, page_size: nil, options: nil, &block req = { parent: parent, page_size: page_size }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListCollectionIdsRequest) @list_collection_ids.call(req, , &block) end |
#list_documents(parent, collection_id, page_size: nil, order_by: nil, mask: nil, transaction: nil, read_time: nil, show_missing: nil, options: nil) {|result, operation| ... } ⇒ Google::Gax::PagedEnumerable<Google::Firestore::V1beta1::Document>
Lists documents.
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 820 def list_documents \ parent, collection_id, page_size: nil, order_by: nil, mask: nil, transaction: nil, read_time: nil, show_missing: nil, options: nil, &block req = { parent: parent, collection_id: collection_id, page_size: page_size, order_by: order_by, mask: mask, transaction: transaction, read_time: read_time, show_missing: show_missing }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListDocumentsRequest) @list_documents.call(req, , &block) end |
#listen(reqs, options: nil) ⇒ Enumerable<Google::Firestore::V1beta1::ListenResponse>
EXPERIMENTAL: Streaming requests are still undergoing review. This method interface might change in the future.
Listens to changes.
623 624 625 626 627 628 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 623 def listen reqs, options: nil request_protos = reqs.lazy.map do |req| Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListenRequest) end @listen.call(request_protos, ) end |
#rollback(database, transaction, options: nil) {|result, operation| ... } ⇒ Object
Rolls back a transaction.
479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 479 def rollback \ database, transaction, options: nil, &block req = { database: database, transaction: transaction }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::RollbackRequest) @rollback.call(req, , &block) nil end |
#run_query(parent, structured_query: nil, transaction: nil, new_transaction: nil, read_time: nil, options: nil) ⇒ Enumerable<Google::Firestore::V1beta1::RunQueryResponse>
Runs a query.
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 538 def run_query \ parent, structured_query: nil, transaction: nil, new_transaction: nil, read_time: nil, options: nil req = { parent: parent, structured_query: structured_query, transaction: transaction, new_transaction: new_transaction, read_time: read_time }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::RunQueryRequest) @run_query.call(req, ) end |
#update_document(document, update_mask: nil, mask: nil, current_document: nil, options: nil) {|result, operation| ... } ⇒ Google::Firestore::V1beta1::Document
Updates or inserts a document.
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 956 def update_document \ document, update_mask: nil, mask: nil, current_document: nil, options: nil, &block req = { document: document, update_mask: update_mask, mask: mask, current_document: current_document }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::UpdateDocumentRequest) @update_document.call(req, , &block) end |
#write(reqs, options: nil) ⇒ Enumerable<Google::Firestore::V1beta1::WriteResponse>
EXPERIMENTAL: Streaming requests are still undergoing review. This method interface might change in the future.
Streams batches of document updates and deletes, in order.
586 587 588 589 590 591 |
# File 'lib/google/cloud/firestore/v1beta1/firestore_client.rb', line 586 def write reqs, options: nil request_protos = reqs.lazy.map do |req| Google::Gax::to_proto(req, Google::Firestore::V1beta1::WriteRequest) end @write.call(request_protos, ) end |