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

99
Visualizações
db.serialize sqlite3 - javascript - return value after correct valorization

Considering these two files: main.js

const  dbHandler  = require('./DBHandler');
var minPrice = dbHandler.retrieveMinPrice("PLAYER");
console.log(minPrice);

DBHandler.js

const sqlite3 = require('sqlite3');
const db = new sqlite3.Database('DB/database.sqlite.db');

module.exports = {
    retrieveMinPrice: function (playerName){
        var to_be_returned= 9999;
        db.serialize(function() {
            var sql_query = "SELECT MIN(ethPrice) FROM cards WHERE playerName = ?";
            var values = [playerName];
            db.get(sql_query, values, function (err, rows) {
                to_be_returned = rows['MIN(ethPrice)'];
                console.log(to_be_returned); //right value 1234 (example)
            });
            console.log(to_be_returned); //wrong value 9999
        });
        console.log(to_be_returned); //wrong value 9999
    }

}

What is the right way to return the variable to_be_returned to the main.js file, in order to have the minPrice variable set to 1234 and not 9999 (or undefined)? Should I use a different function than db.get()? Is db.serialize() used in the wrong way?

about 4 years ago · Santiago Trujillo
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