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