From 339b2ec5b49702702235936684e841b04b0bd872 Mon Sep 17 00:00:00 2001 From: Bucky Schwarz Date: Wed, 6 Apr 2022 07:08:09 -0700 Subject: [PATCH 1/2] docs: update query example --- examples/query.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/query.ts b/examples/query.ts index 362cf80be..fe64adb30 100755 --- a/examples/query.ts +++ b/examples/query.ts @@ -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)) @@ -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') }, }) @@ -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') // }, // } From 1a90b4f9d344054c10195c1dc0307ef36328541e Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Wed, 6 Apr 2022 17:03:44 +0200 Subject: [PATCH 2/2] chore(examples): use arrow function callbacks --- examples/influxdb-1.8.ts | 10 +++++----- examples/queryWithParams.ts | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/influxdb-1.8.ts b/examples/influxdb-1.8.ts index 403929dbb..6d2667e8e 100755 --- a/examples/influxdb-1.8.ts +++ b/examples/influxdb-1.8.ts @@ -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) }) @@ -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') }, }) diff --git a/examples/queryWithParams.ts b/examples/queryWithParams.ts index 9188bd4f6..5ca2d7a0d 100755 --- a/examples/queryWithParams.ts +++ b/examples/queryWithParams.ts @@ -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') }, })