Use ES6 class syntax

This commit is contained in:
Daniel García Aubert 2017-09-14 17:15:43 +02:00
parent cdc56e703c
commit c8ff61c531

View File

@ -12,52 +12,50 @@ var listSqlTpl = ctx => `select ${ctx._columns} from (${ctx._query}) as _cdb_lis
}
}
*/
module.exports = class List extends BaseDataview{
constructor (query, options = {}) {
super();
function List(query, options) {
options = options || {};
this._checkOptions(options);
if (!Array.isArray(options.columns)) {
throw new Error('List expects `columns` array in widget options');
this.query = query;
this.columns = options.columns;
}
BaseDataview.apply(this);
this.query = query;
this.columns = options.columns;
}
List.prototype = new BaseDataview();
List.prototype.constructor = List;
module.exports = List;
List.prototype.sql = function(psql, override, callback) {
if (!callback) {
callback = override;
_checkOptions (options) {
if (!Array.isArray(options.columns)) {
throw new Error('List expects `columns` array in widget options');
}
}
var listSql = listSqlTpl({
_query: this.query,
_columns: this.columns.join(', ')
});
sql (psql, override, callback) {
if (!callback) {
callback = override;
}
return callback(null, listSql);
};
var listSql = listSqlTpl({
_query: this.query,
_columns: this.columns.join(', ')
});
List.prototype.format = function(result) {
return {
rows: result.rows
return callback(null, listSql);
}
format (result) {
return {
rows: result.rows
};
}
getType () {
return TYPE;
}
toString () {
return JSON.stringify({
_type: TYPE,
_query: this.query,
_columns: this.columns.join(', ')
});
};
};
List.prototype.getType = function() {
return TYPE;
};
List.prototype.toString = function() {
return JSON.stringify({
_type: TYPE,
_query: this.query,
_columns: this.columns.join(', ')
});
};
}