-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: serde dynamo #40
base: main
Are you sure you want to change the base?
Conversation
let products: Vec<Product> = match res.items { | ||
Some(items) => from_items(items).map_err(|_| | ||
// TODO: Find out correct error from underlying error? | ||
Error::InternalError("Missing name"))?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This already shows a problem: How to map the underlying error to our very specific error Missing name
. I don't think that the underlying serde errors give us that info: https://github.com/zenlist/serde_dynamo/blob/3.0.0-alpha/src/error.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking into the source code, it looks like it just uses serde_dynamo::ErrorImpl::Message
, which might contain the right message - but that's not a guarantee. The best thing would be to write a small sample using the Product struct and serde_dynamo
.
@@ -69,7 +68,8 @@ impl StoreGet for DynamoDBStore { | |||
.await?; | |||
|
|||
Ok(match res.item { | |||
Some(item) => Some(item.try_into()?), | |||
// TODO: Find out correct error from underlying error? | |||
Some(item) => from_item(item).map_err(|_| Error::InternalError("Missing name"))?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem as above.
@@ -84,7 +84,8 @@ impl StorePut for DynamoDBStore { | |||
self.client | |||
.put_item() | |||
.table_name(&self.table_name) | |||
.set_item(Some(product.into())) | |||
// TODO: Can this fail? | |||
.set_item(Some(to_item(product).unwrap())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still have a unit test for that, so we tested that to_item
can serialize a product.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That shouldn't fail since all the fields in a product map to valid DynamoDB attributes.
let next = res.last_evaluated_key.map(|m| m.get_s("id").unwrap()); | ||
let next = res | ||
.last_evaluated_key | ||
.map(|m| from_attribute_value(m["id"].clone()).unwrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if there is a more elegant way to write this?
Hey @hffmnn! Thanks a lot for creating this! I think given that |
🔥 Don't merge: this is rather experimental and up for discussion!
🔥 Note: So far I didn't deploy the API with theses changes so I am not sure, if it works as expected.
No issue, I wanted to try out
serde_dynamo
crate with the experimental support for the official aws-sdk.Description of changes:
serde_dynamo
from_item
andfrom_items
and remove handcraftedFrom
andTryFrom
implementationsserde_dynamo
from_attribute_value
and removesrc/store/dynamodb/ext.rs