-
Notifications
You must be signed in to change notification settings - Fork 0
/
database_helper.js
36 lines (31 loc) · 1.03 KB
/
database_helper.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
'use strict';
module.change_code = 1;
var OILY_DATA_TABLE_NAME = 'IoTData'; // Table name
// connect to dynamo db
var credentials = {
accessKeyId: 'ABCD1234xxxxxxxxxxxx',
secretAccessKey: 'kjler98774kjergxxxxxxxxxxkhwgerg9842o38'
};
var dynasty = require('dynasty')(credentials);
// connect to dynamo db
function OilyHelper() {}
var oilyDataTable = function() {
return dynasty.table(OILY_DATA_TABLE_NAME);
};
// Read data from Dynamo
OilyHelper.prototype.readOilLevel = function() {
return oilyDataTable().findAll('IoTDevice')
.then(function(result) {
var a = result.length;
console.log(result[0])
var initialLevel = result[0].data.state.reported.Tank_Level;
var finalLevel = result[a - 1].data.state.reported.Tank_Level;
console.log('database tank level initial: ', initialLevel);
console.log('database tank level final: ', finalLevel);
return [initialLevel, finalLevel];
})
.catch(function(error) {
console.log('error from dynamo', error);
});
};
module.exports = OilyHelper;