#firestore #path #google #gcloud

firestore-path

Firestore路径助手

37个版本 (9个重大更新)

新版本 0.9.25 2024年7月31日
0.9.20 2024年6月28日
0.9.7 2024年3月27日
0.6.0 2023年12月30日

#343数据库接口

Download history 212/week @ 2024-04-15 358/week @ 2024-04-22 265/week @ 2024-04-29 198/week @ 2024-05-06 107/week @ 2024-05-13 222/week @ 2024-05-20 221/week @ 2024-05-27 279/week @ 2024-06-03 271/week @ 2024-06-10 229/week @ 2024-06-17 220/week @ 2024-06-24 223/week @ 2024-07-01 228/week @ 2024-07-08 268/week @ 2024-07-15 253/week @ 2024-07-22 253/week @ 2024-07-29

每月1,016次下载

MIT/Apache

135KB
2K SLoC

firestore-path

Firestore路径助手。

ci crates.io docs.rs license

示例

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"
);

许可协议

许可协议为以下之一

任选其一。

依赖项

~300–770KB
~18K SLoC