pub struct FirebaseFirestore { /* private fields */ }Expand description
Client for interacting with Cloud Firestore.
Implementations§
Source§impl FirebaseFirestore
impl FirebaseFirestore
Sourcepub fn new(middleware: AuthMiddleware) -> Self
pub fn new(middleware: AuthMiddleware) -> Self
Creates a new FirebaseFirestore instance.
This is typically called via FirebaseApp::firestore().
Sourcepub fn new_with_url(middleware: AuthMiddleware, base_url: String) -> Self
pub fn new_with_url(middleware: AuthMiddleware, base_url: String) -> Self
Creates a new FirebaseFirestore instance with a custom base URL (useful for testing).
Sourcepub fn collection<'a>(&'a self, collection_id: &str) -> CollectionReference<'a>
pub fn collection<'a>(&'a self, collection_id: &str) -> CollectionReference<'a>
Gets a CollectionReference instance that refers to the collection at the specified path.
§Arguments
collection_id- The ID of the collection (e.g., “users”).
Sourcepub async fn list_collections(
&self,
) -> Result<Vec<CollectionReference<'_>>, FirestoreError>
pub async fn list_collections( &self, ) -> Result<Vec<CollectionReference<'_>>, FirestoreError>
Lists the root collections of the database.
Sourcepub fn doc<'a>(&'a self, document_path: &str) -> DocumentReference<'a>
pub fn doc<'a>(&'a self, document_path: &str) -> DocumentReference<'a>
Gets a DocumentReference instance that refers to the document at the specified path.
§Arguments
document_path- The slash-separated path to the document (e.g., “users/user1”).
Sourcepub fn batch(&self) -> WriteBatch<'_>
pub fn batch(&self) -> WriteBatch<'_>
Creates a write batch, used for performing multiple writes as a single atomic operation.
Sourcepub async fn begin_transaction(
&self,
options: Option<TransactionOptions>,
) -> Result<Transaction, FirestoreError>
pub async fn begin_transaction( &self, options: Option<TransactionOptions>, ) -> Result<Transaction, FirestoreError>
Begins a new transaction.
This method is for manual transaction management. For automatic retries, use run_transaction.
Sourcepub async fn rollback(&self, transaction_id: &str) -> Result<(), FirestoreError>
pub async fn rollback(&self, transaction_id: &str) -> Result<(), FirestoreError>
Rolls back a transaction.
Sourcepub async fn run_transaction<F, Fut, R>(
&self,
update_fn: F,
) -> Result<R, FirestoreError>
pub async fn run_transaction<F, Fut, R>( &self, update_fn: F, ) -> Result<R, FirestoreError>
Runs the given update function within a transaction.
The update function may be called multiple times if the transaction is aborted due to contention.
§Arguments
update_fn- A closure that takes aTransactionand returns aFuture.