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