@ikonintegration/ikapi 4.0.0-alpha19 → 4.0.0-alpha20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikonintegration/ikapi",
3
- "version": "4.0.0-alpha19",
3
+ "version": "4.0.0-alpha20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "main.js",
@@ -154,16 +154,18 @@ export default class IKDBQueryUpdate extends IKDBBaseQuery {
154
154
  if (!expression.ExpressionAttributeNames) expression.ExpressionAttributeNames = {};
155
155
  //build update expression
156
156
  for (let dbKey of Object.keys(this.incrementValues)) {
157
+ let initialKey = ':initial';
157
158
  let appendingKey = (':' + dbKey);
158
159
  let appendingValueKey = ('#' + dbKey);
159
160
  let val = this.incrementValues[dbKey];
160
161
  if (val != undefined) {
161
162
  let last = Object.keys(this.incrementValues).indexOf(dbKey) == (Object.keys(this.incrementValues).length - 1);
162
163
  //last
163
- if (last) expression.UpdateExpression += appendingValueKey + ' =' + appendingValueKey + '+' + appendingKey;
164
- else expression.UpdateExpression += appendingValueKey + ' =' + appendingValueKey + '+' + appendingKey + ', ';
164
+ if (last) expression.UpdateExpression += appendingValueKey + ` = if_not_exists(${appendingValueKey}, :initial) + ${appendingKey}`;
165
+ else expression.UpdateExpression += appendingValueKey + ` = if_not_exists(${appendingValueKey}, :initial) + ${appendingKey}` + ', ';
165
166
  //
166
167
  expression.ExpressionAttributeValues[appendingKey] = Utils.encapsulateForDB(val);
168
+ expression.ExpressionAttributeValues[initialKey] = Utils.encapsulateForDB(0);
167
169
  expression.ExpressionAttributeNames[appendingValueKey] = dbKey;
168
170
  }
169
171
  }