Function to query value in the database and return boolean value

Asked

Viewed 17 times

0

Person, good night!

I am a beginner and I want to create a function that sees if the value exists in the database and return me true or false.

I tried to do so but when printing the result of this function, the result is "test"

async function verificarCnpjNoBanco(cnpj){
    let resultado = 'teste'
    await connection.query("SELECT cnpj FROM dados_clientes WHERE cnpj = ?", [cnpj], (err, result)=>{
        if(err) return console.log(err)
        if(result[0].cnpj){
            return resultado = true
        }else{
            return resultado = false
        }
    })
    return resultado
}

How can I make this function return me a boolean value?

I did not find any similar question, in case this is repeated, delete without problems.

Thank you for your attention!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.