Auto populate timestamp in DynamoDB

前端 未结 2 1650
北恋
北恋 2021-01-11 17:16

I come from Relational Database background and we have a way to populate timestamp for row creation and update. I am having difficulty finding similar feature for DynamoDB.

相关标签:
2条回答
  • 2021-01-11 17:59

    Java Solution using Annotation (Data modelling package)

    You can use the DynamoDBAutoGeneratedTimestamp annotation.

    @DynamoDBAutoGeneratedTimestamp(strategy=DynamoDBAutoGenerateStrategy.CREATE)
    public Date getCreatedDate() { return createdDate; }
    public void setCreatedDate(Date createdDate) { this.createdDate = createdDate; }
    
    @DynamoDBAutoGeneratedTimestamp(strategy=DynamoDBAutoGenerateStrategy.ALWAYS)
    public Date getLastUpdatedDate() { return lastUpdatedDate; }
    public void setLastUpdatedDate(Date lastUpdatedDate) { this.lastUpdatedDate = lastUpdatedDate; }
    

    DynamoDBAutoGeneratedTimestamp

    0 讨论(0)
  • 2021-01-11 17:59

    There is no such functionality like DEFAULT CURRENT TIMESTAMP or UPDATE CURRENT_TIMESTAMP. You will have to set the date by yourself.

    However if you want to keep track of changes on updates then you can use something like atomic counters.

    Thus on every update your will increment the counter value.

    0 讨论(0)
提交回复
热议问题