Expand description
§DynamoDB Table Abstraction
A high-level, type-safe DynamoDB table abstraction for Rust with support for:
- Batch operations (get, write, delete)
- Pagination and streaming
- Global Secondary Indexes (GSI)
- Conditional expressions
- Optimistic locking
- Automatic retry with exponential backoff
§Features
- Type-safe: Leverage Rust’s type system with
serdefor automatic serialization - Async-first: Built on
tokioandaws-sdk-dynamodb - Batch operations: Efficiently process multiple items with automatic batching
- Streaming: Handle large result sets with async streams
- Reserved word validation: Debug-mode checks for DynamoDB reserved words
- GSI support: Query and scan Global Secondary Indexes
§Quick Start
use dynamo_table::{DynamoTable, Error};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
struct User {
user_id: String,
email: String,
name: String,
}
impl DynamoTable for User {
type PK = String;
type SK = String;
const TABLE: &'static str = "users";
const PARTITION_KEY: &'static str = "user_id";
const SORT_KEY: Option<&'static str> = None;
fn partition_key(&self) -> Self::PK {
self.user_id.clone()
}
}
#[tokio::main]
async fn main() -> Result<(), Error> {
// Initialize the global DynamoDB client
let config = aws_config::defaults(aws_config::BehaviorVersion::latest()).load().await;
dynamo_table::init(&config).await;
// Put an item
let user = User {
user_id: "123".to_string(),
email: "user@example.com".to_string(),
name: "John Doe".to_string(),
};
user.add_item().await?;
// Get an item
let retrieved = User::get_item(&"123".to_string(), None).await?;
// Query items
let result = User::query_items(&"123".to_string(), None, None, None).await?;
Ok(())
}Re-exports§
pub use methods::DynamoTableMethods;pub use table::CompositeKey;pub use table::DynamoTable;pub use table::GSITable;
Modules§
Structs§
- Behavior
Version - Behavior version of the client
- Region
- The region to send requests to.
- Region
Provider Chain - Load a region by selecting the first from a series of region providers.
- Retry
Config - Retry configuration for requests.
- SdkConfig
- AWS Shared Configuration
- SdkConfig
Builder - Builder for AWS Shared Configuration
- Timeout
Config - Top-level configuration for timeouts
Enums§
Traits§
- Provide
Region - Provide a
Regionto use with AWS requests
Functions§
- defaults
- Create a config loader with the defaults for the given behavior version.
- dynamodb_
client - Get a reference to the global DynamoDB client
- init
- Initialize the global DynamoDB client with a custom AWS config
- init_
with_ client - Initialize the global DynamoDB client with a custom client instance