1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! # Firestore for Rust
//!
//! Library provides a simple API for Google Firestore:
//! - Create or update documents using Rust structures and Serde;
//! - Support for querying / streaming / listing / listening changes documents from Firestore;
//! - Full async based on Tokio runtime;
//! - Macro that helps you use JSON paths as references to your structure fields;
//! - Implements own Serde serializer to Firestore values;
//! - Supports for Firestore timestamp with `#[serde(with)]`;
//! - 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;
//!
//! ## 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,
//!    one_more_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(),
//!        one_more_string: "Test2".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)]
#![forbid(unsafe_code)]

pub mod errors;
mod value_type;
pub use value_type::*;

mod query;
pub use query::*;

mod list_doc;
pub use list_doc::*;

mod db;
pub use db::*;

mod serde_deserializer;
mod serde_serializer;

mod serde_types_serializers;
pub use serde_types_serializers::*;

mod struct_path_macro;
use crate::errors::FirestoreError;
pub use struct_path_macro::*;

type FirestoreResult<T> = std::result::Result<T, FirestoreError>;