|
1 | 1 | classdef WriteBuilder < handle
|
2 | 2 |
|
3 | 3 | properties(Access = private)
|
4 |
| - InfluxDB, Points; |
| 4 | + InfluxDB = [] |
| 5 | + Items = {} |
| 6 | + Database = [] |
| 7 | + Precision = 'ms' |
| 8 | + Consistency = [] |
| 9 | + RetentionPolicy = [] |
5 | 10 | end
|
6 | 11 |
|
7 | 12 | methods
|
8 |
| - % Constructor |
9 |
| - function obj = WriteBuilder() |
10 |
| - obj.InfluxDB = []; |
11 |
| - obj.Points = {}; |
12 |
| - end |
13 |
| - |
14 | 13 | % Set the client instance used for execution
|
15 | 14 | function obj = influxdb(obj, influxdb)
|
16 | 15 | obj.InfluxDB = influxdb;
|
17 | 16 | end
|
18 | 17 |
|
19 |
| - % Append points |
| 18 | + % Configure the database |
| 19 | + function obj = database(obj, database) |
| 20 | + obj.Database = database; |
| 21 | + end |
| 22 | + |
| 23 | + % Configure the precision |
| 24 | + function obj = precision(obj, precision) |
| 25 | + obj.Precision = precision; |
| 26 | + end |
| 27 | + |
| 28 | + % Configure the retention policy |
| 29 | + function obj = retention(obj, retention) |
| 30 | + obj.RetentionPolicy = retention; |
| 31 | + end |
| 32 | + |
| 33 | + % Configure the consistency |
| 34 | + function obj = consistency(obj, consistency) |
| 35 | + obj.Consistency = consistency; |
| 36 | + end |
| 37 | + |
| 38 | + % Append points or series |
20 | 39 | function obj = append(obj, varargin)
|
21 | 40 | for i = 1:length(varargin)
|
22 | 41 | item = varargin{i};
|
23 | 42 | for j = 1:length(item)
|
24 |
| - obj.Points{end + 1} = item(j); |
| 43 | + obj.Items{end + 1} = item(j); |
25 | 44 | end
|
26 | 45 | end
|
27 | 46 | end
|
28 | 47 |
|
29 | 48 | % Build line protocol
|
30 | 49 | function str = build(obj)
|
31 | 50 | builder = java.lang.StringBuilder();
|
32 |
| - for i = 1:length(obj.Points) |
33 |
| - point = obj.Points{i}; |
34 |
| - builder.append(point.toLine()); |
| 51 | + for i = 1:length(obj.Items) |
| 52 | + item = obj.Items{i}; |
| 53 | + builder.append(item.toLine(obj.Precision)); |
35 | 54 | builder.append(newline);
|
36 | 55 | end
|
37 | 56 | builder.deleteCharAt(int32(builder.length() - 1));
|
|
43 | 62 | assert(~isempty(obj.InfluxDB), 'execute:clientNotSet', ...
|
44 | 63 | 'the influxdb client is not set for this builder');
|
45 | 64 | lines = obj.build();
|
46 |
| - obj.InfluxDB.runWrite(lines); |
| 65 | + obj.InfluxDB.runWrite(lines, obj.Database, ... |
| 66 | + obj.Precision, obj.RetentionPolicy, obj.Consistency); |
47 | 67 | end
|
48 | 68 | end
|
49 | 69 |
|
|
0 commit comments