0

I'm trying to extract data from the SQLite database using NodeJS following the tutorial Following @ShadowCode answer I modified my code as follows.

const sqlite3 = require('sqlite3').verbose();

//open the database
let db = new sqlite3.Database('src/assets/academia.db');

db.run("SELECT userid as id, firstname, lastname FROM users", function(err, row){
    console.log(row.userid + " " + row.firstname + " " + row.lastname);
});

//close connection
db.close();

I get an error saying it can't read property userID. If I run the sql statement in database it runs perfectly.

TypeError: Cannot read property 'userid' of undefined
    at Statement.<anonymous> (C:\academia_2\src\get.js:7:21)
--> in Database#run('SELECT userid, firstname, lastname FROM users', [Function])

1 Answer 1

1

Maybe your Tutorial is kinda outdated, maybe take a look at the docs sqlite3 - npm.

Look at this Snippet, for me it worked.

db.run("UPDATE tbl SET name = ? WHERE id = ?", "bar", 2);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I'll take look.

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.