Reputation: 37
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])
Upvotes: 0
Views: 474
Reputation: 585
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);
Upvotes: 1