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

96 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
var Result = require ('./result');
/**
* This class stores the database results.
2016-12-20 09:32:17 +00:00
*/
2016-09-26 09:28:47 +00:00
module.exports = new Class
({
results: null
,error: null
/**
* Initilizes the resultset object.
2016-12-20 09:32:17 +00:00
*/
,initialize: function (results, error)
{
this.results = results;
this.error = error;
}
/**
* Gets the query error.
*
2016-12-23 08:57:49 +00:00
* @return {Error} the error or null if no errors hapened
2016-12-20 09:32:17 +00:00
*/
,getError: function ()
{
return this.error;
}
,fetch: function ()
{
2016-10-11 14:45:10 +00:00
if (this.error)
throw this.error;
if (this.results !== null
&& this.results.length > 0)
return this.results.shift ();
return null;
}
/**
* Fetchs the next result from the resultset.
*
* @return {Db.Result} the result or %null if error or there are no more results
2016-12-20 09:32:17 +00:00
*/
,fetchResult: function ()
{
var result = this.fetch ();
if (result !== null)
{
if (result.data instanceof Array)
2016-09-26 09:28:47 +00:00
return new Result (result);
else
return true;
}
return null;
}
/**
* Fetchs the first row from the next resultset.
*
* @return {Array} the row if success, %null otherwise
2016-12-20 09:32:17 +00:00
*/
,fetchRow: function ()
{
var result = this.fetch ();
if (result !== null
&& result.data instanceof Array
&& result.data.length > 0)
return result.data[0];
return null;
}
/**
* Fetchs the first row and column value from the next resultset.
*
* @return {Object} the value if success, %null otherwise
2016-12-20 09:32:17 +00:00
*/
,fetchValue: function ()
{
var row = this.fetchRow ();
if (row instanceof Array && row.length > 0)
return row[0];
return null;
}
});