From 97ad9ceee7954869c352ed746ba0b0cae381ad8a Mon Sep 17 00:00:00 2001 From: Lucas Vas Date: Fri, 9 Jan 2026 00:56:23 -0500 Subject: [PATCH] feat: implement server-side conversions The ValueType enum that we've created can now be converted directly into an AWS DynamoDB AttributeValue type, meaning that storage on the server does not require the application to store serialized maps of data. Benefits of this: queries using secondary indexes, simpler filtering, less storage required per database item, faster parsing. We can also start to move away from the ExpandableInfo struct, as we really just use the HashMap inside it. --- src/common/value_type.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/common/value_type.rs b/src/common/value_type.rs index 982df27..ceb6a36 100644 --- a/src/common/value_type.rs +++ b/src/common/value_type.rs @@ -113,3 +113,31 @@ impl Display for ValueType { write!(f, "{}", str) } } + +#[cfg(feature = "ssr")] +use aws_sdk_dynamodb::types::AttributeValue; + +#[cfg(feature = "ssr")] +impl From<&AttributeValue> for ValueType { + fn from(attr: &AttributeValue) -> Self { + match attr { + AttributeValue::S(s) => ValueType::String(Some(s.clone())), + AttributeValue::N(n) => ValueType::Number(Some(n.clone())), + AttributeValue::L(l) => ValueType::List(Some(l.iter().map(|v| v.into()).collect())), + AttributeValue::M(m) => ValueType::Map(Some(m.iter().map(|(k, v)| (k.clone(), v.into())).collect())), + _ => ValueType::default(), + } + } +} + +#[cfg(feature = "ssr")] +impl Into for ValueType { + fn into(self) -> AttributeValue { + match self { + ValueType::String(s) => AttributeValue::S(s.unwrap_or_default()), + ValueType::Number(n) => AttributeValue::N(n.unwrap_or_default()), + ValueType::List(l) => AttributeValue::L(l.unwrap_or_default().into_iter().map(|v| v.into()).collect()), + ValueType::Map(m) => AttributeValue::M(m.unwrap_or_default().into_iter().map(|(k, v)| (k, v.into())).collect()), + } + } +}