0
function resumeID() {
    let searchSQL = `SELECT * FROM students ORDER BY id DESC`;
    db.get(searchSQL, (err, row) => row);
}

I am a newbie in javascript and I use sqlite3 in nodejs. I want to use the variable "row"(as shown in the code) as the return value of the function "resumeID". Is there any way to do that?

Note: the db variable is an database object created with new sqlite3.Database()

AsyncFox
  • 41
  • 1
  • 1
    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) – jonrsharpe Aug 26 '22 at 10:41
  • tldr you can't, you can return a promise though – Konrad Aug 26 '22 at 20:04

1 Answers1

2

Well, actually I solved this problem by using another package called sqlite. It provides easy-to-use promise features. Now the function is as below.

async function resumeID(db) {
    let searchSQL = `SELECT * FROM students ORDER BY id DESC`;
    return ((await db.get(searchSQL)).id += 1);
}
AsyncFox
  • 41
  • 1