dynamodb_crud/lib.rs
1#![doc(
2 html_logo_url = "https://raw.githubusercontent.com/dariocurr/dynamodb-crud/main/assets/logo.png",
3 html_favicon_url = "https://raw.githubusercontent.com/dariocurr/dynamodb-crud/main/assets/logo.png"
4)]
5#![deny(missing_docs)]
6#![deny(warnings)]
7
8//! # DynamoDB CRUD
9//!
10//! A type-safe, ergonomic interface for performing CRUD operations on Amazon DynamoDB tables.
11//!
12//! ## Overview
13//!
14//! This library provides a high-level, type-safe API for interacting with DynamoDB that:
15//! - Prevents common errors at compile time through Rust's type system
16//! - Offers an intuitive builder pattern for constructing operations
17//! - Supports all major DynamoDB operations (Get, Put, Update, Delete, Query, Scan, Batch)
18//! - Handles expression building, pagination, and error handling automatically
19//!
20//! ## Quick Example
21//!
22//! Instead of manually building DynamoDB expression strings and managing placeholders,
23//! use structured types that the compiler validates:
24//!
25//! ```no_run
26//! use aws_sdk_dynamodb::Client;
27//! use dynamodb_crud::{common, write};
28//! use serde_json::Value;
29//!
30//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
31//! # let client = Client::from_conf(aws_sdk_dynamodb::config::Config::builder().build());
32//! // Complex update with multiple operations - no expression strings needed!
33//! let update_item = write::update_item::UpdateItem {
34//! keys: common::key::Keys {
35//! partition_key: common::key::Key {
36//! name: "id".to_string(),
37//! value: Value::String("1".to_string()),
38//! },
39//! ..Default::default()
40//! },
41//! update_expression: write::update_item::UpdateExpressionMap::Combined(vec![
42//! // SET: Update name and increment age atomically
43//! write::update_item::UpdateExpressionMap::Set(
44//! write::update_item::SetInputsMap::Leaves(vec![
45//! ("name".to_string(), write::update_item::SetInput::Assign(Value::String("Jane".to_string()))),
46//! ("age".to_string(), write::update_item::SetInput::Increment(Value::Number(1.into()))),
47//! ]),
48//! ),
49//! // ADD: Add items to a set
50//! write::update_item::UpdateExpressionMap::Add(
51//! write::update_item::AddOrDeleteInputsMap::Leaves(vec![
52//! ("tags".to_string(), Value::Array(vec![
53//! Value::String("new".to_string()),
54//! Value::String("feature".to_string()),
55//! ])),
56//! ]),
57//! ),
58//! ]),
59//! write_args: write::common::WriteArgs {
60//! table_name: "users".to_string(),
61//! ..Default::default()
62//! },
63//! };
64//! // The crate automatically builds: "SET #name = :set0, #age = #age + :set1 ADD #tags :add_or_delete2"
65//! update_item.send(&client).await?;
66//! # Ok(())
67//! # }
68//! ```
69//!
70//! ## Modules
71//!
72//! - [`mod@common`] - Shared utilities for keys, conditions, and selections
73//! - [`mod@read`] - Read operations (GetItem, Query, Scan, BatchGetItem)
74//! - [`mod@write`] - Write operations (PutItem, UpdateItem, DeleteItem, BatchWriteItem)
75
76/// Common utilities for keys, conditions, and attribute selection.
77pub mod common;
78
79/// Read operations for retrieving data from DynamoDB tables.
80///
81/// This module provides operations for:
82/// - Getting individual items by key
83/// - Querying items with key conditions
84/// - Scanning entire tables
85/// - Batch retrieving multiple items
86pub mod read;
87
88/// Write operations for modifying data in DynamoDB tables.
89///
90/// This module provides operations for:
91/// - Putting new items or replacing existing ones
92/// - Updating items with various operations (set, add, remove)
93/// - Deleting items by key
94/// - Batch writing multiple items
95pub mod write;