javascript function does not assign value to variable

0

I have a query function to bd that returns a javascript object, but when I assign the value of this function to a variable, it returns undefined, I suspect it is because the node.js is single thread, but I do not know how to solve it.

follow code example:

var docentes = [];
var docente; 
function query_docentes(){ 
    connection.query(
        'SELECT * FROM docente',
        function (err, results, fields) {
            var i = 0;
            while (results[i] != undefined) {
                docente = {
                    cod_docente: results[i].cod_docente,
                    nome_docente: results[i].nome_docente,
                    classe_docente: results[i].classe_docente,
                    titulo_docente: results[i].titulo_docente,
                    curriculo_docente: results[i].curriculo_docente,
                    email_docente: results[i].email_docente
                };  
                docentes[i] = docente;
                i+=1;
            }
            return docentes;
        }
    };
}
var resposta = query_docentes(); 
    
asked by anonymous 12.01.2018 / 15:25

0 answers