4ossiblellc / dynamodb-update-expression

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

ExpressionAttributeValues must not be empty #14

Closed dermo666 closed 5 years ago

dermo666 commented 6 years ago

in version 0.1.21 I am getting following error while calling dynamodb update: ExpressionAttributeValues must not be empty

This is the object it is trying to update:

{
  "TableName": "product",
  "Key": {
    "id": "ba57689c-24ca-470e-929b-f4c706aa232c"
  },
  "UpdateExpression": "REMOVE #description, #imageUri",
  "ExpressionAttributeNames": {
    "#description": "description",
    "#imageUri": "imageUri"
  ,
  "ExpressionAttributeValues": {}
}

It seems that this code:

    const payload = {
      TableName: this.tableName,
      Key: { id },
      ...DUE.getUpdateExpression(existingItem || { id }, item),
    };

is generating empty ExpressionAttributeValues if there is only REMOVE expression.

4ossiblellc commented 6 years ago

Will get back to you soon.

4ossiblellc commented 6 years ago

Wait. You don't need ExpressionAttributeValues property in the update statement. Just removing the property should work.

snolangps commented 6 years ago

@4ossiblellc is there a way to pass an array to build up the ExpressionAttributeValues?

jazarja commented 6 years ago

@snolangps There is no way to pass your own array to be used in ExpressionAttributesValue. ExpressionAttributesValue will be calculated automatically based on object attribute changes.

What do you want to achieve actually ?

dermo666 commented 6 years ago

What are doing now is that we check whether the DUE.getUpdateExpression(existingItem || { id }, item) returns any ExpressionAttributeValues - something like this:

 const payload = {
  TableName: this.tableName,
  Key: { id },
  ...DUE.getUpdateExpression(existingStoreData || { id }, storeData),
};

if (payload.UpdateExpression === '') {
  return;
}

await this.dynamoDb.update(payload).promise();`
dermo666 commented 6 years ago

If you think that is ok you can close this issue.

4ossiblellc commented 5 years ago

Close this case. I am not sure if it is better to throw an exception in this case. But, I think the result is the same as this.dynamoDb.update function will throw an exception.