Home Manual Reference Source Test
import {IResults} from 'influx'
public interface | source

IResults

Extends:

Array → IResults

IResults are returned from the InfluxDB#query method. It marshals the raw Influx results into a more palatable, JavaScript-y structure. All query results are marshalled into a single, flat array, and methods are provided to examine grouped results as necessary. The time column, if included, is converted into a INanoDate. If .query() was called on an array of strings, it will return an array of IResults, one result per query string.

Example:

influx.query('select host, cpu, mem from perf').then(results => {
  expect(results).to.deep.equal([
    { host: 'ares.peet.io', cpu: 0.12, mem: 2435 },
    { host: 'ares.peet.io', cpu: 0.10, mem: 2451 },
    // ...
  ])
})

Method Summary

Public Methods
public

group(matcher: Object<String, String>): T[]

Looks for and returns the first group in the results that matches the provided tags.

public

groups(): Array<{name: String, tags: Object<String, String>, rows: T[]}>

Returns the data grouped into nested arrays, similarly to how it was returned from Influx originally.

Public Methods

public group(matcher: Object<String, String>): T[] source

Looks for and returns the first group in the results that matches the provided tags.

If you've used lodash or underscore, we do something quite similar to their object matching: for every row in the results, if it contains tag values matching the requested object, we return it.

Params:

NameTypeAttributeDescription
matcher Object<String, String>

Return:

T[]

Example:

// Matching tags sets in queries:
influx.query('select * from perf group by host').then(results => {
  expect(results.group({ host: 'ares.peet.io'})).to.deep.equal([
    { host: 'ares.peet.io', cpu: 0.12, mem: 2435 },
    { host: 'ares.peet.io', cpu: 0.10, mem: 2451 },
    // ...
  ])

  expect(results.group({ host: 'box1.example.com'})).to.deep.equal([
    { host: 'box1.example.com', cpu: 0.54, mem: 8420 },
    // ...
  ])
})

public groups(): Array<{name: String, tags: Object<String, String>, rows: T[]}> source

Returns the data grouped into nested arrays, similarly to how it was returned from Influx originally.

Return:

Array<{name: String, tags: Object<String, String>, rows: T[]}>

Example:

influx.query('select * from perf group by host').then(results => {
  expect(results.groups()).to.deep.equal([
    {
      name: 'perf',
      tags: { host: 'ares.peet.io' },
      rows: [
        { host: 'ares.peet.io', cpu: 0.12, mem: 2435 },
        { host: 'ares.peet.io', cpu: 0.10, mem: 2451 },
        // ...
      ]
    }
    {
      name: 'perf',
      tags: { host: 'box1.example.com' },
      rows: [
        { host: 'box1.example.com', cpu: 0.54, mem: 8420 },
        // ...
      ]
    }
  ])
})