У меня две задачи.Первый DUMP базы данных, т. Е. Второй DROP it.
function dumpDB ( ) {
var conn = mysql.createConnection({
host : config.db.dbHost,
user : config.db.dbUser,
password : config.db.dbPassword,
});
conn.connect();
// Check if is there are tables in the database to backup.
// I do this check because if the database is empty when I dump
// I receive an error in the console.
return conn.query('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = \'' + config.db.dbName + '\'', function (error, results, fields) {
if (error) throw error;
conn.end();
count = results[0]['COUNT(*)'];
if(count>0){
// create trash folder if it doesn't exists
if(! fs.existsSync(config.paths.trash)){
fs.mkdirSync(config.paths.trash);
}else{
del.sync(config.paths.trash + '**/*');
}
// dump the result straight to a file
mysqldump({
connection: {
host : config.db.dbHost,
user : config.db.dbUser,
password : config.db.dbPassword,
database : config.db.dbName,
},
dumpToFile: config.paths.trash + 'dump_' + new Date().toISOString().slice(0,19).replace(/:/g, "-").replace("T", "@") + '.sql',
});
}else{
f.alert('Database <' + config.db.dbName + '> doesn\'t contain anything.\n# Nothing will be dumped.')
}
});
}
function deleteDB (done) {
var pool = mysql.createPool({
host : config.db.dbHost,
user : config.db.dbUser,
password : config.db.dbPassword
});
return pool.getConnection(function(err, connection) {
if (err) throw err; // not connected!
// Use the connection
connection.query('SHOW DATABASES LIKE \'' + config.db.dbName + '\'', function (error, results, fields) {
// When done with the connection, release it.
connection.release();
if (error) throw error;
if(results.length>0){
// Use the connection
connection.query('DROP DATABASE `' + config.db.dbName + '`', function (error, results, fields) {
if (error) throw error;
f.alert('Database <' + config.db.dbName + '> successfully deleted.');
});
}else{
f.alert('Database <' + config.db.dbName + '> doesn\'t exists.');
} // end if(results.length==0){
pool.end();
}); // end connection.query('SHOW DATABASES
}); // pool.getConnection
}
Задача: exports.delete = series (dumpDB, deleteDB);
Проблема заключается в том, что deleteDB запускается приdumpDB все еще создает файл SQL, поэтому выдает ошибку, потому что больше не находит базу данных.
Как я могу решить эту проблему?
Я попытался использовать «gulp-sequence»но проблема та же.Есть ли способ заставить последовательность ждать завершения создания файла sql?