azure-cosmos-rust
Skill này làm gì
Công cụ này cho phép các chương trình viết bằng Rust tương tác với cơ sở dữ liệu NoSQL Azure Cosmos DB. Bạn có thể tạo, đọc, cập nhật và xóa thông tin lưu trữ trong đó.
Khi nào nên dùng
- ✓Khi chương trình Rust của bạn cần lưu hoặc lấy dữ liệu.
- ✓Khi bạn quản lý thông tin trong một cơ sở dữ liệu phân tán.
- ✓Khi bạn thực hiện các thao tác cơ bản (tạo, đọc, cập nhật, xóa) trên dữ liệu trong Cosmos DB.
Liên kết skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/azure-cosmos-rust/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Làm thế nào để tạo một item mới trong container Cosmos DB bằng Rust?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Chương trình Rust dùng một thư viện đặc biệt (SDK) để kết nối với Azure Cosmos DB. Nó định nghĩa cách dữ liệu nên được cấu trúc và gửi lệnh tới cơ sở dữ liệu để thực hiện các thao tác mong muốn.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Azure Cosmos DB SDK for Rust
Client library for Azure Cosmos DB NoSQL API — globally distributed, multi-model database.
The examples below require a reviewed compatible crate set and replacement of every resource placeholder. Do not use production data for demonstration writes.
Installation
cargo add azure_data_cosmos@=0.37.1 azure_identity@=1.0.0 azure_core@=1.1.0
Environment Variables
export COSMOS_ENDPOINT="https://<account>.documents.azure.com:443/"
export COSMOS_DATABASE="mydb"
export COSMOS_CONTAINER="mycontainer"
Authentication
use azure_identity::DeveloperToolsCredential;
use azure_data_cosmos::{AccountEndpoint, AccountReference, CosmosClient, RoutingStrategy};
let credential = DeveloperToolsCredential::new(None)?;
let endpoint: AccountEndpoint = "https://<account>.documents.azure.com/".parse()?;
let account = AccountReference::with_credential(endpoint, credential.clone());
let client = CosmosClient::builder()
.build(account, RoutingStrategy::ProximityTo("East US".into()))
.await?;
Client Hierarchy
| Client | Purpose | Get From |
|---|---|---|
CosmosClient |
Account-level operations | Direct instantiation |
DatabaseClient |
Database operations | client.database_client() |
ContainerClient |
Container/item operations | database.container_client() |
Core Workflow
Get Database and Container Clients
let database = client.database_client("myDatabase");
let container = database.container_client("myContainer", None).await?;
Create Item
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct Item {
pub id: String,
pub partition_key: String,
pub value: String,
}
let item = Item {
id: "1".into(),
partition_key: "partition1".into(),
value: "hello".into(),
};
container.create_item("partition1", "1", item, None).await?;
Read Item
let response = container.read_item("partition1", "1", None).await?;
let item: Item = response.into_model()?;
Replace Item
let mut item: Item = container.read_item("partition1", "1", None).await?.into_model()?;
item.value = "updated".into();
container.replace_item("partition1", "1", item, None).await?;
Patch Item
// Explicit preview opt-in: cargo add azure_data_cosmos@=0.37.1 --features preview_patch
use azure_data_cosmos::models::{PatchInstructions, PatchOperation};
let patch = PatchInstructions::from(vec![
PatchOperation::set("/value", serde_json::json!("newValue")),
]);
let patched: Item = container.patch_item("partition1", "1", patch, None)
.await?.into_model()?;
Delete Item
container.delete_item("partition1", "1", None).await?;
The reviewed current API uses an async builder/container initialization and a separate explicit item ID. Preview PATCH is not a production-ready guarantee; review its selected strategy, conflict/retry behavior and request-unit cost. Official crate reference.
Key Auth (Optional)
Enable key-based authentication with feature flag:
cargo add azure_data_cosmos@=0.37.1 --features key_auth
Best Practices
- Always specify partition key — required for point reads and writes
- Use
into_model()?— to deserialize responses into your types - Derive
SerializeandDeserialize— for all document types - Use Entra ID auth — prefer
DeveloperToolsCredentialover key auth - Reuse client instances — clients are thread-safe and reusable
The reviewed example set uses azure_data_cosmos 0.37.1 and compatible Azure core/credential crates. Record and commit Cargo.lock; source/API review is not a compiler or live-service test.
Reference Links
| Resource | Link |
|---|---|
| API Reference | https://docs.rs/azure_data_cosmos |
| Source Code | https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/cosmos/azure_data_cosmos |
| crates.io | https://crates.io/crates/azure_data_cosmos |
When to Use
Use when a Rust application needs Cosmos DB NoSQL item CRUD, partition-key point reads, container access or explicitly opted-in preview patching.
Limitations
…
Câu hỏi thường gặp
“Container” trong Cosmos DB là gì?
Hãy coi container như một bảng trong cơ sở dữ liệu truyền thống, nơi bạn lưu các item (giống các hàng dữ liệu).
“CRUD” nghĩa là gì?
CRUD là viết tắt của Create (tạo), Read (đọc), Update (cập nhật) và Delete (xóa), là các thao tác dữ liệu cơ bản.
Tôi có cần hiểu nhiều về cơ sở dữ liệu để dùng không?
Nên có hiểu biết cơ bản về cách cơ sở dữ liệu hoạt động, nhưng thư viện giúp đơn giản hóa nhiều tương tác phức tạp.
Chi tiết
Mô tả gốc của tác giả
Azure Cosmos DB SDK for Rust (NoSQL API). Use for document CRUD, queries, containers, and globally distributed data.
Độ phổ biến
- Sao GitHub
- 48k
- Vị trí xếp hạng
- #3919
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
00-andruia-consultant
48kGiúp agent của bạn bắt đầu hoặc cải thiện các dự án AI. Phân tích mã, gợi ý công cụ và lập kế hoạch hành động bằng tiếng Tây Ban Nha.
007
48kCho phép agent của bạn thực hiện kiểm toán bảo mật và mô hình hóa mối đe dọa. Hữu ích để bảo vệ dự án khỏi các cuộc tấn công và lỗ hổng.
10-andruia-skill-smith
48kGiúp agent của bạn tạo hoặc cải thiện các công cụ AI. Xác định cách công cụ hoạt động, viết tài liệu và kiểm tra cấu trúc.
20-andruia-niche-intelligence
48kGiúp agent của bạn tạo bản tóm tắt về một ngành cụ thể. Hữu ích để hiểu bối cảnh, quy tắc, cách người dùng tương tác và rủi ro của dự án.
Skill tương tự
discrawl
394kCho phép agent của bạn tìm kiếm và tóm tắt kho lưu trữ tin nhắn Discord trên máy, kiểm tra độ mới của dữ liệu và đọc tin nhắn trực tiếp.
clickhouse-io
280kGiúp agent của bạn tối ưu truy vấn và schema trong ClickHouse theo thực hành tốt nhất cho phân tích dữ liệu hiệu năng cao khi truy vấn chậm.
scientific-db-pubmed-database
280kGiúp agent của bạn tìm bài báo khoa học trong lĩnh vực y sinh. Hữu ích cho nghiên cứu cần thông tin y khoa cụ thể.