diff --git a/package.json b/package.json index 495b0f2..89ed2c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@parana-games/tinymo", - "version": "2.0.5", + "version": "2.0.6", "description": "simple DynamoDB DocumentClient wrapper", "types": "./dist-types/index.d.ts", "main": "./dist/index.js", diff --git a/src/update.ts b/src/update.ts index cd5d715..ddf7d89 100644 --- a/src/update.ts +++ b/src/update.ts @@ -53,8 +53,8 @@ export class Update extends Write { const flatArray = [value].flat() if (createIfNotExists) { - this.setBuilder.addValue(`newList`, []) - this.setBuilder.pair(listName, flatArray, (n, v) => `${n} = list_append(if_not_exists(${n}, :newList), ${v})`) + const valueToken = this.setBuilder.addValue(`newList`, []) + this.setBuilder.pair(listName, flatArray, (n, v) => `${n} = list_append(if_not_exists(${n}, ${valueToken}), ${v})`) } else { this.setBuilder.pair(listName, flatArray, (n, v) => `${n} = list_append(${n}, ${v})`) } diff --git a/test/update.test.ts b/test/update.test.ts index bb80ea6..5c864b7 100644 --- a/test/update.test.ts +++ b/test/update.test.ts @@ -244,4 +244,22 @@ describe('update', () => { ConditionExpression: "#a = :aEqualsConditionValue AND #a = :aEqualsConditionValue2 AND #a = :aEqualsConditionValue3" }) }) + + it('update with 2 empty lists', () => { + const update = new Update('table1850', { PK: 'duplicates' }) + update.addToList('a', [1, 2, 3]) + update.addToList('b', [4, 5, 6]) + expect(update.build()).toStrictEqual({ + "TableName": "table1850", + "Key": { "PK": "duplicates" }, + "UpdateExpression": "SET #a = list_append(if_not_exists(#a, :newList), :a), #b = list_append(if_not_exists(#b, :newList2), :b)", + "ExpressionAttributeNames": { "#a": "a", "#b": "b" }, + "ExpressionAttributeValues": { + ":newList": [], + ":a": [ 1, 2, 3 ], + ":newList2": [], + ":b": [ 4, 5, 6 ] + } + }) + }) }) \ No newline at end of file