You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
|
|
const Automate = require('sequelize-automate-freesun')
|
|
|
|
async function handleTask(app, task) {
|
|
try {
|
|
const { models } = app.fs.dc
|
|
const dataSource = await models.DataSource.findOne({
|
|
where: {
|
|
id: task.dataSourceId
|
|
}
|
|
});
|
|
|
|
if (dataSource) {
|
|
const dbOptions = createDbOptions(dataSource.config);
|
|
const automate = new Automate(dbOptions, {});
|
|
const tables = await automate.getTables()
|
|
console.log(tables)
|
|
}
|
|
} catch (error) {
|
|
app.fs.logger.error(`sechedule: handleTask, error: ${error}`);
|
|
}
|
|
}
|
|
|
|
function createDbOptions(params) {
|
|
const dbOptions = {
|
|
database: params.database,
|
|
username: params.user,
|
|
password: params.password,
|
|
dialect: 'postgres',
|
|
host: params.host,
|
|
port: params.port,
|
|
define: {
|
|
underscored: false,
|
|
freezeTableName: false,
|
|
charset: 'utf8mb4',
|
|
timezone: '+00: 00',
|
|
dialectOptions: {
|
|
collate: 'utf8_general_ci',
|
|
},
|
|
timestamps: false,
|
|
},
|
|
}
|
|
return dbOptions
|
|
|
|
}
|
|
|
|
module.exports = { handleTask }
|