# CustomMapper

{% embed url="<https://shiftcode.github.io/dynamo-easy/interfaces/mapper.mapperfortype.html>" %}
technical api doc
{% endembed %}

Scenarios when you need a custom mapper:

* Using objects as partition key or sort key (since DynamoDB only supports \[N]umber | \[S]tring | \[B]inary for such)
* Working with class instances (non-primitives) instead of plain javascript objects (e.g. Dates)
* Storing objects in a DynamoDB set (only N|S|B sets are possible)

A mapper for date objects which would be stored as \[N]umbers could look like this:

{% code title="date-to-number.mapper.ts" %}

```typescript
import { MapperForType, NumberAttribute } from '@shiftcoders/dynamo-easy'

export const dateToNumberMapper: MapperForType<Date, NumberAttribute> = {
  fromDb: attributeValue => new Date(parseInt(attributeValue.N, 10)),
  toDb: propertyValue => ({ N: `${propertyValue.getTime()}` }),
}
```

{% endcode %}
