2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* 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({
|
2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* Initilizes the result object.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2022-11-16 01:46:44 +00:00
|
|
|
initialize(result) {
|
2015-03-19 19:36:11 +00:00
|
|
|
this.data = result.data;
|
|
|
|
this.tables = result.tables;
|
|
|
|
this.columns = result.columns;
|
2015-01-23 13:09:30 +00:00
|
|
|
this.row = -1;
|
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
if (this.columns) {
|
2015-01-23 13:09:30 +00:00
|
|
|
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
|
2015-03-19 19:36:11 +00:00
|
|
|
this.columnMap = null;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-11-16 01:46:44 +00:00
|
|
|
,get(columnName) {
|
2022-05-28 15:49:46 +00:00
|
|
|
return this.data[this.row][columnName];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a row.
|
|
|
|
*
|
|
|
|
* @return {Object} The cell value
|
|
|
|
*/
|
2022-11-16 01:46:44 +00:00
|
|
|
,getObject() {
|
2022-05-28 15:49:46 +00:00
|
|
|
return this.data[this.row];
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the result iterator.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2022-11-16 01:46:44 +00:00
|
|
|
,reset() {
|
2015-01-23 13:09:30 +00:00
|
|
|
this.row = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves the internal iterator to the next row.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2022-11-16 01:46:44 +00:00
|
|
|
,next() {
|
2015-01-23 13:09:30 +00:00
|
|
|
this.row++;
|
|
|
|
|
|
|
|
if (this.row >= this.data.length)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|