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) { this._checkOptions(options);
options = options || {};
if (!Array.isArray(options.columns)) { this.query = query;
throw new Error('List expects `columns` array in widget options'); this.columns = options.columns;
} }
BaseDataview.apply(this); _checkOptions (options) {
if (!Array.isArray(options.columns)) {
this.query = query; throw new Error('List expects `columns` array in widget options');
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;
} }
var listSql = listSqlTpl({ sql (psql, override, callback) {
_query: this.query, if (!callback) {
_columns: this.columns.join(', ') callback = override;
}); }
return callback(null, listSql); var listSql = listSqlTpl({
}; _query: this.query,
_columns: this.columns.join(', ')
});
List.prototype.format = function(result) { return callback(null, listSql);
return { }
rows: result.rows
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(', ')
});
};