Firestore for Rust
Library provides a simple API for Google Firestore based on the official gRPC API:
- Fluent high-level and strongly typed API, the only public API of this library;
- Create or update documents using Rust structures and Serde;
- Support for:
- Querying/streaming docs/objects;
- Listing documents/objects (
stream_allfollows the page tokens for you); - Listening changes from Firestore;
- Transactions;
- Aggregated queries: count, sum, avg;
- Streaming batch writes with automatic throttling to stay under the Firestore write rate limits;
- K-nearest neighbor (KNN) vector search with Euclidean, Cosine and Dot Product measures;
- Query cursors and partition queries;
- Collection group queries and listing collection IDs;
- Server side document transforms: increment, array append/remove, server timestamp;
- Update/delete preconditions;
- Consistency selectors to read at a given time or inside a transaction;
- Explaining queries;
- Request tags to attribute Firestore usage;
- Opt-in request timeouts;
- Full async based on Tokio runtime;
- Macros that help you use your structure fields as Firestore field paths;
- Implements own Serde serializer to Firestore protobuf values;
- Support for multiple database IDs;
- Support for extended datatypes:
- Firestore timestamp as a
FirestoreTimestamptype or with#[serde(with)]attributes (based on jiff); - Lat/Lng;
- References;
- Explicit nulls;
- Firestore timestamp as a
- Caching support for collections and documents:
- In-memory cache;
- Persistent cache;
- Declarative index management behind an opt-in
adminfeature: composite indexes, vector indexes, single-field overrides and TTL policy, planned and synced with one call; - Bulk delete behind the same
adminfeature: removes every document in named collection groups, at any depth across the whole database, in the background; - Works with the Firestore emulator through
FIRESTORE_EMULATOR_HOST, no credentials needed; - Google client based on gcloud-sdk library that automatically detects GCE environment or application default accounts for local development;
Documentation
Please follow to the official website: https://firestore-rust.abdolence.dev.
Upgrading from an older version? See the migration guide.
Quick start
Cargo.toml:
[]
= "0.58"
use *;
use ;
async
If you see no process-level CryptoProvider available, see
Crypto provider error.
Examples
All examples available in the examples directory.
To run an example with environment variables:
PROJECT_ID=<your-google-project-id> cargo
Google authentication
Looks for credentials in the following places, preferring the first location found:
- A JSON file whose path is specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable.
- A JSON file in a location known to the gcloud command-line tool using
gcloud auth application-default login. - On Google Compute Engine, it fetches credentials from the metadata server.
For local development don't confuse gcloud auth login with gcloud auth application-default login,
since the first authorize only gcloud tool to access the Cloud Platform.
See Google authentication for the details.
Other credentials go through FirestoreDb::with_options_auth, which takes the google-cloud-auth credentials
gcloud-sdk re-exports, or a GoogleAuthHeaders. The library re-exports gcloud-sdk as firestore::gcloud_sdk,
so these types need no gcloud-sdk dependency of your own.
See Client instance and lifecycle for the examples.
Upgrading to 0.58
0.58 moves to gcloud-sdk 0.33, which mints the tokens with google-cloud-auth:
FirestoreDb::with_options_token_sourceand the gcloud-sdk token sources are removed,FirestoreDb::with_options_authreplaces them;FirestoreDb::new,with_optionsandwith_options_service_account_key_filekeep their signatures;- gcloud-sdk is re-exported as
firestore::gcloud_sdk; - the new default feature
auth-default-cryptobrings the crypto provider service account keys sign with; - the MSRV is 1.91.
See the migration guide for the details.
How this library is tested
There are integration tests in the tests directory that runs for every commit against the real Firestore instance allocated for testing purposes. Be aware not to introduce huge document reads/updates and collection isolation from other tests.
Licence
Apache Software License (ASL)
Author
Abdulla Abdurakhmanov