0
1
Fork 0
hedera-web-mindshore/js/db/result.js

65 lines
1.0 KiB
JavaScript

/**
* This class stores a database result.
*/
module.exports = new Class({
/**
* Initilizes the result object.
*/
initialize(result) {
this.data = result.data;
this.tables = result.tables;
this.columns = result.columns;
this.row = -1;
if (this.columns) {
this.columnMap = {};
for (var i = 0; i < this.columns.length; i++) {
const col = this.columns[i];
col.index = i;
this.columnMap[col.name] = col;
}
} else
this.columnMap = null;
}
/**
* Gets a value from de result.
*
* @param {String} columnName The column name
* @return {Object} The cell value
*/
,get(columnName) {
return this.data[this.row][columnName];
}
/**
* Gets a row.
*
* @return {Object} The cell value
*/
,getObject() {
return this.data[this.row];
}
/**
* Resets the result iterator.
*/
,reset() {
this.row = -1;
}
/**
* Moves the internal iterator to the next row.
*/
,next() {
this.row++;
if (this.row >= this.data.length)
return false;
return true;
}
});