-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuery.js
More file actions
35 lines (34 loc) · 1.73 KB
/
Copy pathQuery.js
File metadata and controls
35 lines (34 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#query-property */
/* ===================== Query ===================== */
var params = {
TableName: 'table_name',
IndexName: 'index_name', // optional (if querying an index)
KeyConditionExpression: 'attribute_name = :value', // a string representing a constraint on the attribute
FilterExpression: 'attr_name = :val', // a string representing a constraint on the attribute
ExpressionAttributeNames: { // a map of substitutions for attribute names with special characters
//'#name': 'attribute name'
},
ExpressionAttributeValues: { // a map of substitutions for all attribute values
':value': 'STRING_VALUE',
':val': 0
},
ScanIndexForward: true, // optional (true | false) defines direction of Query in the index
Limit: 0, // optional (limit the number of items to evaluate)
ConsistentRead: false, // optional (true | false)
Select: 'ALL_ATTRIBUTES', // optional (ALL_ATTRIBUTES | ALL_PROJECTED_ATTRIBUTES |
// SPECIFIC_ATTRIBUTES | COUNT)
AttributesToGet: [ // optional (list of specific attribute names to return)
'attribute_name',
// ... more attributes ...
],
ExclusiveStartKey: { // optional (for pagination, returned by prior calls as LastEvaluatedKey)
attribute_name: attribute_value,
// attribute_value (string | number | boolean | null | Binary | DynamoDBSet | Array | Object)
// anotherKey: ...
},
ReturnConsumedCapacity: 'NONE', // optional (NONE | TOTAL | INDEXES)
};
dynamodb.query(params, function(err, data) {
if (err) console.error(err); // an error occurred
else console.log(data); // successful response
});