How to make a UUID in DynamoDB?

后端 未结 10 1310
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 18:17

In my db scheme, I need a autoincrement primary key. How I can realize this feature?

PS For access to DynamoDB, I use dynode, module for Node.js.

10条回答
  •  猫巷女王i
    2020-12-01 18:23

    For those coding in Java, DynamoDBMapper can now generate unique UUIDs on your behalf.

    DynamoDBAutoGeneratedKey

    Marks a partition key or sort key property as being auto-generated. DynamoDBMapper will generate a random UUID when saving these attributes. Only String properties can be marked as auto-generated keys.

    Use the DynamoDBAutoGeneratedKey annotation like this

    @DynamoDBTable(tableName="AutoGeneratedKeysExample")
    public class AutoGeneratedKeys { 
        private String id;
    
        @DynamoDBHashKey(attributeName = "Id")
        @DynamoDBAutoGeneratedKey
        public String getId() { return id; }
        public void setId(String id) { this.id = id; } 
    

    As you can see in the example above, you can apply both the DynamoDBAutoGeneratedKey and DynamoDBHashKey annotation to the same attribute to generate a unique hash key.

提交回复
热议问题