awslabs / dynamodb-data-mapper-js

A schema-based data mapper for Amazon DynamoDB.
https://awslabs.github.io/dynamodb-data-mapper-js/
Apache License 2.0
816 stars 106 forks source link

Add a @ttl decorator #98

Open hassankhan opened 6 years ago

hassankhan commented 6 years ago

It would be super useful if we could take advantage of DynamoDB's TTL functionality with a @ttl decorator:

class MyDomainClass {
    @autoGeneratedHashKey()
    id: string;

    @rangeKey({defaultProvider: () => new Date()})
    createdAt: Date;

    @ttl({defaultProvider: () => moment().add(7, 'days').unix() })
    expiresAt: number;
}
jeskew commented 6 years ago

You can do this today by using the @attribute annotation on a property whose type is a Date. Dates are persisted as an epoch timestamp and can be used a TTL field.

hassankhan commented 6 years ago

Does it also set the TimeToLiveSpecification when creating the table via createTable()?

jeskew commented 6 years ago

It doesn’t. The TTL specification for a table can’t be specified for a CreateTable operation but requires a separate call to UpdateTimeToLive. There’s no reason createTable couldn’t call both operations, though.

adrianpanicek commented 4 years ago

Bump

vishnumishra commented 3 years ago

@adrianpanicek @jeskew any. update on this?