Skip to content

Commit

Permalink
Merge pull request #429 from influxdata/bucky_update_query_example
Browse files Browse the repository at this point in the history
docs: update query example
  • Loading branch information
sranka authored Apr 6, 2022
2 parents 67be07b + 1a90b4f commit 205719d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions examples/influxdb-1.8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const point = new Point('mem')
writeAPI.writePoint(point)
writeAPI
.close()
.then(() => console.log('FINISHED'))
.then(() => console.log('Write FINISHED'))
.catch(error => {
console.error(error)
})
Expand All @@ -43,14 +43,14 @@ console.log('*** QUERY ROWS ***')
const queryAPI = influxDB.getQueryApi('')
const query = `from(bucket: "${bucket}") |> range(start: -1h)`
queryAPI.queryRows(query, {
next(row, tableMeta) {
next: (row, tableMeta) => {
const o = tableMeta.toObject(row)
console.log(`${o._time} ${o._measurement} : ${o._field}=${o._value}`)
},
error(error) {
error: (error: Error) => {
console.error(error)
},
complete() {
console.log('\nFinished')
complete: () => {
console.log('\nQuery FINISHED')
},
})
16 changes: 8 additions & 8 deletions examples/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ console.log('*** QUERY ROWS ***')
// Execute query and receive table metadata and rows as they arrive from the server.
// https://docs.influxdata.com/influxdb/v2.1/reference/syntax/annotated-csv/
queryApi.queryRows(fluxQuery, {
next(row: string[], tableMeta: FluxTableMetaData) {
next: (row: string[], tableMeta: FluxTableMetaData) => {
// the following line creates an object for each row
const o = tableMeta.toObject(row)
// console.log(JSON.stringify(o, null, 2))
Expand All @@ -35,11 +35,11 @@ queryApi.queryRows(fluxQuery, {
// `${p._time} ${p._measurement} in '${p.location}' (${p.example}): ${p._field}=${p._value}`
// )
},
error(error: Error) {
error: (error: Error) => {
console.error(error)
console.log('\nFinished ERROR')
},
complete() {
complete: () => {
console.log('\nFinished SUCCESS')
},
})
Expand Down Expand Up @@ -74,14 +74,14 @@ queryApi.queryRows(fluxQuery, {
// queryApi.queryLines(
// fluxQuery,
// {
// error(error: Error) {
// next: (line: string) => {
// console.log(line)
// },
// error: (error: Error) => {
// console.error(error)
// console.log('\nFinished ERROR')
// },
// next(line: string) {
// console.log(line)
// },
// complete() {
// complete: () => {
// console.log('\nFinished SUCCESS')
// },
// }
Expand Down
8 changes: 4 additions & 4 deletions examples/queryWithParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ const measurement = 'temperature'
const fluxQuery = flux`from(bucket:"my-bucket")
|> range(start: ${start})
|> filter(fn: (r) => r._measurement == ${measurement})`
console.log('query:', fluxQuery)
console.log('query:', fluxQuery.toString())

console.log('*** QUERY ROWS ***')
// performs query and receive line table metadata and rows
// https://v2.docs.influxdata.com/v2.0/reference/syntax/annotated-csv/
queryApi.queryRows(fluxQuery, {
next(row: string[], tableMeta: FluxTableMetaData) {
next: (row: string[], tableMeta: FluxTableMetaData) => {
const o = tableMeta.toObject(row)
// console.log(JSON.stringify(o, null, 2))
console.log(
`${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}`
)
},
error(error: Error) {
error: (error: Error) => {
console.error(error)
console.log('\nFinished ERROR')
},
complete() {
complete: () => {
console.log('\nFinished SUCCESS')
},
})

0 comments on commit 205719d

Please sign in to comment.