0

I am simply trying to console.log() rows that each have an automatically incremented integer as their primary key. What is the most efficient way to do this in Node.js? My database file, at least for now, consists of one table with a few rows that I need to access. I am very new to sqlite3 and have tried to log

db.run('SELECT * FROM "talon"')

which returns

Database { open: false, filename: 'bin/data.db', mode: 65542 }

Clearly I've not much of an idea what I'm doing, any help is much appreciated!

2
  • a sqlite-nodejs tutorial Commented Feb 2, 2018 at 22:03
  • @gato wow I really didn’t search as hard as I thought. Thank you sir. Commented Feb 2, 2018 at 22:04

1 Answer 1

1

In Node.JS, I/O happens asynchronously. This means that db.run will return execution flow before the DB results are fetched. You will need to provide a callback in order to read the results:

// note, that I changed the call to use "each"
db.each('SELECT * FROM "talon"', function(err, row) {
  if (err) throw err
  console.log(row)
})

I have not tried this code, but I gathered the API details from this link.

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.