Results
Extends:
Results are returned from the .query method. It marshals the raw Influx
results into a more palatable, JavaScript-y structure. All query results
are marshalled into a single, flat arrays, and methods are provided to
example grouped results as necessary. The time
column, if included, is
converted into a NanoDate.
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 looks for and returns the first group in the results that matches the provided tags. |
|
public |
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
Group 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.
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[]}>{name:> source
Returns the data grouped into nested arrays, similarly to how it was returned from Influx originally.
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 },
// ...
]
}
])
})