hedera-web/js/db/result.js

65 lines
1020 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)
{
2017-04-08 11:42:27 +00:00
Object.assign (this, {
data: result.data,
2017-11-02 08:23:55 +00:00
tables: result.tables,
2017-04-08 11:42:27 +00:00
columns: result.columns,
row: -1
});
}
2017-04-08 11:42:27 +00:00
/**
* Moves the pointer to the next row and returns it as an object.
*
* @return {Object} The row or %null if there are no more rows
*/
2017-10-28 15:13:00 +00:00
,fetchRow: function ()
2017-04-08 11:42:27 +00:00
{
if (!this.next ())
return null;
2017-10-25 07:47:32 +00:00
return this.data[this.row];
2017-04-08 11:42:27 +00:00
}
/**
* Returns the current row as an object.
*
2017-04-21 10:53:15 +00:00
* @param {number} rowIndex The row index
2017-04-08 11:42:27 +00:00
* @return {Object} The row or %null if there are no more rows
*/
2017-10-28 15:13:00 +00:00
,getRow: function (rowIndex)
2017-04-08 11:42:27 +00:00
{
2017-10-25 07:47:32 +00:00
return this.data[rowIndex];
2017-04-08 11:42:27 +00:00
}
/**
* 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;
}
});