Function serde_dynamo::to_attribute_value
source · [−]pub fn to_attribute_value<Tin, Tout>(value: Tin) -> Result<Tout> where
Tin: Serialize,
Tout: AttributeValue,
Expand description
Convert a T
into an AttributeValue
which is rusoto’s representation of a
DynamoDb value.
In some circumstances, building AttributeValue
s directly is required.
For example, when generating a key to supply to get_item.
TODO
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.
TODO
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?;