Last active
January 15, 2025 19:28
-
-
Save daverickdunn/2ec81525aa9ea75c15aa99f310fe2b28 to your computer and use it in GitHub Desktop.
DynamoDB Scan FilterExpression item IN list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At line 13:
I think the correct output would be: