Mapping Concept
Depending on the value type or the meta data provided from decorators, values are mapped to DynamoDB attributes.
As long as there are no decorators the mapper decides by the value type, to which DynamoDB attribute type it will map.
We map all properties (Object.getOwnPropertyNames(objectToMap)
) by default. Use the @Transient decorator to prevent a property from being mapped.
Empty Values
(null & undefined)
are treated as empty values and are not mapped to an attribute value.
Without Decorator
JS Type
Mapped DynamoDB type
boolean
[BOOL]
string
[S]tring
number
[N]umber
Array
[L]ist
Set<number>
Set<string>
Set<Binary*>
[N]umber[S]et
[S]tring[S]et
[B]inary[S]et
Mixed item types are
only supported with
decorator (see below)
Object
[M]ap
*Binary is not yet supported
Avoid using Set for types other than string|number|Binary without decorator. In this case make sure to add the@CollectionProperty({opt})
Set<CustomType>
would be mapped implicitly to [L]ist of [M]aps. But when parsing the Attribute from DynamoDB, there's no information about the Set and will therefore be parsed to an array. To fix this, use the @CollectionProperty() decorator.
With Decorator
JS Type + CollectionProperty decorator
DynamoDB Type
@CollectionProperty()
Set<string | number>
[L]ist
only list supports different types
@CollectionProperty({ sorted: true })
Set<string>
[L]ist
only list preserves the order
@CollectionProperty({ sorted: true })
Set<number>
[L]ist
only list preserves the order
@CollectionProperty({ itemType: CustomType* })
Set<CustomType>
[L]ist
only makes sense when CustomType is @Model decorated - will be used for mapping
@CollectionProperty({ itemType: CustomType* })
Array<CustomType>
[L]ist
only makes sense when CustomType is @Model decorated - will be used for mapping
@CollectionProperty({itemMapper:CustomTypeMapper})
Set<CustomType>
[(N|S|B)S]et
itemMapper must return N|S|B - Attribute
*If CustomType is string|number|Binary, it will be mapped to the respective [S]et
Generic information is never available due to some serialization limitations of the typescript compiler. Therefore you can provide the itemType to the @CollectionProperty decorator.
Last updated