4ossiblellc / dynamodb-update-expression

A small library providing the solution to return the DynamoDB update expression.
MIT License
25 stars 15 forks source link

Remove colon `:` characters from attribute names #8

Closed jramoyo closed 7 years ago

jramoyo commented 7 years ago

Colons :are treated as special characters denoting attribute values. They should be removed when generating expression attribute names and values.

Example:

var original = {
    "prefix:key": "value",
    "prefix:list": ["list value"],
    "prefix:group": {
        "prefix:group:key": "group value"
    }
};

var updates = {
    "prefix:key": "update value",
    "prefix:list": ["new list value"],
    "prefix:group": {
        "prefix:group:key": "update group value"
    },
    "prefix:new:group": {
        "prefix:group:key": "new group value"
    }
};

Should generate the following update expression:

{
    "UpdateExpression": "SET #prefixkey = :prefixkey, #prefixlist = :prefixlist, #prefixgroup.#prefixgroupkey = :prefixgroupprefixgroupkey, #prefixnewgroup = :prefixnewgroup",
    "ExpressionAttributeNames": {
        "#prefixkey": "prefix:key",
        "#prefixlist": "prefix:list",
        "#prefixgroup": "prefix:group",
        "#prefixgroupkey": "prefix:group:key",
        "#prefixnewgroup": "prefix:new:group"
    },
    "ExpressionAttributeValues": {
        ":prefixkey": "update value",
        ":prefixlist": [
            "list value",
            "new list value"
        ],
        ":prefixgroupprefixgroupkey": "update group value",
        ":prefixnewgroup": {
            "prefix:group:key": "new group value"
        }
    }
}
4ossiblellc commented 7 years ago

Thanks for the feedback. Can I ask what is your use case to name the field name as "prefix:key"?

jramoyo commented 7 years ago

We have a CRUD service built on top of DynamoDB which uses : as a delimiter for complex attribute keys.

jramoyo commented 7 years ago

I created a pull request for your review: https://github.com/4ossiblellc/dynamodb-update-expression/pull/9

4ossiblellc commented 7 years ago

Merged the pull request. Thanks for reporting and fixing it.