aws_sdk_dynamodb/types/
_update.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3/// <p>Represents a request to perform an <code>UpdateItem</code> operation.</p>
4#[non_exhaustive]
5#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
6pub struct Update {
7    /// <p>The primary key of the item to be updated. Each element consists of an attribute name and a value for that attribute.</p>
8    pub key: ::std::collections::HashMap<::std::string::String, crate::types::AttributeValue>,
9    /// <p>An expression that defines one or more attributes to be updated, the action to be performed on them, and new value(s) for them.</p>
10    pub update_expression: ::std::string::String,
11    /// <p>Name of the table for the <code>UpdateItem</code> request. You can also provide the Amazon Resource Name (ARN) of the table in this parameter.</p>
12    pub table_name: ::std::string::String,
13    /// <p>A condition that must be satisfied in order for a conditional update to succeed.</p>
14    pub condition_expression: ::std::option::Option<::std::string::String>,
15    /// <p>One or more substitution tokens for attribute names in an expression.</p>
16    pub expression_attribute_names: ::std::option::Option<::std::collections::HashMap<::std::string::String, ::std::string::String>>,
17    /// <p>One or more values that can be substituted in an expression.</p>
18    pub expression_attribute_values: ::std::option::Option<::std::collections::HashMap<::std::string::String, crate::types::AttributeValue>>,
19    /// <p>Use <code>ReturnValuesOnConditionCheckFailure</code> to get the item attributes if the <code>Update</code> condition fails. For <code>ReturnValuesOnConditionCheckFailure</code>, the valid values are: NONE and ALL_OLD.</p>
20    pub return_values_on_condition_check_failure: ::std::option::Option<crate::types::ReturnValuesOnConditionCheckFailure>,
21}
22impl Update {
23    /// <p>The primary key of the item to be updated. Each element consists of an attribute name and a value for that attribute.</p>
24    pub fn key(&self) -> &::std::collections::HashMap<::std::string::String, crate::types::AttributeValue> {
25        &self.key
26    }
27    /// <p>An expression that defines one or more attributes to be updated, the action to be performed on them, and new value(s) for them.</p>
28    pub fn update_expression(&self) -> &str {
29        use std::ops::Deref;
30        self.update_expression.deref()
31    }
32    /// <p>Name of the table for the <code>UpdateItem</code> request. You can also provide the Amazon Resource Name (ARN) of the table in this parameter.</p>
33    pub fn table_name(&self) -> &str {
34        use std::ops::Deref;
35        self.table_name.deref()
36    }
37    /// <p>A condition that must be satisfied in order for a conditional update to succeed.</p>
38    pub fn condition_expression(&self) -> ::std::option::Option<&str> {
39        self.condition_expression.as_deref()
40    }
41    /// <p>One or more substitution tokens for attribute names in an expression.</p>
42    pub fn expression_attribute_names(&self) -> ::std::option::Option<&::std::collections::HashMap<::std::string::String, ::std::string::String>> {
43        self.expression_attribute_names.as_ref()
44    }
45    /// <p>One or more values that can be substituted in an expression.</p>
46    pub fn expression_attribute_values(
47        &self,
48    ) -> ::std::option::Option<&::std::collections::HashMap<::std::string::String, crate::types::AttributeValue>> {
49        self.expression_attribute_values.as_ref()
50    }
51    /// <p>Use <code>ReturnValuesOnConditionCheckFailure</code> to get the item attributes if the <code>Update</code> condition fails. For <code>ReturnValuesOnConditionCheckFailure</code>, the valid values are: NONE and ALL_OLD.</p>
52    pub fn return_values_on_condition_check_failure(&self) -> ::std::option::Option<&crate::types::ReturnValuesOnConditionCheckFailure> {
53        self.return_values_on_condition_check_failure.as_ref()
54    }
55}
56impl Update {
57    /// Creates a new builder-style object to manufacture [`Update`](crate::types::Update).
58    pub fn builder() -> crate::types::builders::UpdateBuilder {
59        crate::types::builders::UpdateBuilder::default()
60    }
61}
62
63/// A builder for [`Update`](crate::types::Update).
64#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
65#[non_exhaustive]
66pub struct UpdateBuilder {
67    pub(crate) key: ::std::option::Option<::std::collections::HashMap<::std::string::String, crate::types::AttributeValue>>,
68    pub(crate) update_expression: ::std::option::Option<::std::string::String>,
69    pub(crate) table_name: ::std::option::Option<::std::string::String>,
70    pub(crate) condition_expression: ::std::option::Option<::std::string::String>,
71    pub(crate) expression_attribute_names: ::std::option::Option<::std::collections::HashMap<::std::string::String, ::std::string::String>>,
72    pub(crate) expression_attribute_values: ::std::option::Option<::std::collections::HashMap<::std::string::String, crate::types::AttributeValue>>,
73    pub(crate) return_values_on_condition_check_failure: ::std::option::Option<crate::types::ReturnValuesOnConditionCheckFailure>,
74}
75impl UpdateBuilder {
76    /// Adds a key-value pair to `key`.
77    ///
78    /// To override the contents of this collection use [`set_key`](Self::set_key).
79    ///
80    /// <p>The primary key of the item to be updated. Each element consists of an attribute name and a value for that attribute.</p>
81    pub fn key(mut self, k: impl ::std::convert::Into<::std::string::String>, v: crate::types::AttributeValue) -> Self {
82        let mut hash_map = self.key.unwrap_or_default();
83        hash_map.insert(k.into(), v);
84        self.key = ::std::option::Option::Some(hash_map);
85        self
86    }
87    /// <p>The primary key of the item to be updated. Each element consists of an attribute name and a value for that attribute.</p>
88    pub fn set_key(mut self, input: ::std::option::Option<::std::collections::HashMap<::std::string::String, crate::types::AttributeValue>>) -> Self {
89        self.key = input;
90        self
91    }
92    /// <p>The primary key of the item to be updated. Each element consists of an attribute name and a value for that attribute.</p>
93    pub fn get_key(&self) -> &::std::option::Option<::std::collections::HashMap<::std::string::String, crate::types::AttributeValue>> {
94        &self.key
95    }
96    /// <p>An expression that defines one or more attributes to be updated, the action to be performed on them, and new value(s) for them.</p>
97    /// This field is required.
98    pub fn update_expression(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
99        self.update_expression = ::std::option::Option::Some(input.into());
100        self
101    }
102    /// <p>An expression that defines one or more attributes to be updated, the action to be performed on them, and new value(s) for them.</p>
103    pub fn set_update_expression(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
104        self.update_expression = input;
105        self
106    }
107    /// <p>An expression that defines one or more attributes to be updated, the action to be performed on them, and new value(s) for them.</p>
108    pub fn get_update_expression(&self) -> &::std::option::Option<::std::string::String> {
109        &self.update_expression
110    }
111    /// <p>Name of the table for the <code>UpdateItem</code> request. You can also provide the Amazon Resource Name (ARN) of the table in this parameter.</p>
112    /// This field is required.
113    pub fn table_name(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
114        self.table_name = ::std::option::Option::Some(input.into());
115        self
116    }
117    /// <p>Name of the table for the <code>UpdateItem</code> request. You can also provide the Amazon Resource Name (ARN) of the table in this parameter.</p>
118    pub fn set_table_name(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
119        self.table_name = input;
120        self
121    }
122    /// <p>Name of the table for the <code>UpdateItem</code> request. You can also provide the Amazon Resource Name (ARN) of the table in this parameter.</p>
123    pub fn get_table_name(&self) -> &::std::option::Option<::std::string::String> {
124        &self.table_name
125    }
126    /// <p>A condition that must be satisfied in order for a conditional update to succeed.</p>
127    pub fn condition_expression(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
128        self.condition_expression = ::std::option::Option::Some(input.into());
129        self
130    }
131    /// <p>A condition that must be satisfied in order for a conditional update to succeed.</p>
132    pub fn set_condition_expression(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
133        self.condition_expression = input;
134        self
135    }
136    /// <p>A condition that must be satisfied in order for a conditional update to succeed.</p>
137    pub fn get_condition_expression(&self) -> &::std::option::Option<::std::string::String> {
138        &self.condition_expression
139    }
140    /// Adds a key-value pair to `expression_attribute_names`.
141    ///
142    /// To override the contents of this collection use [`set_expression_attribute_names`](Self::set_expression_attribute_names).
143    ///
144    /// <p>One or more substitution tokens for attribute names in an expression.</p>
145    pub fn expression_attribute_names(
146        mut self,
147        k: impl ::std::convert::Into<::std::string::String>,
148        v: impl ::std::convert::Into<::std::string::String>,
149    ) -> Self {
150        let mut hash_map = self.expression_attribute_names.unwrap_or_default();
151        hash_map.insert(k.into(), v.into());
152        self.expression_attribute_names = ::std::option::Option::Some(hash_map);
153        self
154    }
155    /// <p>One or more substitution tokens for attribute names in an expression.</p>
156    pub fn set_expression_attribute_names(
157        mut self,
158        input: ::std::option::Option<::std::collections::HashMap<::std::string::String, ::std::string::String>>,
159    ) -> Self {
160        self.expression_attribute_names = input;
161        self
162    }
163    /// <p>One or more substitution tokens for attribute names in an expression.</p>
164    pub fn get_expression_attribute_names(
165        &self,
166    ) -> &::std::option::Option<::std::collections::HashMap<::std::string::String, ::std::string::String>> {
167        &self.expression_attribute_names
168    }
169    /// Adds a key-value pair to `expression_attribute_values`.
170    ///
171    /// To override the contents of this collection use [`set_expression_attribute_values`](Self::set_expression_attribute_values).
172    ///
173    /// <p>One or more values that can be substituted in an expression.</p>
174    pub fn expression_attribute_values(mut self, k: impl ::std::convert::Into<::std::string::String>, v: crate::types::AttributeValue) -> Self {
175        let mut hash_map = self.expression_attribute_values.unwrap_or_default();
176        hash_map.insert(k.into(), v);
177        self.expression_attribute_values = ::std::option::Option::Some(hash_map);
178        self
179    }
180    /// <p>One or more values that can be substituted in an expression.</p>
181    pub fn set_expression_attribute_values(
182        mut self,
183        input: ::std::option::Option<::std::collections::HashMap<::std::string::String, crate::types::AttributeValue>>,
184    ) -> Self {
185        self.expression_attribute_values = input;
186        self
187    }
188    /// <p>One or more values that can be substituted in an expression.</p>
189    pub fn get_expression_attribute_values(
190        &self,
191    ) -> &::std::option::Option<::std::collections::HashMap<::std::string::String, crate::types::AttributeValue>> {
192        &self.expression_attribute_values
193    }
194    /// <p>Use <code>ReturnValuesOnConditionCheckFailure</code> to get the item attributes if the <code>Update</code> condition fails. For <code>ReturnValuesOnConditionCheckFailure</code>, the valid values are: NONE and ALL_OLD.</p>
195    pub fn return_values_on_condition_check_failure(mut self, input: crate::types::ReturnValuesOnConditionCheckFailure) -> Self {
196        self.return_values_on_condition_check_failure = ::std::option::Option::Some(input);
197        self
198    }
199    /// <p>Use <code>ReturnValuesOnConditionCheckFailure</code> to get the item attributes if the <code>Update</code> condition fails. For <code>ReturnValuesOnConditionCheckFailure</code>, the valid values are: NONE and ALL_OLD.</p>
200    pub fn set_return_values_on_condition_check_failure(
201        mut self,
202        input: ::std::option::Option<crate::types::ReturnValuesOnConditionCheckFailure>,
203    ) -> Self {
204        self.return_values_on_condition_check_failure = input;
205        self
206    }
207    /// <p>Use <code>ReturnValuesOnConditionCheckFailure</code> to get the item attributes if the <code>Update</code> condition fails. For <code>ReturnValuesOnConditionCheckFailure</code>, the valid values are: NONE and ALL_OLD.</p>
208    pub fn get_return_values_on_condition_check_failure(&self) -> &::std::option::Option<crate::types::ReturnValuesOnConditionCheckFailure> {
209        &self.return_values_on_condition_check_failure
210    }
211    /// Consumes the builder and constructs a [`Update`](crate::types::Update).
212    /// This method will fail if any of the following fields are not set:
213    /// - [`key`](crate::types::builders::UpdateBuilder::key)
214    /// - [`update_expression`](crate::types::builders::UpdateBuilder::update_expression)
215    /// - [`table_name`](crate::types::builders::UpdateBuilder::table_name)
216    pub fn build(self) -> ::std::result::Result<crate::types::Update, ::aws_smithy_types::error::operation::BuildError> {
217        ::std::result::Result::Ok(crate::types::Update {
218            key: self.key.ok_or_else(|| {
219                ::aws_smithy_types::error::operation::BuildError::missing_field(
220                    "key",
221                    "key was not specified but it is required when building Update",
222                )
223            })?,
224            update_expression: self.update_expression.ok_or_else(|| {
225                ::aws_smithy_types::error::operation::BuildError::missing_field(
226                    "update_expression",
227                    "update_expression was not specified but it is required when building Update",
228                )
229            })?,
230            table_name: self.table_name.ok_or_else(|| {
231                ::aws_smithy_types::error::operation::BuildError::missing_field(
232                    "table_name",
233                    "table_name was not specified but it is required when building Update",
234                )
235            })?,
236            condition_expression: self.condition_expression,
237            expression_attribute_names: self.expression_attribute_names,
238            expression_attribute_values: self.expression_attribute_values,
239            return_values_on_condition_check_failure: self.return_values_on_condition_check_failure,
240        })
241    }
242}