diff --git a/lib/cartodb/models/dataview/list.js b/lib/cartodb/models/dataview/list.js index 33993777..a54c660f 100644 --- a/lib/cartodb/models/dataview/list.js +++ b/lib/cartodb/models/dataview/list.js @@ -1,11 +1,9 @@ -var dot = require('dot'); -dot.templateSettings.strip = false; +const BaseDataview = require('./base'); +const debug = require('debug')('windshaft:dataview:list'); -var BaseWidget = require('./base'); +const TYPE = 'list'; -var TYPE = 'list'; - -var listSqlTpl = dot.template('select {{=it._columns}} from ({{=it._query}}) as _cdb_list'); +const listSqlTpl = ctx => `select ${ctx.columns} from (${ctx.query}) as _cdb_list`; /** { @@ -15,52 +13,52 @@ var listSqlTpl = dot.template('select {{=it._columns}} from ({{=it._query}}) as } } */ +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; } - BaseWidget.apply(this); - - this.query = query; - this.columns = options.columns; -} - -List.prototype = new BaseWidget(); -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 dataview options'); + } } - var listSql = listSqlTpl({ - _query: this.query, - _columns: this.columns.join(', ') - }); + sql (psql, override, callback) { + if (!callback) { + callback = override; + } - return callback(null, listSql); -}; + const listSql = listSqlTpl({ + query: this.query, + columns: this.columns.join(', ') + }); -List.prototype.format = function(result) { - return { - rows: result.rows - }; -}; + debug(listSql); -List.prototype.getType = function() { - return TYPE; -}; + return callback(null, listSql); + } -List.prototype.toString = function() { - return JSON.stringify({ - _type: TYPE, - _query: this.query, - _columns: this.columns.join(', ') - }); + format (result) { + return { + rows: result.rows + }; + } + + getType () { + return TYPE; + } + + toString () { + return JSON.stringify({ + _type: TYPE, + _query: this.query, + _columns: this.columns.join(', ') + }); + } };