-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrecord_row_example.dart
49 lines (38 loc) · 1.25 KB
/
record_row_example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import 'package:influxdb_client/api.dart';
void main() async {
var client = InfluxDBClient(
url: 'http://localhost:8086',
token: 'my-token',
org: 'my-org',
bucket: 'my-bucket',
);
var writeApi = client.getWriteService(WriteOptions().merge(
precision: WritePrecision.s,
batchSize: 100,
flushInterval: 5000,
gzip: true));
var point = Point('point')
.addField('table', 'my-table')
.addField('result', 3.14)
.time(DateTime.now().toUtc());
await writeApi.write(point);
var queryService = client.getQueryService();
var fluxQuery = '''
from(bucket: "my-bucket")
|> range(start: -1d)
|> filter(fn: (r) => r["_measurement"] == "point")
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
''';
var recordStream = await queryService.query(fluxQuery);
var recordValues = [];
var recordRow = [];
await recordStream.forEach((record) {
recordValues.add(record.values.join(","));
recordRow.add(record.row.join(", "));
});
print("-------------------------- record.values ---------------------------");
print(recordValues.join("\n"));
print("---------------------------- record.row ----------------------------");
print(recordRow.join("\n"));
client.close();
}