0

I wrote a code, my goal is to easily retrieve information from the sqlite3 database without always having to do "db.get ..." so I make a function but it doesn't work , can you help me ?

Here is the code:

exports.getGuildLanguage = function(guild) {
var lang = null;

db.get("SELECT guildLanguage FROM a" + guild.id, (err, data) =>{
    if(err){
        throw err;
    }
    lang = data;
    (data.guildLanguage);
})

return lang;
};

in "getters.js" file And in another class

const getters = require("../getters.js") // récupération du fichier
console.log(getters.getGuildLanguage(message.guild)) // envoie du message

Please help me ! Thanks for your reponse in advance

PS : Sorry, my english is bad because I am french

KodyS
  • 1
  • What kind of error returns you the console? – Marcelo J Forclaz Aug 08 '20 at 14:20
  • Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Keith Aug 08 '20 at 14:25
  • I think you should make it an async function that returns a promise. Or you add a second argument to the function, that is a callback and you call it inside with the result. Returning a Promise however will be preferred solution today in modern javascrip. Because you can directly use the function with async/await. – Tobias Nickel Aug 24 '20 at 10:26

0 Answers0