-1

Sorry for my English.

I've been looking for information on how to get a list of objects with all the entries from a table in a sqlite database, but in all the examples they are only obtained inside a .then() method.

From what I've read this is due to the asynchronous nature of Node, but I don't know how to make useful queries this way.

This is code I have. What I need is to be able to use the query outside of the promise.

const sqlite = require('sqlite')
const sqlite3 = require('sqlite3')

db = sqlite.open({
  filename: './database.db',
  driver: sqlite3.Database
})

var data = db.then(async (db, cb=(ls)=>{return ls}) => {
  const result = await db.all('SELECT * FROM Person')
  return result
})

console.log(data); // error

What I need...

console.log(data); // [{id: 1, name: 'x'}]

0 Answers0