Skip to content

Instantly share code, notes, and snippets.

@daverickdunn
Last active January 15, 2025 19:28
Show Gist options
  • Select an option

  • Save daverickdunn/2ec81525aa9ea75c15aa99f310fe2b28 to your computer and use it in GitHub Desktop.

Select an option

Save daverickdunn/2ec81525aa9ea75c15aa99f310fe2b28 to your computer and use it in GitHub Desktop.
DynamoDB Scan FilterExpression item IN list
const listToObjectMappings = (list) => {
let x = {}
for (var i=0; i<list.length; i++){
x[':' + i.toString()] = list[i]
}
return x
}
let statuses = ['available', 'in-transit', 'delivered']
let mappings = listToObjectMappings(statuses)
let type = 'delivery' // type is just to demonstrate the use of Object.assign to build the 'ExpressionAttributeValues'
let joined = Object.keys(mappings).join(); // string: ":available, :in-transit, :delivered"
query = {
FilterExpression: '#type = :type AND #stat IN (' + joined + ')',
ExpressionAttributeNames: {
'#stat' : 'status',
'#type' : 'type'
},
ExpressionAttributeValues: Object.assign( { ':type': type }, mappings )
}
@Potentii
Copy link
Copy Markdown

At line 13:

let joined = Object.keys(mappings).join(); // string: ":available, :in-transit, :delivered"

I think the correct output would be:

let joined = Object.keys(mappings).join(); // string: ":0, :1, :2"

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