-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_chats.js
45 lines (39 loc) · 1.05 KB
/
query_chats.js
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
36
37
38
39
40
41
42
43
44
45
var AWS = require('aws-sdk')
module.exports = function(config, channel, from, to, callback) {
AWS.config.update({
region: "us-east-1",
endpoint: config.aws.endpoints.dynamodb
});
var docClient = new AWS.DynamoDB.DocumentClient();
var params = {
TableName: 'attak-chat',
KeyConditionExpression: '#channel = :channelValue and #timestamp BETWEEN :from AND :to',
ExpressionAttributeNames: {
'#channel': 'channel',
'#timestamp': 'timestamp'
},
ExpressionAttributeValues: {
':channelValue': channel,
':from': from,
':to': to
}
}
var items = []
var queryExecute = function(callback) {
docClient.query(params,function(err, result) {
if (err) {
callback(err)
} else {
console.log(result)
items = items.concat(result.Items)
if (result.LastEvaluatedKey) {
params.ExclusiveStartKey = result.LastEvaluatedKey
queryExecute(callback)
} else {
callback(err, items)
}
}
})
}
queryExecute(callback);
}