forked from influxdata/influxdb-client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueryWithParams.mjs
executable file
·29 lines (26 loc) · 990 Bytes
/
queryWithParams.mjs
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
#!/usr/bin/env node
//////////////////////////////////////////
// Shows how to use InfluxDB query API. //
//////////////////////////////////////////
import {InfluxDB, flux, fluxDuration} from '@influxdata/influxdb-client'
import {url, token, org} from './env.mjs'
const queryApi = new InfluxDB({url, token}).getQueryApi(org)
const start = fluxDuration('-1m')
const measurement = 'temperature'
const fluxQuery = flux`from(bucket:"my-bucket")
|> range(start: ${start})
|> filter(fn: (r) => r._measurement == ${measurement})`
console.log('query:', fluxQuery.toString())
console.log('*** QUERY ROWS ***')
try {
for await (const {values, tableMeta} of queryApi.iterateRows(fluxQuery)) {
const o = tableMeta.toObject(values)
// console.log(JSON.stringify(o, null, 2))
console.log(
`${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}`
)
}
console.log('\nFinished SUCCESS')
} catch (e) {
console.log('\nFinished ERROR')
}