Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Aug 7, 2023
1 parent 78ac175 commit 9a3c4b4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,40 @@ struct MyTestStructure {

Complete example available [here](examples/generated-document-id.rs).

## Working on dynamic/document level
Sometimes having static structure may restrict you from working with dynamic data,
so there is a way to use Fluent API to work with documents without introducing structures at all.

```rust

let fields: HashMap<String, FirestoreValue> = [
("some_id".to_string(), my_struct.some_id.clone().into()),
(
"some_string".to_string(),
my_struct.some_string.clone().into(),
),
(
"one_more_string".to_string(),
my_struct.one_more_string.clone().into(),
),
("some_num".to_string(), my_struct.some_num.into()),
("created_at".to_string(), my_struct.created_at.into()),
]
.into_iter()
.collect();

let object_returned = db
.fluent()
.insert()
.into(TEST_COLLECTION_NAME)
.document_id(&my_struct.some_id)
.document(FirestoreDb::serialize_map_to_doc("", fields)?)
.execute()
.await?;

```
Full example available [here](examples/dynamic_doc_level_crud.rs).

## Document transformations
The library supports server side document transformations in transactions and batch writes:

Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic_doc_level_crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let object_updated = db
.fluent()
.update()
.fields(paths!(MyTestStructure::{some_num, one_more_string}))
.fields(["some_num", "one_more_string"])
.in_col(TEST_COLLECTION_NAME)
.document(FirestoreDb::serialize_map_to_doc(
db.parent_path(TEST_COLLECTION_NAME, &my_struct.some_id)?,
Expand Down

0 comments on commit 9a3c4b4

Please sign in to comment.