influxdata / influxdb-client-js

InfluxDB 2.0 JavaScript client

Home Page:https://influxdata.github.io/influxdb-client-js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code examples are not clear on how to actually save the queried rows to a variable

sylvesterroos opened this issue · comments

Specifications

  • Client Version: 1.33.0
  • InfluxDB Version: latest docker version
  • Platform: Linux

Code sample to reproduce problem

function queryRows() {
  console.log('*** QueryRows ***')
  queryApi.queryRows(fluxQuery, {
    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))
      console.log(
        `${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}`
      )
    },
    error: (error: Error) => {
      console.error(error)
      console.log('\nQueryRows ERROR')
    },
    complete: () => {
      console.log('\nQueryRows SUCCESS')
    },
  })
}

Expected behavior

I expect a result that will show me how to return the queried rows to a variable when calling the function.

Actual behavior

The example only show how to log the row to the console

Additional info

No response

Hi @Pistrie,

thanks for using our client.

Expected behavior

I expect a result that will show me how to return the queried rows to a variable when calling the function.

You can use QueryApi.collectRows() method for this purpose.

Here is an example:

async function collectRows() {

Regards

It works, thanks :)