var Result = require ('./result'); /** * This class stores the database results. */ module.exports = new Class ({ results: null ,error: null /** * Initilizes the resultset object. */ ,initialize: function (results, error) { this.results = results; this.error = error; } /** * Gets the query error. * * @return {Error} the error or null if no errors hapened */ ,getError: function () { return this.error; } ,fetch: function () { 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 */ ,fetchResult: function () { var result = this.fetch (); if (result !== null) { if (result.data instanceof Array) return new Result (result); else return true; } return null; } /** * Fetchs the next result from the resultset. * * @return {Array} The result or %null if error or there are no more results */ ,fetchArray: function () { var result = this.fetch (); if (result !== null) { if (result.data instanceof Array) return result.data; else return true; } return null; } /** * Fetchs the first row from the next resultset. * * @return {Array} the row if success, %null otherwise */ ,fetchRow: function () { var result = this.fetchArray (); if (result === null || result.length === 0) return null; return result[0]; } /** * Fetchs the first row and column value from the next resultset. * * @return {Object} the value if success, %null otherwise */ ,fetchValue: function () { var result = this.fetchResult (); if (result === null || result.data.length === 0 || result.columns.length === 0) return undefined; return result.data[0][result.columns[0].name]; } });