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,26 +12,23 @@ 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) { this._checkOptions(options);
options = options || {};
if (!Array.isArray(options.columns)) {
throw new Error('List expects `columns` array in widget options');
}
BaseDataview.apply(this);
this.query = query; this.query = query;
this.columns = options.columns; this.columns = options.columns;
} }
List.prototype = new BaseDataview(); _checkOptions (options) {
List.prototype.constructor = List; if (!Array.isArray(options.columns)) {
throw new Error('List expects `columns` array in widget options');
}
}
module.exports = List; sql (psql, override, callback) {
List.prototype.sql = function(psql, override, callback) {
if (!callback) { if (!callback) {
callback = override; callback = override;
} }
@ -42,22 +39,23 @@ List.prototype.sql = function(psql, override, callback) {
}); });
return callback(null, listSql); return callback(null, listSql);
}; }
List.prototype.format = function(result) { format (result) {
return { return {
rows: result.rows rows: result.rows
}; };
}; }
List.prototype.getType = function() { getType () {
return TYPE; return TYPE;
}; }
List.prototype.toString = function() { toString () {
return JSON.stringify({ return JSON.stringify({
_type: TYPE, _type: TYPE,
_query: this.query, _query: this.query,
_columns: this.columns.join(', ') _columns: this.columns.join(', ')
}); });
}; };
}