pub struct WriteBatch<'a> { /* private fields */ }Expand description
Represents a Firestore Write Batch.
specific set of writes can be performed atomically.
§Examples
let batch = firestore.batch();
let user1 = json!({"name": "User 1"});
let user2_updates = json!({"name": "User 2 Updated"});
batch.set("users/user1", &user1)?;
batch.update("users/user2", &user2_updates)?;
batch.delete("users/user3")?;
batch.commit().await?;Implementations§
Source§impl<'a> WriteBatch<'a>
impl<'a> WriteBatch<'a>
Sourcepub fn set<T: Serialize>(
&self,
document_path: &str,
value: &T,
) -> Result<&Self, FirestoreError>
pub fn set<T: Serialize>( &self, document_path: &str, value: &T, ) -> Result<&Self, FirestoreError>
Overwrites the document referred to by document_path.
If the document does not exist, it will be created. If it does exist, it will be overwritten.
§Arguments
document_path- The path to the document to write.value- The data to write.
Sourcepub fn update<T: Serialize>(
&self,
document_path: &str,
value: &T,
) -> Result<&Self, FirestoreError>
pub fn update<T: Serialize>( &self, document_path: &str, value: &T, ) -> Result<&Self, FirestoreError>
Updates fields in the document referred to by document_path.
If the document does not exist, the operation will fail.
§Arguments
document_path- The path to the document to update.value- The data to update.
Sourcepub fn delete(&self, document_path: &str) -> Result<&Self, FirestoreError>
pub fn delete(&self, document_path: &str) -> Result<&Self, FirestoreError>
Deletes the document referred to by document_path.
§Arguments
document_path- The path to the document to delete.
Sourcepub fn create<T: Serialize>(
&self,
document_path: &str,
value: &T,
) -> Result<&Self, FirestoreError>
pub fn create<T: Serialize>( &self, document_path: &str, value: &T, ) -> Result<&Self, FirestoreError>
Creates a document at the given path.
If the document already exists, the operation will fail.
§Arguments
document_path- The path to the document to create.value- The data to write.
Sourcepub async fn commit(&self) -> Result<Vec<WriteResult>, FirestoreError>
pub async fn commit(&self) -> Result<Vec<WriteResult>, FirestoreError>
Commits the batch of writes.
Trait Implementations§
Source§impl<'a> Clone for WriteBatch<'a>
impl<'a> Clone for WriteBatch<'a>
Source§fn clone(&self) -> WriteBatch<'a>
fn clone(&self) -> WriteBatch<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<'a> Freeze for WriteBatch<'a>
impl<'a> !RefUnwindSafe for WriteBatch<'a>
impl<'a> Send for WriteBatch<'a>
impl<'a> Sync for WriteBatch<'a>
impl<'a> Unpin for WriteBatch<'a>
impl<'a> !UnwindSafe for WriteBatch<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more