Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Aug 8, 2022
1 parent 93abeb9 commit 40ed072
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "firestore"
version = "0.6.0"
version = "0.6.1"
authors = ["Abdulla Abdurakhmanov <me@abdolence.dev>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Library provides a simple API for Google Firestore:
- Support for querying / streaming / listening documents from Firestore;
- Full async based on Tokio runtime;
- Macro that helps you use JSON paths as references to your structure fields;
- Caching Google client based on [gcloud-sdk library](https://github.com/abdolence/gcloud-sdk-rs)
that automatically detects tokens or GKE environment;
- Google client based on [gcloud-sdk library](https://github.com/abdolence/gcloud-sdk-rs)
that automatically detects GKE environment or application default accounts for local development;

## Quick start

Expand Down
88 changes: 85 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,92 @@
//! - Support for querying / streaming / listening documents from Firestore;
//! - Full async based on Tokio runtime;
//! - Macro that helps you use JSON paths as references to your structure fields;
//! - Caching Google client based on [gcloud-sdk library](https://github.com/abdolence/gcloud-sdk-rs)
//! that automatically detects tokens or GKE environment;
//! - Google client based on [gcloud-sdk library](https://github.com/abdolence/gcloud-sdk-rs)
//! that automatically detects GKE environment or application default accounts for local development;
//!
//! Examples available at: https://github.com/abdolence/firestore-rs/tree/master/src/examples
//! ## Example:
//!
//! ```rust,no_run
//! use firestore::*;
//!use serde::{Deserialize, Serialize};
//!
//!pub fn config_env_var(name: &str) -> Result<String, String> {
//! std::env::var(name).map_err(|e| format!("{}: {}", name, e))
//!}
//!
//!// Example structure to play with
//!#[derive(Debug, Clone, Deserialize, Serialize)]
//!struct MyTestStructure {
//! some_id: String,
//! some_string: String,
//! some_num: u64,
//!}
//!
//!#[tokio::main]
//!async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! // Create an instance
//! let db = FirestoreDb::new(&config_env_var("PROJECT_ID")?).await?;
//!
//! const TEST_COLLECTION_NAME: &'static str = "test";
//!
//! let my_struct = MyTestStructure {
//! some_id: "test-1".to_string(),
//! some_string: "Test".to_string(),
//! some_num: 42,
//! };
//!
//! // Remove if it already exist
//! db.delete_by_id(TEST_COLLECTION_NAME, &my_struct.some_id)
//! .await?;
//!
//! // Let's insert some data
//! db.create_obj(TEST_COLLECTION_NAME, &my_struct.some_id, &my_struct)
//! .await?;
//!
//! // Update some field in it
//! let updated_obj = db
//! .update_obj(
//! TEST_COLLECTION_NAME,
//! &my_struct.some_id,
//! &MyTestStructure {
//! some_num: my_struct.some_num + 1,
//! some_string: "updated-value".to_string(),
//! ..my_struct.clone()
//! },
//! Some(paths!(MyTestStructure::{
//! some_num,
//! some_string
//! })),
//! )
//! .await?;
//!
//! println!("Updated object: {:?}", updated_obj);
//!
//! // Get object by id
//! let find_it_again: MyTestStructure =
//! db.get_obj(TEST_COLLECTION_NAME, &my_struct.some_id).await?;
//!
//! println!("Should be the same: {:?}", find_it_again);
//!
//! // Query our data
//! let objects: Vec<MyTestStructure> = db
//! .query_obj(
//! FirestoreQueryParams::new(TEST_COLLECTION_NAME.into()).with_filter(
//! FirestoreQueryFilter::Compare(Some(FirestoreQueryFilterCompare::Equal(
//! path!(MyTestStructure::some_num),
//! find_it_again.some_num.into(),
//! ))),
//! ),
//! )
//! .await?;
//!
//! println!("Now in the list: {:?}", objects);
//!
//! Ok(())
//!}
//! ```
//!
//! All examples available at: [github](https://github.com/abdolence/firestore-rs/tree/master/src/examples)
//!
#![allow(clippy::new_without_default)]
Expand Down

0 comments on commit 40ed072

Please sign in to comment.