CartoDB-SQL-API/lib/batch/models/job-factory.js

27 lines
600 B
JavaScript
Raw Normal View History

2016-05-14 00:50:55 +08:00
'use strict';
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');
};