2

I read all the documentation and this seemingly simple operation seems completely ignored throughout the entire README.

Currently, I am trying to run a SELECT query and console.log the results, but it is simply returning a database object. How do I view the results from my query in Node console?

exports.runDB = function() {
  db.serialize(function() {
    console.log(db.run('SELECT * FROM archive'));
  });
db.close();
}

1 Answer 1

3

run does not have retrieval capabilities. You need to use all, each, or get

According to the documentation for all:

Note that it first retrieves all result rows and stores them in memory. For queries that have potentially large result sets, use the Database#each function to retrieve all rows or Database#prepare followed by multiple Statement#get calls to retrieve a previously unknown amount of rows.

As an illistration:

db.all('SELECT url, rowid FROM archive', function(err, table) {
  console.log(table);
});

That will return all entries in the archive table as an array of objects.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.