Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
Getting the result value out of Sqlite3 callback function

I'm using Sqlite3 in an Express back-end with a React front-end. So I'm trying to check if there is a user with a certain email in the database. I've got the function below, which is not finished yet, but the issue I'm having is that I cannot return the result.

Is there a way to return the result variable from the callback function or do I only have access to it inside the callback function?

When finished the function should be returning the email of the user if they exists or false if they don't exist in the database.

getUserByEmail = () => {
    database.get(getUserByEmailQuery, [], (err, result) => {
        if (err) {
            console.log(err.message);
        }
        console.log(result.emailAddress);
        return result;
    });
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I just solved it an hour or so ago. Not the smartest solution, but what I did was just use a different package for the database.

So I used better-sqlite3 which makes it possible to just store the result from the database query into a variable.

Here is the updated code:

exports.getUserByEmail = (email) => {
    const result = betterSqlite3DB.prepare(getUserByEmailQuery).get(email);
    return result;
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda