Alias

Define property alias

You can set custom name of the dynamoProperty.

@DynamoEntity()
class Cat {
    @DynamoProperty({
        keyType: KeyType.hash,
        propertyName: "number_id"  // <<<
    })
    id!: number;

    @DynamoProperty({ keyType: KeyType.sort })
    age!: number;

    @DynamoProperty({ keyType: KeyType.attr })
    name!: string;

    constructor(id: number, age: number, name: string) {
        this.id = id;
        this.age = age;
        this.name = name;
    }
}

For example,

const badCat: Cat = new Cat(0, 1, "garfield");
const dynamo: AttributeMap = Mapper.formation(badCat, Cat);

It will formationed as,

{
    "number_id": {   // <<<
        "N": "0"
    },
    "age": {
        "N": "1"
    },
    "name": {
        "S": "garfield"
    }
}

Last updated

Was this helpful?