I need to do a truncate of a table and then wait to start populate again, I must implement async/await otherwise is not working good.
How can I do this? I try with await on truncateCharfileWorldSaveTable and using async on that function but I don't understand how to make it work.
async function truncateCharfileWorldSaveTable(){
let query = 'TRUNCATE charfiles_worldsave'
await db.get().query(query, function (err, result, fields) {
if (err) console.error('function truncateCharfileWorldSaveTable: ' + err);
console.info('Tabla charfiles_worldsave_temporal TRUNCATE');
});
}
exports.backupCharfiles = async function(req, res) {
try {
//Primero borramos todo el contenido de la tabla e iniciamos el proceso
await truncateCharfileWorldSaveTable()
console.info('==== INICIANDO COPIA DE CHARFILES POR WORLDSAVE ======')
let files = fs.readdirSync('./charfiles/');
files = files.filter(file => file.endsWith('.chr'));
files.forEach(writeCharfileWorldSaveTable)
res.status(200).send('Se estan guardando los charfiles en la base de datos');
} catch(err) {
console.error('function backupCharfiles: ' + err)
}
};