-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquery.js
executable file
·31 lines (28 loc) · 921 Bytes
/
query.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
#!/usr/bin/env node
const skygear = require('skygear');
const endPoint = process.env.SKYGEAR_ENDPOINT;
const apiKey = process.env.SKYGEAR_APIKEY;
const username = process.env.SKYGEAR_USERNAME;
const password = process.env.SKYGEAR_PASSWORD;
const HealthModel = skygear.Record.extend('piHealth');
skygear.config({
apiKey: apiKey,
endPoint: endPoint
}).then(() => {
console.log('Loging in to Skygear');
skygear.loginWithUsername(username, password).then(() => {
console.log('Sucessfully login');
const q = new skygear.Query(HealthModel);
q.addDescending('_created_at');
skygear.privateDB.query(q).then((results) => {
console.log('<Time> <cupTemp>');
results.map((result) => {
console.log(`<${result.createdAt}> <${result.cpuTemp}>`);
});
process.exit();
}, (err) => {
console.log('Fails to fetch device health');
console.log(err);
});
});
});