aws_sdk_dynamodb/types/
_put.rs

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