aws / aws-sdk-ruby-record

Official repository for the aws-record gem, an abstraction for Amazon DynamoDB.
Apache License 2.0
318 stars 41 forks source link

Nested List Attributes & Type Casting #93

Closed metaskills closed 5 years ago

metaskills commented 5 years ago

I've noticed that when I use a nested list, that integers come back as BigDecimal even tho they are PUT into an item using N type. This means I have to take on the need of type casting my items collection as needed. This seems fine an natural to me but wanted to make sure this was not an issue or if there was some better direction/method to use?

For example, as is now. My collect is using an _list as the name and then in my model I have a list method that iterates over _list data and casts it accordingly. Sound good?

awood45 commented 5 years ago

The problem with aggregate types in this case is that at the DynamoDB level, there’s just one numeric type and the low-level SDK clients use BigDecimal to avoid losing precision.

In individual numeric types, I can use the attribute type to perform type casting. For aggregate types, I don’t want to guess.

So, adding logic to your code to iterate and type cast is fine. If you know you’re making homogenous lists, you could also define a custom type like integer_list_type and write it’s type caster appropriately.

metaskills commented 5 years ago

Thanks for the reply! Gonna close this out too.