43 releases (2 stable)

1.0.1 Nov 28, 2024
0.9.29 Oct 30, 2024
0.9.25 Jul 31, 2024
0.9.7 Mar 27, 2024
0.6.0 Dec 30, 2023

#448 in Web programming

Download history 49/week @ 2024-08-17 61/week @ 2024-08-24 47/week @ 2024-08-31 186/week @ 2024-09-07 267/week @ 2024-09-14 83/week @ 2024-09-21 278/week @ 2024-09-28 87/week @ 2024-10-05 41/week @ 2024-10-12 63/week @ 2024-10-19 144/week @ 2024-10-26 85/week @ 2024-11-02 204/week @ 2024-11-09 103/week @ 2024-11-16 148/week @ 2024-11-23 113/week @ 2024-11-30

585 downloads per month

MIT/Apache

140KB
2K SLoC

firestore-path

A Firestore path helper.

ci crates.io docs.rs license

Examples

use firestore_path::{CollectionId, CollectionName, CollectionPath, DatabaseId, DatabaseName, DocumentId, DocumentName, DocumentPath, ProjectId, RootDocumentName};
use std::str::FromStr;

let project_id = ProjectId::from_str("my-project")?;
let database_id = DatabaseId::from_str("my-database")?;
let database_name = DatabaseName::new(project_id, database_id);
assert_eq!(database_name.to_string(), "projects/my-project/databases/my-database");
// assert_eq!(
//     DatabaseName::from_project_id("my-project")?.to_string(),
//     "projects/my-project/databases/(default)"
// );

let root_document_name: RootDocumentName = database_name.root_document_name();
assert_eq!(root_document_name.to_string(), "projects/my-project/databases/my-database/documents");

let collection_name: CollectionName = root_document_name.collection("chatrooms")?;
assert_eq!(collection_name.to_string(), "projects/my-project/databases/my-database/documents/chatrooms");
assert_eq!(collection_name.collection_id().as_ref(), "chatrooms");

let document_name: DocumentName = collection_name.doc("chatroom1")?;
assert_eq!(document_name.to_string(), "projects/my-project/databases/my-database/documents/chatrooms/chatroom1");
assert_eq!(document_name.collection_id().as_ref(), "chatrooms");
assert_eq!(document_name.document_id().as_ref(), "chatroom1");

let collection_id = CollectionId::from_str("messages")?;
let collection_path = CollectionPath::from(collection_id);
assert_eq!(collection_path.to_string(), "messages");

let document_id = DocumentId::from_str("message1")?;
let document_path: DocumentPath = collection_path.doc(document_id)?;
assert_eq!(document_path.to_string(), "messages/message1");

let child_document_name = document_name.doc(document_path)?;
assert_eq!(
    child_document_name.to_string(),
    "projects/my-project/databases/my-database/documents/chatrooms/chatroom1/messages/message1"
);

License

Licensed under either of

at your option.

Dependencies

~260–710KB
~17K SLoC