Decorators
Decorators are used to add some metadata to our model classes, relevant to our javascript-to-dynamo mapper.
Last updated
Was this helpful?
Decorators are used to add some metadata to our model classes, relevant to our javascript-to-dynamo mapper.
Last updated
Was this helpful?
To get started with defining a model add the decorator to your typescript class.
Use the @Model
decorator to make it 'mappable' for the dynamo-easy mapper.
You can optionally pass an object containing the table name if you don't want the default table name.
The default table name is built with ${kebabCase(modelName)}s
PartitionKey
SortKey
We provide two decorators to work with global secondary indexes:
GSIPartitionKey
GSISortKey
name: string
define a different name (than the property name) for DynamoDB.
mapper: MapperForType
define a custom mapper (e.g if you want to use a complex object as PartitionKey or SortKey)
The CollectionProperty decorator is used for arrays and sets. It defines if the values should be mapped to [L]ist or [(N|S|B)S]et and stores the information how the Attributes should be parsed.
itemType: ModelConstructor
provide the class of the items inside the collection if they have decorators (this ItemClass also needs the @Model
decorator)
itemMapper: MapperForType
provide a custom mapper to map the complex items of your collection to [S]tring, [N]umber or [B]inary. This is mainly useful if you want to store them in a [S]et.
sorted: boolean
the collection will be stored as [L]ist ([S]et does not preserve the order) no matter if the javascript type is a Set
or an Array
.
name: string
define a different name (than the property name) for DynamoDB.
further information how arrays and sets are mapped:
The DateProperty decorator is just syntactic sugar for @Property({mapper: dateMapper})
all properties decorated with it will be mapped with the default dateMapper or the one you define with updateDynamoEasyConfig({dateMapper: MapperForType})
.
name: string
define a different name (than the property name) for DynamoDB.
The @Transient
decorator can be used to ignore a property when the object is mapped.
To use different table names on different stages the is the right choice.
PartitionKeyUUID
which generates an id using the (peer dependency)
We map all properties (Object.getOwnPropertyNames(objectToMap)
) by default. Use the decorator to prevent a property from being mapped.