forked from RedisGraph/redisgraph.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord.js
80 lines (71 loc) · 1.64 KB
/
record.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
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
"use strict";
/**
* Hold a query record
*/
class Record {
/**
* Builds a Record object
* @constructor
* @param {string[]} header
* @param {object[]} values
*/
constructor(header, values) {
this._header = header;
this._values = values;
}
/**
* Returns a value of the given schema key or in the given position.
* @param {string | number} key (integer)
* @returns {object} Requested value.
*/
get(key) {
let index = key;
if (typeof key === "string") {
index = this._header.indexOf(key);
}
return this._values[index];
}
/**
* Returns a string representation for the value of the given schema key or in the given position.
* @param {string | number} key (integer)
* @returns {string} Requested string representation of the value.
*/
getString(key) {
let index = key;
if (typeof key === "string") {
index = this._header.indexOf(key);
}
let value = this._values[index];
if (value !== undefined && value !== null) {
return value.toString();
}
return null;
}
/**
* @returns {string[]} The record header - List of strings.
*/
keys() {
return this._header;
}
/**
* @returns {object[]} The record values - List of values.
*/
values() {
return this._values;
}
/**
* Returns if the header contains a given key.
* @param {string} key
* @returns {boolean} true if header contains key.
*/
containsKey(key) {
return this._header.includes(key);
}
/**
* @returns {number} The amount of values in the record. (integer)
*/
size() {
return this._header.length;
}
}
module.exports = Record;