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;
- 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;
- 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.54"
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.
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