diff --git a/lib/cartodb/models/dataview/list.js b/lib/cartodb/models/dataview/list.js index 064a4cdc..cb895429 100644 --- a/lib/cartodb/models/dataview/list.js +++ b/lib/cartodb/models/dataview/list.js @@ -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(', ') - }); -}; +}