Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConditionExpression compares Maps (objects) as "==" #142

Open
VaidotasSm opened this issue Jul 6, 2021 · 2 comments
Open

ConditionExpression compares Maps (objects) as "==" #142

VaidotasSm opened this issue Jul 6, 2021 · 2 comments

Comments

@VaidotasSm
Copy link

VaidotasSm commented Jul 6, 2021

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.

@saurabhsuniljain
Copy link

saurabhsuniljain commented Sep 1, 2021

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?

@Hideman85
Copy link

Hideman85 commented Sep 8, 2022

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');`,
));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants