Expand description
§Firestore for Rust
A client for Google Firestore built on the official gRPC API, with a fluent, strongly typed query builder and its own Serde serializer for Firestore’s protobuf values.
Full documentation, with a chapter per topic: https://firestore-rust.abdolence.dev
§Example
use firestore::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)]
struct MyTestStructure {
some_id: FirestoreDocumentId,
some_string: String,
some_num: u64,
}
let db = FirestoreDb::new("my-project-id").await?;
const TEST_COLLECTION_NAME: FirestoreCollectionId =
FirestoreCollectionId::from_static("test");
let my_struct = MyTestStructure {
some_id: FirestoreDocumentId::from_static("test-1"),
some_string: "Test".to_string(),
some_num: 42,
};
// Create a document from a Rust structure
let created: MyTestStructure = db.fluent()
.insert()
.into(TEST_COLLECTION_NAME)
.document_id(&my_struct.some_id)
.object(&my_struct)
.execute()
.await?;
// Query, selecting fields by compile-time checked paths
let as_vec: Vec<MyTestStructure> = db.fluent()
.select()
.fields(paths!(MyTestStructure::{some_id, some_num, some_string}))
.from(TEST_COLLECTION_NAME)
.filter(|q| q.for_all([
q.field(path!(MyTestStructure::some_num)).is_not_null(),
q.field(path!(MyTestStructure::some_string)).eq("Test"),
]))
.order(|o| o.fields([o.field(path!(MyTestStructure::some_num)).desc()]))
.obj()
.query()
.await?;
db.fluent()
.delete()
.from(TEST_COLLECTION_NAME)
.document_id(&my_struct.some_id)
.execute()
.await?;§Where to look
| For | Start at |
|---|---|
| Creating a client | FirestoreDb::new, FirestoreDb::with_options, FirestoreDb::with_options_auth |
| Every read and write | FirestoreDb::fluent |
| Document and collection IDs | FirestoreDocumentId, FirestoreCollectionId, ParentPathBuilder |
| Field paths in queries and updates | path!, paths! |
| Transactions | FirestoreDb::run_transaction, FirestoreTransaction |
| Batch writes | FirestoreDb::create_simple_batch_writer, FirestoreDb::create_streaming_batch_writer |
| Realtime changes | FirestoreDb::create_listener, FirestoreListener |
| Timestamps | FirestoreTimestamp, FirestoreInstant, serialize_as_timestamp |
| Schemaless documents | FirestoreDb::serialize_map_to_doc, FirestoreValue |
| Errors | errors |
Caching is enabled in this build: see FirestoreCache.
§Cargo features
| Feature | Effect |
|---|---|
tls-roots (default) | TLS trust anchors from the platform’s native root store |
tls-webpki-roots | TLS trust anchors bundled from the webpki-roots crate instead |
auth-default-crypto (default) | The aws-lc-rs rustls crypto provider service account keys sign their tokens with; without it, install a rustls CryptoProvider before creating a client |
caching-memory | In-memory collection and document cache, kept current by a listener |
caching-persistent | The same cache backed by an on-disk database |
admin | Declarative index management and bulk delete: composite indexes, vector indexes, single-field overrides, TTL policy, and BulkDeleteDocuments |
Runnable examples for every topic: https://github.com/abdolence/firestore-rs/tree/master/examples
Re-exports§
pub extern crate struct_path;
Re-exports§
pub use gcloud_sdk;pub use jiff;
Modules§
- delete_
builder - Deletes a document, or queues the delete on a batch or transaction.
- document_
transform_ builder - Builds server-side field transformations (increment, array append/remove, server timestamp) for an update.
- errors
- Defines the error types used throughout the
firestore-rscrate. - index_
builder - Declares and syncs one collection group’s composite indexes, single-field overrides and TTL
policy. Requires the
adminfeature. - insert_
builder - Inserts a document from a raw
Documentor a serializable Rust object. - listing_
builder - Lists the documents in a collection, or the collection IDs under a path, with pagination.
- select_
aggregation_ builder - Builds
COUNT,SUMandAVGaggregations for a query. - select_
builder - Runs queries and document/collection-group reads, including filtering, ordering, cursors, vector search, partitioned queries and listeners.
- select_
filter_ builder - Builds comparison, unary and composite (AND/OR) filters for a query.
- select_
order_ builder - Builds the per-field sort direction for a query or listing’s result ordering.
- serialize_
as_ null - Stores an
Option<T>field asT’s ordinary Firestore value when present, or an explicit Firestore null whenNone. - serialize_
as_ null_ timestamp - Stores an
Option<FirestoreInstant>field as a native Firestore timestamp when present, or an explicit Firestore null whenNone. - serialize_
as_ optional_ timestamp - Stores an
Option<FirestoreInstant>field as a native Firestore timestamp when present. - serialize_
as_ reference - Stores a
Stringfield as a native Firestore document reference instead of a plain string value. - serialize_
as_ timestamp - Stores a
FirestoreInstantfield as a native Firestore timestamp instead of a string. - timestamp_
utils - Provides utility functions for working with Firestore timestamps.
- update_
builder - Updates a document from a raw
Document, a serializable Rust object, or transformations only, and queues updates on a batch or transaction.
Macros§
- path
- Builds the Firestore field path for one field of
Structas aString. - path_
camel_ case - Builds the Firestore field path for one field of
Struct, converting it to camelCase. - paths
- Builds the Firestore field paths for several fields of
Structas aVec<String>. - paths_
camel_ case - Builds the Firestore field paths for several fields of
Struct, converting each to camelCase.
Structs§
- Firestore
Aggregated Query Params - Firestore
Aggregated Query Params Init - Required fields of
FirestoreAggregatedQueryParams; convert withFirestoreAggregatedQueryParams::fromor.into(). - Firestore
Aggregation - Firestore
Aggregation Init - Required fields of
FirestoreAggregation; convert withFirestoreAggregation::fromor.into(). - Firestore
Aggregation Operator Avg - Firestore
Aggregation Operator AvgInit - Required fields of
FirestoreAggregationOperatorAvg; convert withFirestoreAggregationOperatorAvg::fromor.into(). - Firestore
Aggregation Operator Count - Firestore
Aggregation Operator Count Init - Required fields of
FirestoreAggregationOperatorCount; convert withFirestoreAggregationOperatorCount::fromor.into(). - Firestore
Aggregation Operator Sum - Firestore
Aggregation Operator SumInit - Required fields of
FirestoreAggregationOperatorSum; convert withFirestoreAggregationOperatorSum::fromor.into(). - Firestore
Batch - Firestore
Batch Write Response - Firestore
Batch Write Response Init - Required fields of
FirestoreBatchWriteResponse; convert withFirestoreBatchWriteResponse::fromor.into(). - Firestore
Bulk Delete Params - A declared bulk delete: the collection groups to remove, at any depth across the whole database, and whether to wait for Firestore to finish.
- Firestore
Bulk Delete Params Init - Required fields of
FirestoreBulkDeleteParams; convert withFirestoreBulkDeleteParams::fromor.into(). - Firestore
Bulk Delete Progress - One collection group’s document- or byte-deletion progress, as Firestore reports it in
BulkDeleteDocumentsMetadata. - Firestore
Bulk Delete Result - The outcome of a bulk delete: what was requested, and - when
FirestoreBulkDeleteParams::waitwas set - what Firestore reported once the operation reached a terminal state. - Firestore
Cache - Manages a cache of Firestore data.
- Firestore
Cache Builder - Builds a
FirestoreCache. - Firestore
Cache Collection - One collection to cache, as described to
FirestoreCacheBuilder. - Firestore
Cache Collection Configuration - Configuration for a single cached collection.
- Firestore
Cache Configuration - Describes which collections a
FirestoreCacheholds and how each of them is loaded. - Firestore
Cache Name - A name identifying a cache instance.
- Firestore
Cache Options - Options for a
FirestoreCache. - Firestore
Cache Options Init - Required fields of
FirestoreCacheOptions; convert withFirestoreCacheOptions::fromor.into(). - Firestore
Collection Documents - Firestore
Collection Documents Init - Required fields of
FirestoreCollectionDocuments; convert withFirestoreCollectionDocuments::fromor.into(). - Firestore
Collection Id - A Firestore collection ID that has been checked against Firestore’s ID rules.
- Firestore
Composite Index - A declared composite index: an ordered list of fields plus the scope it serves.
- Firestore
Db - The main entry point for interacting with a Google Firestore database.
- Firestore
DbOptions - Configuration options for the
FirestoreDbclient. - Firestore
DbOptions Init - Required fields of
FirestoreDbOptions; convert withFirestoreDbOptions::fromor.into(). - Firestore
DbSession Params - Parameters that define the behavior of a Firestore session or a specific set of operations.
- Firestore
DbSession Params Init - Required fields of
FirestoreDbSessionParams; convert withFirestoreDbSessionParams::fromor.into(). - Firestore
Document Id - A Firestore document ID that has been checked against Firestore’s ID rules.
- Firestore
Document Metadata - Metadata associated with a Firestore document or a query operation.
- Firestore
Document Metadata Init - Required fields of
FirestoreDocumentMetadata; convert withFirestoreDocumentMetadata::fromor.into(). - Firestore
Dynamic Struct - A dynamically-typed structure used to represent complex, nested data often found in Firestore’s explain metrics or other metadata.
- Firestore
Dynamic Struct Init - Required fields of
FirestoreDynamicStruct; convert withFirestoreDynamicStruct::fromor.into(). - Firestore
Execution Stats - Statistics related to the execution of a Firestore query.
- Firestore
Execution Stats Init - Required fields of
FirestoreExecutionStats; convert withFirestoreExecutionStats::fromor.into(). - Firestore
Explain Metrics - Detailed metrics about query execution, if requested via
FirestoreExplainOptions. - Firestore
Explain Metrics Init - Required fields of
FirestoreExplainMetrics; convert withFirestoreExplainMetrics::fromor.into(). - Firestore
Explain Options - Options for requesting query execution analysis from Firestore.
- Firestore
Explain Options Init - Required fields of
FirestoreExplainOptions; convert withFirestoreExplainOptions::fromor.into(). - Firestore
Explicit Field Override - An explicit, non-inherited single-field index override, as listed for one field resource.
- Firestore
Expr Builder - The entry point for building fluent Firestore expressions.
- Firestore
Field Override - A single-field index override: the automatic indexes Firestore would otherwise build for
target, replaced by exactly the indexes listed here. - Firestore
Field Override Index - One single-field index a
FirestoreFieldOverridedeclares explicitly. - Firestore
Field Transform - Represents a transformation to apply to a specific field within a document.
- Firestore
Field Transform Init - Required fields of
FirestoreFieldTransform; convert withFirestoreFieldTransform::fromor.into(). - Firestore
Find Nearest Options - Options for performing a vector similarity search (find nearest neighbors).
- Firestore
Find Nearest Options Init - Required fields of
FirestoreFindNearestOptions; convert withFirestoreFindNearestOptions::fromor.into(). - Firestore
GeoPoint - Firestore
Index Deletes Withheld - Undeclared composite indexes a pruning
.sync()planned to delete but left in place, because deleting them could have left queries without an index. - Firestore
Index Field - One field of a composite index: its path and how it participates.
- Firestore
Index Params - One collection group’s declared composite indexes, single-field overrides and TTL policy.
- Firestore
Index Params Init - Required fields of
FirestoreIndexParams; convert withFirestoreIndexParams::fromor.into(). - Firestore
Index Plan - The outcome of comparing a declared
FirestoreIndexParamsagainst one collection group’s existing indexes, field overrides and TTL configuration, under the givenFirestoreIndexSyncOptions::prunesetting. - Firestore
Index Sync Options - Options controlling how
.sync()reconciles a declaredFirestoreIndexParamswith Firestore. - Firestore
Index Sync Options Init - Required fields of
FirestoreIndexSyncOptions; convert withFirestoreIndexSyncOptions::fromor.into(). - Firestore
Index Sync Report - The result of
.sync(): what it changed, what it left alone, and what it found undeclared. - Firestore
Index Sync Timings - How long a
.sync()took, in total and per phase. A phase isNonewhen it did not run: all of them for a skipped sync, andwaitwhen the caller did not ask to wait. - Firestore
LatLng - Firestore
List Collection IdsParams - Firestore
List Collection IdsParams Init - Required fields of
FirestoreListCollectionIdsParams; convert withFirestoreListCollectionIdsParams::fromor.into(). - Firestore
List Collection IdsResult - Firestore
List Collection IdsResult Init - Required fields of
FirestoreListCollectionIdsResult; convert withFirestoreListCollectionIdsResult::fromor.into(). - Firestore
List DocParams - Firestore
List DocParams Init - Required fields of
FirestoreListDocParams; convert withFirestoreListDocParams::fromor.into(). - Firestore
List DocResult - Firestore
List DocResult Init - Required fields of
FirestoreListDocResult; convert withFirestoreListDocResult::fromor.into(). - Firestore
Listed Composite Index - One composite index Firestore has listed for the owned collection group.
- Firestore
Listed Field - One field resource Firestore has listed for the owned collection group, because it carries an explicit single-field index override, a TTL configuration, or both.
- Firestore
Listener - Firestore
Listener Control Handle - A cheap, cloneable handle for asking a listener whether it listens on a target, and for removing or resynchronising one while it runs.
- Firestore
Listener Params - Firestore
Listener Params Init - Required fields of
FirestoreListenerParams; convert withFirestoreListenerParams::fromor.into(). - Firestore
Listener Target - Firestore
Listener Target Params - Firestore
Listener Target Params Init - Required fields of
FirestoreListenerTargetParams; convert withFirestoreListenerTargetParams::fromor.into(). - Firestore
Listener Token - Firestore
MemListen State Storage - Firestore
Memory Cache Backend - An in-memory cache backend, backed by the moka cache.
- Firestore
Memory Cache Kind - The in-memory backend flavour. See
FirestoreCache::memory. - Firestore
Memory Cache Options - Tuning options for
FirestoreMemoryCacheBackend. - Firestore
Operation Wait Options - How long long-running Firestore operations are polled for before giving up, shared by index sync and bulk delete.
- Firestore
Operation Wait Options Init - Required fields of
FirestoreOperationWaitOptions; convert withFirestoreOperationWaitOptions::fromor.into(). - Firestore
Parsed Reference - Firestore
Partition - Represents a single partition of a query.
- Firestore
Partition Init - Required fields of
FirestorePartition; convert withFirestorePartition::fromor.into(). - Firestore
Partition Query Params - Parameters for a partitioned query.
- Firestore
Partition Query Params Init - Required fields of
FirestorePartitionQueryParams; convert withFirestorePartitionQueryParams::fromor.into(). - Firestore
Persistent Cache Backend - A disk-backed cache, storing documents as protobuf in a redb database with one table per collection.
- Firestore
Persistent Cache Kind - The persistent backend flavour. See
FirestoreCache::persistent. - Firestore
Persistent Cache Options - Tuning options for
FirestorePersistentCacheBackend. - Firestore
Plan Summary - A summary of the query plan used by Firestore to execute a query.
- Firestore
Plan Summary Init - Required fields of
FirestorePlanSummary; convert withFirestorePlanSummary::fromor.into(). - Firestore
Query Filter Composite - A composite filter that combines multiple
FirestoreQueryFilters. - Firestore
Query Filter Composite Init - Required fields of
FirestoreQueryFilterComposite; convert withFirestoreQueryFilterComposite::fromor.into(). - Firestore
Query Order - Specifies an ordering for query results based on a field.
- Firestore
Query Order Init - Required fields of
FirestoreQueryOrder; convert withFirestoreQueryOrder::fromor.into(). - Firestore
Query Params - Parameters for constructing and executing a Firestore query.
- Firestore
Query Params Init - Required fields of
FirestoreQueryParams; convert withFirestoreQueryParams::fromor.into(). - Firestore
Reference - Firestore
Request Options - Options attached to an individual Firestore server request.
- Firestore
Request Options Init - Required fields of
FirestoreRequestOptions; convert withFirestoreRequestOptions::fromor.into(). - Firestore
Request Tag - A single request tag attached to a Firestore request.
- Firestore
Simple Batch Write Options - Firestore
Simple Batch Write Options Init - Required fields of
FirestoreSimpleBatchWriteOptions; convert withFirestoreSimpleBatchWriteOptions::fromor.into(). - Firestore
Simple Batch Writer - Firestore
Streaming Batch Write Options - Firestore
Streaming Batch Write Options Init - Required fields of
FirestoreStreamingBatchWriteOptions; convert withFirestoreStreamingBatchWriteOptions::fromor.into(). - Firestore
Streaming Batch Writer - Firestore
Temp Files Listen State Storage - Firestore
Timestamp - A wrapper around
FirestoreInstantthat is always serialized as a Firestore timestamp value, without needing a#[serde(with)]attribute. - Firestore
Transaction - Firestore
Transaction Data - Firestore
Transaction Options - Options for configuring a Firestore transaction.
- Firestore
Transaction Options Init - Required fields of
FirestoreTransactionOptions; convert withFirestoreTransactionOptions::fromor.into(). - Firestore
Transaction Response - Represents the response from committing a Firestore transaction.
- Firestore
Transaction Response Init - Required fields of
FirestoreTransactionResponse; convert withFirestoreTransactionResponse::fromor.into(). - Firestore
Unrecognised Index Item - One listed index or field resource this crate’s domain model cannot represent, kept for visibility instead of being silently dropped.
- Firestore
Value - Represents a Firestore value, wrapping the underlying gRPC
Valuetype. - Firestore
Vector - Firestore
Vector Index Config - A flat vector index’s configuration, for nearest-neighbor search.
- Firestore
Vector Index Config Init - Required fields of
FirestoreVectorIndexConfig; convert withFirestoreVectorIndexConfig::fromor.into(). - Firestore
With Metadata - A container that pairs a document (or other data
T) with its associated Firestore metadata. - Firestore
Write Result - The result of a Firestore write operation (create, update, delete).
- Firestore
Write Result Init - Required fields of
FirestoreWriteResult; convert withFirestoreWriteResult::fromor.into(). - Parent
Path Builder - A builder for constructing Firestore document paths, typically for parent documents when dealing with sub-collections.
Enums§
- Firestore
Aggregation Operator - Firestore
Cache Collection Load Mode - Determines how a cached collection is populated when the cache starts.
- Firestore
Cache Collection Watch - Which documents of a collection the cache holds and listens to.
- Firestore
Cache Incomplete Collection Policy - Controls whether collections that are not fully preloaded may serve
list/queryrequests from the cache. - Firestore
Cache Invalidation - What one target change asks the backend to drop.
- Firestore
Cache Target Change Action - What a backend should do with the collections a Firestore target change affects.
- Firestore
Cached Value - Represents a value that might be retrieved from the cache.
- Firestore
Consistency Selector - Specifies the consistency guarantee for Firestore read operations.
- Firestore
DbSession Cache Mode - Defines the caching mode for Firestore operations within a session.
- Firestore
Field Override Outcome - A field resource’s single-field index configuration, as read from a listed
ProtoField(gcloud_sdk::google::firestore::admin::v1::Field). - Firestore
Field Override Target - What a
FirestoreFieldOverrideapplies to: one named field, or every field in the owned collection group. - Firestore
Field Transform Type - Defines the specific type of transformation to apply to a field.
- Firestore
Field TtlOutcome - A field resource’s TTL configuration, as read from a listed
ProtoFieldthat carries one. - Firestore
Field TtlState - The lifecycle state Firestore reports for a listed field’s TTL configuration.
- Firestore
Find Nearest Distance Measure - Specifies the distance measure for vector similarity searches.
- Firestore
Index Deletes Withheld Reason - Why a pruning
.sync()sent none of its planned index deletes. - Firestore
Index Field Mode - How a single field participates in an index.
- Firestore
Index Query Scope - Whether an index serves queries against one collection or a collection-group query across every collection with the same ID anywhere under the database.
- Firestore
Index State - The lifecycle state Firestore reports for a listed composite index.
- Firestore
Index Sync Skip Reason - Why a
.sync()returned without contacting Firestore. - Firestore
Listener Target Resume Type - Firestore
Query Collection - Specifies the target collection(s) for a Firestore query.
- Firestore
Query Cursor - Represents a cursor for paginating query results.
- Firestore
Query Direction - The direction for ordering query results.
- Firestore
Query Filter - Represents a filter condition for a Firestore query.
- Firestore
Query Filter Compare - A field filter that compares a field to a value using a specific operator.
The first
Stringargument in each variant is the field path. TheFirestoreValueis the value to compare against. - Firestore
Query Filter Composite Operator - The operator for combining filters in a
FirestoreQueryFilterComposite. - Firestore
Query Filter Unary - A unary filter that applies an operation to a single field.
- Firestore
Target Type - Firestore
Transaction Mode - Defines the mode of a Firestore transaction.
- Firestore
Transform Server Value - Specifies a server-generated value for a field transformation.
- Firestore
Write Precondition - A precondition on a document, used for conditional write operations in Firestore.
Constants§
- FIREBASE_
DEFAULT_ DATABASE_ ID - The default database ID for Firestore, which is
"(default)". - FIRESTORE_
CACHE_ DEFAULT_ LISTENER_ TARGET_ BASE - The first Firestore listener target ID assigned to cached collections.
- FIRESTORE_
CACHE_ DEFAULT_ NAME - The cache name used when none is given.
Traits§
- Firestore
Batch Writer - Sends a queued batch of writes to Firestore. Implemented by
FirestoreSimpleBatchWriterandFirestoreStreamingBatchWriter, which differ in how they send the writes and whatWriteResultthey return; seeFirestoreBatch::writefor the call callers actually make. - Firestore
Cache Backend - Defines the contract for a Firestore cache backend.
- Firestore
Cache Backend Kind - Describes a cache backend flavour - in-memory or persistent - for
FirestoreCacheBuilder. - Firestore
Cache Docs ByPath Support - Defines support for retrieving and updating cached documents by their full path.
- Firestore
Resume State Storage - Stores where each listener target should resume from, so a listener picks up where it left off rather than replaying everything.
- Firestore
Transaction Ops - Queues writes on a
FirestoreTransactionor onFirestoreTransactionData- both stage writes the same way, which is why this is a trait rather than inherent methods on either type. Nothing here talks to Firestore: writes are only sent once the transaction is committed. - Value
Struct - Re-export of
rvstruct::ValueStruct.
Functions§
- firestore_
doc_ get_ field_ by_ path - Retrieves a field’s value from a Firestore document using a dot-separated path.
- firestore_
document_ from_ map - Builds a Firestore document named
document_pathdirectly from a(field name, value)iterator, bypassingSerialize. - firestore_
document_ from_ serializable - Serializes
objectinto a Firestore document nameddocument_path. - firestore_
document_ to_ serializable - Deserializes a Firestore document into
T. - serialize_
latlng_ for_ firestore - Serializes a struct with
latitudeandlongitudefields as a native FirestoreLatLng. - serialize_
reference_ for_ firestore - Serializes
valueas a Firestore reference value, writing an explicit null forNonewhennone_as_nullis set. - serialize_
timestamp_ for_ firestore - Serializes
valueas a Firestore timestamp value, writing an explicit null forNonewhennone_as_nullis set. - serialize_
vector_ for_ firestore - Serializes
valueas a Firestore vector value, the shape Firestore’s nearest-neighbour queries expect.
Type Aliases§
- Firestore
Document - A type alias for the raw Firestore document representation.
- Firestore
Duration - The type of durations that Firestore reports.
- Firestore
Instant - An exact instant in time, used by this library for Firestore timestamps.
- Firestore
Listen Event - Firestore
Listener Target Change Type - The kind of change a listener reports for one of its targets.
- Firestore
MemCache - Exposes the underlying
mokacache type. Not part of the supported API surface: themokaversion is not covered by this crate’s semver contract. - Firestore
MemCache Options - Exposes the underlying
mokacache builder. Not part of the supported API surface: themokaversion is not covered by this crate’s semver contract. - Firestore
Memory Cache - A ready-to-use in-memory cache.
- Firestore
Persistent Cache - A ready-to-use persistent cache. See
FirestoreMemoryCachefor how to use the alias. - Firestore
Result - A type alias for
std::result::Result<T, FirestoreError>. - Firestore
Shared Cache Backend - A type alias for a thread-safe, shareable Firestore cache backend.
- Firestore
Transaction Id - A type alias for Firestore transaction IDs. Transaction IDs are represented as a vector of bytes.
Attribute Macros§
- async_
trait - Re-export of the
async_traitmacro.
Derive Macros§
- Value
Struct - Re-export of
rvstruct::ValueStruct.