Windshaft-cartodb/lib/models/dataview/factory.js

23 lines
651 B
JavaScript
Raw Normal View History

'use strict';
2019-10-07 15:40:50 +08:00
const dataviews = require('.');
2017-09-15 20:04:09 +08:00
module.exports = class DataviewFactory {
2019-10-22 01:07:24 +08:00
static get dataviews () {
2017-09-15 20:04:09 +08:00
return Object.keys(dataviews).reduce((allDataviews, dataviewClassName) => {
allDataviews[dataviewClassName.toLowerCase()] = dataviews[dataviewClassName];
return allDataviews;
}, {});
}
2017-09-15 20:04:09 +08:00
static getDataview (query, dataviewDefinition) {
const { type, options, sql } = dataviewDefinition;
if (!this.dataviews[type]) {
throw new Error('Invalid dataview type: "' + type + '"');
}
return new this.dataviews[type](query, options, sql);
}
};