-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.js
53 lines (45 loc) · 1.6 KB
/
result.js
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
50
51
52
53
class Result {
constructor() {
/**
* The return value from a stored procedure call (or series of calls).
* @type {*|Array.<*>}
*/
this.returned = null;
/**
* Array of column metadata. This will always be an array of columns even when the options `useColumnNames` is
* used.
* @type {Array}
*/
this.columns = [];
/**
* Array of row data. If the `useColumnNames` config option is true, each row will be an object with keys and
* values corresponding to column names and values. If `useColumnNames` is false, each row will be an array
* of values with indexes aligned with the `columns` metadata array.
* @type {Array.<Object>|Array.<Array>}
*/
this.rows = [];
}
/**
* Flattens a and merges multiple results into either an array of `Result` or a single `Result` object if only one
* result is discovered. If no `Result` instances are found, a `null` value is returned.
* @param {...Result|Array.<Result>} results - The results to flatten.
* @returns {Result|Array.<Result>}
*/
static flatten(...results) {
let output = [];
for (let r of results) {
if (r) {
if (Array.isArray(r)) {
output.push(...r.filter(r => !!r));
} else {
output.push(r);
}
}
}
if (!output.length) {
return null;
}
return (output.length > 1 ? output : output[0]);
}
}
module.exports = Result;