dynalite icon indicating copy to clipboard operation
dynalite copied to clipboard

ConditionExpression compares Maps (objects) as "=="

Open VaidotasSm opened this issue 3 years ago • 2 comments

Actual DynamoDB (via Node.js client) supports deep comparison with ConditionExpression and ExpressionAttributeValues:

ConditionExpression: 'xxx = :old_xxx',
ExpressionAttributeValues {
  ':xxx': {...},
  ':old_xxx': {...},
}

This fails in Dynalite.

This happens in db/index.js

function valsEqual(val1, val2) {
  if (Array.isArray(val1) && Array.isArray(val2)) {
    if (val1.length != val2.length) return false
    return val1.every(function(val) { return ~val2.indexOf(val) })
  } else {
    return val1 == val2
  }
}

Potentially quick fix, might be able to do PR myself sometime later, in that case just want to hear some feedback if this is something to be accepted and/or preferred approaches.

VaidotasSm avatar Jul 06 '21 17:07 VaidotasSm

I am also facing the same issue. I am also comparing maps attributes and they are getting compared using ==.

@VaidotasSm Did you find any work around?

saurabhsuniljain avatar Sep 01 '21 18:09 saurabhsuniljain

Same issue there, any update since?

Quick fix yarn add -D lodash.isequal In package.json scripts "postinstall": "node patchDynalite.js"

const fs = require('fs');

const file = './node_modules/dynalite/db/index.js';
fs.writeFileSync(file, fs.readFileSync(file, 'utf8').replace(
`
function valsEqual(val1, val2) {
  if (Array.isArray(val1) && Array.isArray(val2)) {
    if (val1.length != val2.length) return false
    return val1.every(function(val) { return ~val2.indexOf(val) })
  } else {
    return val1 == val2
  }
}
`,
  `const valsEqual = require('lodash.isequal');`,
));

Hideman85 avatar Sep 08 '22 08:09 Hideman85