@icgio/icg-utils 1.9.48 → 1.9.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/influxdb.js +16 -16
- package/package.json +1 -1
package/lib/influxdb.js
CHANGED
|
@@ -29,22 +29,22 @@ class Influx {
|
|
|
29
29
|
async query(query_string, cb) {
|
|
30
30
|
const query_api = this.influx_db.getQueryApi(this.org)
|
|
31
31
|
let result = await query_api.queryRaw(query_string)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
skip_empty_lines: true,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
32
|
+
// Split by empty lines into table blocks — each InfluxDB table may have
|
|
33
|
+
// different columns (different tag sets), so parse each with its own headers
|
|
34
|
+
const tables = result.split(/\r?\n\s*\r?\n/).filter((b) => b.trim())
|
|
35
|
+
const parse_table = (csv) =>
|
|
36
|
+
new Promise((resolve, reject) => {
|
|
37
|
+
parse(csv, { columns: true, comment: '#', skip_empty_lines: true, relax_column_count: true }, (err, res) => {
|
|
38
|
+
if (err) reject(err)
|
|
39
|
+
else resolve(res)
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
try {
|
|
43
|
+
const results = await Promise.all(tables.map((t) => parse_table(t)))
|
|
44
|
+
cb({ success: true, body: results.flat() })
|
|
45
|
+
} catch (err) {
|
|
46
|
+
cb({ success: false, body: err })
|
|
47
|
+
}
|
|
48
48
|
}
|
|
49
49
|
async write_points_with_check(points, cb) {
|
|
50
50
|
const write_api = this.influx_db.getWriteApi(this.org, this.bucket)
|