Skip to content

Commit

Permalink
feat(examples): modify examples so that they can be re-used also in t…
Browse files Browse the repository at this point in the history
…he browser
  • Loading branch information
sranka committed Jan 8, 2020
1 parent e15abc4 commit becf321
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Prerequisites
- [yarn](https://yarnpkg.com/lang/en/docs/install/) installed
- Run `yarn --cwd ..` in this directory
- Run `yarn --cwd .. build` in this directory, the referenced client library is then compiled
- Change variables in [./env.ts](env.ts) to configure connection to your InfluxDB instance. The file can be used as-is against a [docker influxDB v2.0 installation](https://v2.docs.influxdata.com/v2.0/get-started/)
- Examples are executable. If it does not work for you, run `yarn ts-node EXAMPLE.ts`.
- [setupInfluxDB.ts](./setupInfluxDB.ts)
Expand Down
2 changes: 1 addition & 1 deletion examples/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ queryApi.queryRows(fluxQuery, {
const o = tableMeta.toObject(row)
// console.log(JSON.stringify(o, null, 2))
console.log(
`${o._time} ${o._measurement} at ${o.hostname}: ${o._field}=${o._value}`
`${o._time} ${o._measurement} at '${o.location}': ${o._field}=${o._value}`
)
},
error(error: Error) {
Expand Down
3 changes: 2 additions & 1 deletion examples/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

import {InfluxDB, Point} from '@bonitoo-io/influxdb-client'
import {url, token, org, bucket} from './env'
import {hostname} from 'os'

const writeApi = new InfluxDB({url, token}).getWriteApi(org, bucket)
// setup default tags for all writes through this API
writeApi.useDefaultTags({hostname: require('os').hostname()})
writeApi.useDefaultTags({location: hostname()})

console.log('*** WRITE POINTS ***')
// writes points
Expand Down

0 comments on commit becf321

Please sign in to comment.