Skip to content

Commit

Permalink
docs: node wizzard async
Browse files Browse the repository at this point in the history
  • Loading branch information
Sciator committed Oct 18, 2022
1 parent 8e08f50 commit e8ec4a4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ fluxQuery = \`from(bucket: "${bucket}")
|> filter(fn: (r) => r._measurement == "measurement1")
|> mean()\`
queryClient.queryRows(fluxQuery, {
next: (row, tableMeta) => {
const tableObject = tableMeta.toObject(row)
async function iterateRowsAggregated() {
for await (const {values, tableMeta} of queryClient.iterateRows(fluxQuery)) {
const tableObject = tableMeta.toObject(values)
console.log(tableObject)
},
error: (error) => {
console.error('\\nError', error)
},
complete: () => {
}
}
iterateRowsAggregated()
.then(() => {
console.log('\\nSuccess')
},
})`
})
.catch(error => {
console.error('\\nError', error)
})`

return (
<>
Expand Down
21 changes: 11 additions & 10 deletions src/homepageExperience/components/steps/nodejs/ExecuteQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ let fluxQuery = \`from(bucket: "${bucket}")
|> range(start: -10m)
|> filter(fn: (r) => r._measurement == "measurement1")\`
queryClient.queryRows(fluxQuery, {
next: (row, tableMeta) => {
const tableObject = tableMeta.toObject(row)
async function iterateRows() {
for await (const {values, tableMeta} of queryClient.iterateRows(fluxQuery)) {
const tableObject = tableMeta.toObject(values)
console.log(tableObject)
},
error: (error) => {
console.error('\\nError', error)
},
complete: () => {
}
}
iterateRows()
.then(() => {
console.log('\\nSuccess')
},
})`
})
.catch(error => {
console.error('\\nError', error)
})`

return (
<>
Expand Down
26 changes: 14 additions & 12 deletions src/writeData/clients/Javascript/execute.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
const queryApi = client.getQueryApi(org)

const query = `<%= query %>`
queryApi.queryRows(query, {
next: (row, tableMeta) => {
const o = tableMeta.toObject(row)

async function iterateRows() {
for await (const {values, tableMeta} of queryClient.iterateRows(query)) {
const o = tableMeta.toObject(values)
console.log(`${o._time} ${o._measurement}: ${o._field}=${o._value}`)
},
error: (error) => {
console.error(error)
console.log('Finished ERROR')
},
complete: () => {
console.log('Finished SUCCESS')
},
})
}
}

iterateRows()
.then(() => {
console.log('\\nSuccess')
})
.catch(error => {
console.error('\\nError', error)
})

26 changes: 14 additions & 12 deletions src/writeData/clients/Javascript/executeFull.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ const client = new InfluxDB({url: '<%= server %>', token: token})
const queryApi = client.getQueryApi(org)

const query = `<%= query %>`
queryApi.queryRows(query, {
next: (row, tableMeta) => {
const o = tableMeta.toObject(row)

async function iterateRows() {
for await (const {values, tableMeta} of queryClient.iterateRows(query)) {
const o = tableMeta.toObject(values)
console.log(`${o._time} ${o._measurement}: ${o._field}=${o._value}`)
},
error: (error) => {
console.error(error)
console.log('Finished ERROR')
},
complete: () => {
console.log('Finished SUCCESS')
},
})
}
}

iterateRows()
.then(() => {
console.log('\\nSuccess')
})
.catch(error => {
console.error('\\nError', error)
})

0 comments on commit e8ec4a4

Please sign in to comment.