Class: Google::Cloud::Firestore::Batch
- Inherits:
-
Object
- Object
- Google::Cloud::Firestore::Batch
- Defined in:
- lib/google/cloud/firestore/batch.rb
Overview
Batch
A batch in Cloud Firestore is a set of writes that execute atomically at a single logical point in time in a database.
All changes are accumulated in memory until the block passed to Client#batch completes. Unlike transactions, batches don't lock on document reads, should only fail if users provide preconditions, and are not automatically retried.
Modifications collapse
-
#create(doc, data) ⇒ Object
Create a document with the provided data (fields and values).
-
#delete(doc, exists: nil, update_time: nil) ⇒ Object
Deletes a document from the database.
-
#set(doc, data, merge: nil) ⇒ Object
Write the provided data (fields and values) to the provided document.
-
#update(doc, data, update_time: nil) ⇒ Object
Update the document with the provided data (fields and values).
Instance Method Summary collapse
-
#firestore ⇒ Client
(also: #client)
The client the Cloud Firestore batch belongs to.
Instance Method Details
#create(doc, data) ⇒ Object
Create a document with the provided data (fields and values).
The batch will fail if the document already exists.
117 118 119 120 121 122 123 124 125 |
# File 'lib/google/cloud/firestore/batch.rb', line 117 def create doc, data ensure_not_closed! doc_path = coalesce_doc_path_argument doc @writes << Convert.writes_for_create(doc_path, data) nil end |
#delete(doc, exists: nil, update_time: nil) ⇒ Object
Deletes a document from the database.
383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/google/cloud/firestore/batch.rb', line 383 def delete doc, exists: nil, update_time: nil ensure_not_closed! doc_path = coalesce_doc_path_argument doc @writes << Convert.write_for_delete( doc_path, exists: exists, update_time: update_time ) nil end |
#firestore ⇒ Client Also known as: client
The client the Cloud Firestore batch belongs to.
67 68 69 |
# File 'lib/google/cloud/firestore/batch.rb', line 67 def firestore @client end |
#set(doc, data, merge: nil) ⇒ Object
Write the provided data (fields and values) to the provided document.
If the document does not exist, it will be created. By default, the
provided data overwrites existing data, but the provided data can be
merged into the existing document using the merge
argument.
If you're not sure whether the document exists, use the merge
argument to merge the new data with any existing document data to
avoid overwriting entire documents.
216 217 218 219 220 221 222 223 224 |
# File 'lib/google/cloud/firestore/batch.rb', line 216 def set doc, data, merge: nil ensure_not_closed! doc_path = coalesce_doc_path_argument doc @writes << Convert.writes_for_set(doc_path, data, merge: merge) nil end |
#update(doc, data, update_time: nil) ⇒ Object
Update the document with the provided data (fields and values). The provided data is merged into the existing document data.
The batch will fail if the document does not exist.
320 321 322 323 324 325 326 327 328 329 |
# File 'lib/google/cloud/firestore/batch.rb', line 320 def update doc, data, update_time: nil ensure_not_closed! doc_path = coalesce_doc_path_argument doc @writes << Convert.writes_for_update(doc_path, data, update_time: update_time) nil end |