Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

98
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!