influx 5.0.3 → 5.0.7
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/CHANGELOG.md +7 -0
- package/lib/src/backoff/backoff.d.ts +15 -15
- package/lib/src/backoff/backoff.js +2 -1
- package/lib/src/backoff/exponential.d.ts +52 -52
- package/lib/src/backoff/exponential.js +40 -39
- package/lib/src/builder.d.ts +265 -265
- package/lib/src/builder.js +366 -365
- package/lib/src/doc.d.ts +315 -310
- package/lib/src/doc.js +340 -329
- package/lib/src/grammar/ds.d.ts +45 -45
- package/lib/src/grammar/ds.js +56 -55
- package/lib/src/grammar/escape.d.ts +25 -25
- package/lib/src/grammar/escape.js +108 -107
- package/lib/src/grammar/index.d.ts +3 -3
- package/lib/src/grammar/index.js +8 -7
- package/lib/src/grammar/times.d.ts +74 -74
- package/lib/src/grammar/times.js +325 -318
- package/lib/src/host.d.ts +26 -24
- package/lib/src/host.js +34 -32
- package/lib/src/index.d.ts +659 -653
- package/lib/src/index.js +870 -866
- package/lib/src/pool.d.ts +149 -148
- package/lib/src/pool.js +344 -333
- package/lib/src/results.d.ts +118 -119
- package/lib/src/results.js +146 -139
- package/lib/src/schema.d.ts +58 -58
- package/lib/src/schema.js +117 -116
- package/package.json +10 -10
package/lib/src/builder.js
CHANGED
|
@@ -1,365 +1,366 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* @
|
|
58
|
-
* @
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* .
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* -
|
|
75
|
-
* -
|
|
76
|
-
* -
|
|
77
|
-
* -
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* @
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
*
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
*
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
*
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
*
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
*
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
*
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
*
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
*
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
*
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
*
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
*
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
*
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
*
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
*
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* m.name('my_measurement')
|
|
303
|
-
* m.name('my_measurement').policy('one_day')
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
*
|
|
312
|
-
* @
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
*
|
|
321
|
-
* @
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
*
|
|
330
|
-
* @
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
*
|
|
339
|
-
* @
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
.
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var grammar_1 = require("./grammar");
|
|
4
|
+
function regexHasFlags(re) {
|
|
5
|
+
if (typeof re.flags !== 'undefined') {
|
|
6
|
+
return re.flags.length > 0;
|
|
7
|
+
}
|
|
8
|
+
return !(/\/$/).test(re.toString());
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Expression is used to build filtering expressions, like those used in WHERE
|
|
12
|
+
* clauses. It can be used for fluent and safe building of queries using
|
|
13
|
+
* untrusted input.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* e => e
|
|
17
|
+
* .field('host').equals.value('ares.peet.io')
|
|
18
|
+
* .or
|
|
19
|
+
* .field('host').matches(/example\.com$/)
|
|
20
|
+
* .or
|
|
21
|
+
* .expr(e => e
|
|
22
|
+
* .field('country').equals.value('US')
|
|
23
|
+
* .and
|
|
24
|
+
* .field('state').equals.value('WA'));
|
|
25
|
+
*
|
|
26
|
+
* // Generates:
|
|
27
|
+
* // "host" = 'ares.peet.io' OR "host" ~= /example\.com$/ OR \
|
|
28
|
+
* // ("county" = 'US' AND "state" = 'WA')
|
|
29
|
+
*/
|
|
30
|
+
var Expression = (function () {
|
|
31
|
+
function Expression() {
|
|
32
|
+
this.query = [];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Inserts a tag reference into the expression; the name will be
|
|
36
|
+
* automatically escaped.
|
|
37
|
+
* @param {String} name
|
|
38
|
+
* @return {Expression}
|
|
39
|
+
*/
|
|
40
|
+
Expression.prototype.tag = function (name) {
|
|
41
|
+
this.field(name);
|
|
42
|
+
return this;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Inserts a field reference into the expression; the name will be
|
|
46
|
+
* automatically escaped.
|
|
47
|
+
* @param {String} name
|
|
48
|
+
* @return {Expression}
|
|
49
|
+
*/
|
|
50
|
+
Expression.prototype.field = function (name) {
|
|
51
|
+
this.query.push(grammar_1.escape.quoted(name));
|
|
52
|
+
return this;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Inserts a subexpression; invokes the function with a new expression
|
|
56
|
+
* that can be chained on.
|
|
57
|
+
* @param {function(e: Expression): Expression} fn
|
|
58
|
+
* @return {Expression}
|
|
59
|
+
* @example
|
|
60
|
+
* e.field('a').equals.value('b')
|
|
61
|
+
* .or.expr(e =>
|
|
62
|
+
* e.field('b').equals.value('b')
|
|
63
|
+
* .and.field('a').equals.value('c'))
|
|
64
|
+
* .toString()
|
|
65
|
+
* // "a" = 'b' OR ("b" = 'b' AND "a" = 'c')
|
|
66
|
+
*/
|
|
67
|
+
Expression.prototype.exp = function (fn) {
|
|
68
|
+
this.query.push('(' + fn(new Expression()).toString() + ')');
|
|
69
|
+
return this;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Value chains on a value to the expression.
|
|
73
|
+
*
|
|
74
|
+
* - Numbers will be inserted verbatim
|
|
75
|
+
* - Strings will be escaped and inserted
|
|
76
|
+
* - Booleans will be inserted correctly
|
|
77
|
+
* - Dates will be formatted and inserted correctly, including INanoDates.
|
|
78
|
+
* - Regular expressions will be inserted correctly, however an error will
|
|
79
|
+
* be thrown if they contain flags, as regex flags do not work in Influx
|
|
80
|
+
* - Otherwise we'll try to call `.toString()` on the value, throwing
|
|
81
|
+
* if we cannot do so.
|
|
82
|
+
*
|
|
83
|
+
* @param {*} value
|
|
84
|
+
* @return {Expression}
|
|
85
|
+
*/
|
|
86
|
+
Expression.prototype.value = function (value) {
|
|
87
|
+
switch (typeof value) {
|
|
88
|
+
case 'number':
|
|
89
|
+
this.query.push(value);
|
|
90
|
+
return this;
|
|
91
|
+
case 'string':
|
|
92
|
+
this.query.push(grammar_1.escape.stringLit(value));
|
|
93
|
+
return this;
|
|
94
|
+
case 'boolean':
|
|
95
|
+
this.query.push(value ? 'TRUE' : 'FALSE');
|
|
96
|
+
return this;
|
|
97
|
+
default:
|
|
98
|
+
if (value instanceof Date) {
|
|
99
|
+
this.query.push(grammar_1.formatDate(value));
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
if (value instanceof RegExp) {
|
|
103
|
+
if (regexHasFlags(value)) {
|
|
104
|
+
throw new Error('Attempted to query using a regex with flags, ' +
|
|
105
|
+
'but Influx doesn\'t support flags in queries.');
|
|
106
|
+
}
|
|
107
|
+
this.query.push('/' + value.source + '/');
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
if (value && typeof value.toString === 'function') {
|
|
111
|
+
this.query.push(value.toString());
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
throw new Error("node-influx doesn't know how to encode the provided value into a " +
|
|
115
|
+
'query. If you think this is a bug, open an issue here: https://git.io/influx-err');
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
Object.defineProperty(Expression.prototype, "and", {
|
|
119
|
+
/**
|
|
120
|
+
* Chains on an AND clause to the expression.
|
|
121
|
+
* @type {Expression}
|
|
122
|
+
*/
|
|
123
|
+
get: function () {
|
|
124
|
+
this.query.push('AND');
|
|
125
|
+
return this;
|
|
126
|
+
},
|
|
127
|
+
enumerable: true,
|
|
128
|
+
configurable: true
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(Expression.prototype, "or", {
|
|
131
|
+
/**
|
|
132
|
+
* Chains on an OR clause to the expression.
|
|
133
|
+
* @type {Expression}
|
|
134
|
+
*/
|
|
135
|
+
get: function () {
|
|
136
|
+
this.query.push('OR');
|
|
137
|
+
return this;
|
|
138
|
+
},
|
|
139
|
+
enumerable: true,
|
|
140
|
+
configurable: true
|
|
141
|
+
});
|
|
142
|
+
Object.defineProperty(Expression.prototype, "plus", {
|
|
143
|
+
/**
|
|
144
|
+
* Chains on a `+` operator to the expression.
|
|
145
|
+
* @type {Expression}
|
|
146
|
+
*/
|
|
147
|
+
get: function () {
|
|
148
|
+
this.query.push('+');
|
|
149
|
+
return this;
|
|
150
|
+
},
|
|
151
|
+
enumerable: true,
|
|
152
|
+
configurable: true
|
|
153
|
+
});
|
|
154
|
+
Object.defineProperty(Expression.prototype, "times", {
|
|
155
|
+
/**
|
|
156
|
+
* Chains on a `*` operator to the expression.
|
|
157
|
+
* @type {Expression}
|
|
158
|
+
*/
|
|
159
|
+
get: function () {
|
|
160
|
+
this.query.push('*');
|
|
161
|
+
return this;
|
|
162
|
+
},
|
|
163
|
+
enumerable: true,
|
|
164
|
+
configurable: true
|
|
165
|
+
});
|
|
166
|
+
Object.defineProperty(Expression.prototype, "minus", {
|
|
167
|
+
/**
|
|
168
|
+
* Chains on a `-` operator to the expression.
|
|
169
|
+
* @type {Expression}
|
|
170
|
+
*/
|
|
171
|
+
get: function () {
|
|
172
|
+
this.query.push('-');
|
|
173
|
+
return this;
|
|
174
|
+
},
|
|
175
|
+
enumerable: true,
|
|
176
|
+
configurable: true
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(Expression.prototype, "div", {
|
|
179
|
+
/**
|
|
180
|
+
* Chains on a `/` operator to the expression.
|
|
181
|
+
* @type {Expression}
|
|
182
|
+
*/
|
|
183
|
+
get: function () {
|
|
184
|
+
this.query.push('/');
|
|
185
|
+
return this;
|
|
186
|
+
},
|
|
187
|
+
enumerable: true,
|
|
188
|
+
configurable: true
|
|
189
|
+
});
|
|
190
|
+
Object.defineProperty(Expression.prototype, "equals", {
|
|
191
|
+
/**
|
|
192
|
+
* Chains on a `=` conditional to the expression.
|
|
193
|
+
* @type {Expression}
|
|
194
|
+
*/
|
|
195
|
+
get: function () {
|
|
196
|
+
this.query.push('=');
|
|
197
|
+
return this;
|
|
198
|
+
},
|
|
199
|
+
enumerable: true,
|
|
200
|
+
configurable: true
|
|
201
|
+
});
|
|
202
|
+
Object.defineProperty(Expression.prototype, "matches", {
|
|
203
|
+
/**
|
|
204
|
+
* Chains on a `=~` conditional to the expression to match regexes.
|
|
205
|
+
* @type {Expression}
|
|
206
|
+
*/
|
|
207
|
+
get: function () {
|
|
208
|
+
this.query.push('=~');
|
|
209
|
+
return this;
|
|
210
|
+
},
|
|
211
|
+
enumerable: true,
|
|
212
|
+
configurable: true
|
|
213
|
+
});
|
|
214
|
+
Object.defineProperty(Expression.prototype, "doesntMatch", {
|
|
215
|
+
/**
|
|
216
|
+
* Chains on a `!`` conditional to the expression to match regexes.
|
|
217
|
+
* @type {Expression}
|
|
218
|
+
*/
|
|
219
|
+
get: function () {
|
|
220
|
+
this.query.push('!~');
|
|
221
|
+
return this;
|
|
222
|
+
},
|
|
223
|
+
enumerable: true,
|
|
224
|
+
configurable: true
|
|
225
|
+
});
|
|
226
|
+
Object.defineProperty(Expression.prototype, "notEqual", {
|
|
227
|
+
/**
|
|
228
|
+
* Chains on a `!=` conditional to the expression.
|
|
229
|
+
* @type {Expression}
|
|
230
|
+
*/
|
|
231
|
+
get: function () {
|
|
232
|
+
this.query.push('!=');
|
|
233
|
+
return this;
|
|
234
|
+
},
|
|
235
|
+
enumerable: true,
|
|
236
|
+
configurable: true
|
|
237
|
+
});
|
|
238
|
+
Object.defineProperty(Expression.prototype, "gt", {
|
|
239
|
+
/**
|
|
240
|
+
* Chains on a `>` conditional to the expression.
|
|
241
|
+
* @type {Expression}
|
|
242
|
+
*/
|
|
243
|
+
get: function () {
|
|
244
|
+
this.query.push('>');
|
|
245
|
+
return this;
|
|
246
|
+
},
|
|
247
|
+
enumerable: true,
|
|
248
|
+
configurable: true
|
|
249
|
+
});
|
|
250
|
+
Object.defineProperty(Expression.prototype, "gte", {
|
|
251
|
+
/**
|
|
252
|
+
* Chains on a `>=` conditional to the expression.
|
|
253
|
+
* @type {Expression}
|
|
254
|
+
*/
|
|
255
|
+
get: function () {
|
|
256
|
+
this.query.push('>=');
|
|
257
|
+
return this;
|
|
258
|
+
},
|
|
259
|
+
enumerable: true,
|
|
260
|
+
configurable: true
|
|
261
|
+
});
|
|
262
|
+
Object.defineProperty(Expression.prototype, "lt", {
|
|
263
|
+
/**
|
|
264
|
+
* Chains on a `<` conditional to the expression.
|
|
265
|
+
* @type {Expression}
|
|
266
|
+
*/
|
|
267
|
+
get: function () {
|
|
268
|
+
this.query.push('<');
|
|
269
|
+
return this;
|
|
270
|
+
},
|
|
271
|
+
enumerable: true,
|
|
272
|
+
configurable: true
|
|
273
|
+
});
|
|
274
|
+
Object.defineProperty(Expression.prototype, "lte", {
|
|
275
|
+
/**
|
|
276
|
+
* Chains on a `<=` conditional to the expression.
|
|
277
|
+
* @type {Expression}
|
|
278
|
+
*/
|
|
279
|
+
get: function () {
|
|
280
|
+
this.query.push('<=');
|
|
281
|
+
return this;
|
|
282
|
+
},
|
|
283
|
+
enumerable: true,
|
|
284
|
+
configurable: true
|
|
285
|
+
});
|
|
286
|
+
/**
|
|
287
|
+
* Converts the expression into its InfluxQL representation.
|
|
288
|
+
* @return {String}
|
|
289
|
+
*/
|
|
290
|
+
Expression.prototype.toString = function () {
|
|
291
|
+
return this.query.join(' ');
|
|
292
|
+
};
|
|
293
|
+
return Expression;
|
|
294
|
+
}());
|
|
295
|
+
exports.Expression = Expression;
|
|
296
|
+
/**
|
|
297
|
+
* Measurement creates a reference to a particular measurement. You can
|
|
298
|
+
* reference it solely by its name, but you can also specify the retention
|
|
299
|
+
* policy and database it lives under.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* m.name('my_measurement') // "my_measurement"
|
|
303
|
+
* m.name('my_measurement').policy('one_day') // "one_day"."my_measurement"
|
|
304
|
+
* m.name('my_measurement').policy('one_day').db('mydb') // "mydb".one_day"."my_measurement"
|
|
305
|
+
*/
|
|
306
|
+
var Measurement = (function () {
|
|
307
|
+
function Measurement() {
|
|
308
|
+
this.parts = [null, null, null];
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Sets the measurement name.
|
|
312
|
+
* @param {String} name
|
|
313
|
+
* @return {Measurement}
|
|
314
|
+
*/
|
|
315
|
+
Measurement.prototype.name = function (name) {
|
|
316
|
+
this.parts[2] = name;
|
|
317
|
+
return this;
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* Sets the retention policy name.
|
|
321
|
+
* @param {String} retentionPolicy
|
|
322
|
+
* @return {Measurement}
|
|
323
|
+
*/
|
|
324
|
+
Measurement.prototype.policy = function (retentionPolicy) {
|
|
325
|
+
this.parts[1] = retentionPolicy;
|
|
326
|
+
return this;
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* Sets the database name.
|
|
330
|
+
* @param {String} db
|
|
331
|
+
* @return {Measurement}
|
|
332
|
+
*/
|
|
333
|
+
Measurement.prototype.db = function (db) {
|
|
334
|
+
this.parts[0] = db;
|
|
335
|
+
return this;
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* Converts the measurement into its InfluxQL representation.
|
|
339
|
+
* @return {String}
|
|
340
|
+
* @throws {Error} if a measurement name is not provided
|
|
341
|
+
*/
|
|
342
|
+
Measurement.prototype.toString = function () {
|
|
343
|
+
if (!this.parts[2]) {
|
|
344
|
+
throw new Error("You must specify a measurement name to query! Got `" + this.parts[2] + "`");
|
|
345
|
+
}
|
|
346
|
+
return this.parts.filter(function (p) { return !!p; })
|
|
347
|
+
.map(function (p) { return grammar_1.escape.quoted(p); })
|
|
348
|
+
.join('.');
|
|
349
|
+
};
|
|
350
|
+
return Measurement;
|
|
351
|
+
}());
|
|
352
|
+
exports.Measurement = Measurement;
|
|
353
|
+
function parseMeasurement(q) {
|
|
354
|
+
if (typeof q.measurement === 'function') {
|
|
355
|
+
return q.measurement(new Measurement()).toString();
|
|
356
|
+
}
|
|
357
|
+
return q.measurement;
|
|
358
|
+
}
|
|
359
|
+
exports.parseMeasurement = parseMeasurement;
|
|
360
|
+
function parseWhere(q) {
|
|
361
|
+
if (typeof q.where === 'function') {
|
|
362
|
+
return q.where(new Expression()).toString();
|
|
363
|
+
}
|
|
364
|
+
return q.where;
|
|
365
|
+
}
|
|
366
|
+
exports.parseWhere = parseWhere;
|