-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathresultSet.ts
53 lines (43 loc) · 1.01 KB
/
resultSet.ts
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
import { Statistics } from "./statistics"
import { Record } from "./record";
type Header = string[]
/**
* Hold a query result
*/
export class ResultSet {
private _position: number
private _header: Header
private _totalResults: number
private _results: Record[]
private _statistics: Statistics
constructor(resp: any) {
this._position = 0;
this._statistics = new Statistics(resp[1]);
let result = resp[0];
// Empty result set
if (result === null || result.length === 0) {
this._header = [];
this._totalResults = 0;
this._results = [];
} else {
this._header = result[0];
this._totalResults = result.length - 1;
this._results = new Array(this._totalResults);
for (let i = 0; i < this._totalResults; ++i) {
this._results[i] = new Record(this._header, result[i + 1]);
}
}
}
getHeader() {
return this._header;
}
hasNext() {
return this._position < this._totalResults;
}
next() {
return this._results[this._position++];
}
getStatistics() {
return this._statistics;
}
}