[−][src]Function serde_dynamo::to_attribute_value
pub fn to_attribute_value<T>(value: T) -> Result<AttributeValue> where
T: Serialize,
Convert a T
into a rusoto_dynamodb::AttributeValue which is rusoto's representation of a
DynamoDb value.
In some circumstances, building rusoto_dynamodb::AttributeValues directly is required.
For example, when generating a key to supply to get_item.
use maplit::hashmap; use serde_dynamo::to_attribute_value; // Create the unique key of the record in DynamoDB in a way rusoto understands let key = hashmap! { "id".into() => to_attribute_value(&user.id)?, }; // And get the record let input = GetItemInput { table_name: "users".to_string(), key: key, ..GetItemInput::default() }; client.get_item(input).await?;
Or when generating attribute values in a query call.
use maplit::hashmap; use serde_dynamo::to_attribute_value; // Declare all of the expression inputs for a query call let expression_attribute_values = hashmap! { ":user_type".to_string() => to_attribute_value(user_type)?, ":last_login".to_string() => to_attribute_value(yesterday)?, }; // And execute the query let input = QueryInput { table_name: "users".to_string(), index_name: Some("by_type_and_last_login".to_string()), key_condition_expression: Some("user_type = :user_type AND last_login > :last_login".to_string()), expression_attribute_values: Some(expression_attribute_values), ..QueryInput::default() }; client.query(input).await?;