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

61 lines
978 B
JavaScript
Raw Normal View History

/**
* This class stores a database result.
2016-12-20 09:32:17 +00:00
*/
2016-09-26 09:28:47 +00:00
module.exports = new Class
({
/**
* Initilizes the result object.
2016-12-20 09:32:17 +00:00
*/
initialize: function (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++)
this.columnMap[this.columns[i].name] = i;
}
else
this.columnMap = null;
}
/**
* Gets a value from de result.
*
* @param {String} columnName The column name
* @return {Object} The cell value
2016-12-20 09:32:17 +00:00
*/
,get: function (columnName)
{
var columnIndex = this.columnMap[columnName];
return this.data[this.row][columnIndex];
}
/**
* Resets the result iterator.
2016-12-20 09:32:17 +00:00
*/
,reset: function ()
{
this.row = -1;
}
/**
* Moves the internal iterator to the next row.
2016-12-20 09:32:17 +00:00
*/
,next: function ()
{
this.row++;
if (this.row >= this.data.length)
return false;
return true;
}
});