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

65 lines
1.1 KiB
JavaScript
Raw Normal View History

/**
* This class stores a database result.
2022-05-26 06:08:31 +00:00
*/
2022-05-28 15:49:46 +00:00
module.exports = new Class({
/**
* Initilizes the result object.
2022-05-26 06:08:31 +00:00
*/
2022-05-28 15:49:46 +00:00
initialize: function(result) {
this.data = result.data;
this.tables = result.tables;
this.columns = result.columns;
this.row = -1;
2022-05-28 15:49:46 +00:00
if (this.columns) {
this.columnMap = {};
2022-05-28 15:49:46 +00:00
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
2022-05-26 06:08:31 +00:00
*/
2022-05-28 15:49:46 +00:00
,get: function(columnName) {
return this.data[this.row][columnName];
}
/**
* Gets a row.
*
* @return {Object} The cell value
*/
,getObject: function() {
return this.data[this.row];
}
/**
* Resets the result iterator.
2022-05-26 06:08:31 +00:00
*/
2022-05-28 15:49:46 +00:00
,reset: function() {
this.row = -1;
}
/**
* Moves the internal iterator to the next row.
2022-05-26 06:08:31 +00:00
*/
2022-05-28 15:49:46 +00:00
,next: function() {
this.row++;
if (this.row >= this.data.length)
return false;
return true;
}
});