CartoDB-SQL-API/batch/models/job_factory.js

27 lines
600 B
JavaScript
Raw Normal View History

2016-05-14 00:50:55 +08:00
'use strict';
2016-05-23 21:20:14 +08:00
var JobSimple = require('./job_simple');
var JobMultiple = require('./job_multiple');
var JobFallback = require('./job_fallback');
2016-05-23 21:13:31 +08:00
var Models = [ JobSimple, JobMultiple, JobFallback ];
2016-05-14 00:50:55 +08:00
function JobFactory() {
}
module.exports = JobFactory;
JobFactory.create = function (data) {
if (!data.query) {
2016-05-16 07:22:47 +08:00
throw new Error('You must indicate a valid SQL');
2016-05-14 00:50:55 +08:00
}
2016-05-23 21:13:31 +08:00
for (var i = 0; i < Models.length; i++) {
if (Models[i].is(data.query)) {
return new Models[i](data);
2016-05-14 00:50:55 +08:00
}
}
throw new Error('there is no job class for the provided query');
};