Skip to content

Instantly share code, notes, and snippets.

@atimin
Created April 18, 2022 21:17
Show Gist options
  • Save atimin/b774b56ee4655a2c82892746237acb2d to your computer and use it in GitHub Desktop.
Save atimin/b774b56ee4655a2c82892746237acb2d to your computer and use it in GitHub Desktop.
const {Client} = require('reduct-js');
const client = new Client('http://localhost:8383');
client.getBucket('mqtt').then(async (bucket) => {
let data = await bucket.read('mqtt_data');
console.log('Last record: %s', data);
// Get data for the last hour
const stopTime = BigInt(Date.now() * 1000);
const startTime = stopTime - 3_600_000_000n;
const records = await bucket.list('mqtt_data', startTime, stopTime);
for (const record of records) {
data = await bucket.read('mqtt_data', record.timestamp);
console.log('Found record "%s" with timestamp "%d"', data, record.timestamp);
}
}).catch(error => console.error(error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment