Skip to main content

rustack_dynamodb_model/
operations.rs

1//! DynamoDB operation enum.
2
3use std::fmt;
4
5/// All supported DynamoDB operations.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum DynamoDBOperation {
8    // Table management
9    /// Create a new table.
10    CreateTable,
11    /// Delete a table.
12    DeleteTable,
13    /// Update a table's settings.
14    UpdateTable,
15    /// Describe a table.
16    DescribeTable,
17    /// List all tables.
18    ListTables,
19
20    // Item CRUD
21    /// Put (insert or replace) an item.
22    PutItem,
23    /// Get an item by primary key.
24    GetItem,
25    /// Update an item.
26    UpdateItem,
27    /// Delete an item by primary key.
28    DeleteItem,
29
30    // Query & Scan
31    /// Query items by key condition.
32    Query,
33    /// Scan all items in a table.
34    Scan,
35
36    // Batch operations
37    /// Batch get items from multiple tables.
38    BatchGetItem,
39    /// Batch write (put/delete) items to multiple tables.
40    BatchWriteItem,
41
42    // Tagging
43    /// Add tags to a resource.
44    TagResource,
45    /// Remove tags from a resource.
46    UntagResource,
47    /// List tags for a resource.
48    ListTagsOfResource,
49
50    // Time to Live
51    /// Describe the TTL settings for a table.
52    DescribeTimeToLive,
53    /// Update the TTL settings for a table.
54    UpdateTimeToLive,
55
56    // Transactions
57    /// Get items atomically across tables.
58    TransactGetItems,
59    /// Write items atomically across tables.
60    TransactWriteItems,
61
62    // Describe
63    /// Describe account limits for DynamoDB.
64    DescribeLimits,
65    /// Describe regional endpoints for DynamoDB.
66    DescribeEndpoints,
67}
68
69impl DynamoDBOperation {
70    /// Returns the AWS operation name string.
71    #[must_use]
72    pub fn as_str(&self) -> &'static str {
73        match self {
74            Self::CreateTable => "CreateTable",
75            Self::DeleteTable => "DeleteTable",
76            Self::UpdateTable => "UpdateTable",
77            Self::DescribeTable => "DescribeTable",
78            Self::ListTables => "ListTables",
79            Self::PutItem => "PutItem",
80            Self::GetItem => "GetItem",
81            Self::UpdateItem => "UpdateItem",
82            Self::DeleteItem => "DeleteItem",
83            Self::Query => "Query",
84            Self::Scan => "Scan",
85            Self::BatchGetItem => "BatchGetItem",
86            Self::BatchWriteItem => "BatchWriteItem",
87            Self::TagResource => "TagResource",
88            Self::UntagResource => "UntagResource",
89            Self::ListTagsOfResource => "ListTagsOfResource",
90            Self::DescribeTimeToLive => "DescribeTimeToLive",
91            Self::UpdateTimeToLive => "UpdateTimeToLive",
92            Self::TransactGetItems => "TransactGetItems",
93            Self::TransactWriteItems => "TransactWriteItems",
94            Self::DescribeLimits => "DescribeLimits",
95            Self::DescribeEndpoints => "DescribeEndpoints",
96        }
97    }
98
99    /// Parse an operation name string into a `DynamoDBOperation`.
100    #[must_use]
101    pub fn from_name(name: &str) -> Option<Self> {
102        match name {
103            "CreateTable" => Some(Self::CreateTable),
104            "DeleteTable" => Some(Self::DeleteTable),
105            "UpdateTable" => Some(Self::UpdateTable),
106            "DescribeTable" => Some(Self::DescribeTable),
107            "ListTables" => Some(Self::ListTables),
108            "PutItem" => Some(Self::PutItem),
109            "GetItem" => Some(Self::GetItem),
110            "UpdateItem" => Some(Self::UpdateItem),
111            "DeleteItem" => Some(Self::DeleteItem),
112            "Query" => Some(Self::Query),
113            "Scan" => Some(Self::Scan),
114            "BatchGetItem" => Some(Self::BatchGetItem),
115            "BatchWriteItem" => Some(Self::BatchWriteItem),
116            "TagResource" => Some(Self::TagResource),
117            "UntagResource" => Some(Self::UntagResource),
118            "ListTagsOfResource" => Some(Self::ListTagsOfResource),
119            "DescribeTimeToLive" => Some(Self::DescribeTimeToLive),
120            "UpdateTimeToLive" => Some(Self::UpdateTimeToLive),
121            "TransactGetItems" => Some(Self::TransactGetItems),
122            "TransactWriteItems" => Some(Self::TransactWriteItems),
123            "DescribeLimits" => Some(Self::DescribeLimits),
124            "DescribeEndpoints" => Some(Self::DescribeEndpoints),
125            _ => None,
126        }
127    }
128}
129
130impl fmt::Display for DynamoDBOperation {
131    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
132        f.write_str(self.as_str())
133    }
134}