简体   繁体   中英

Trying to get data from SQLite DB using NodeJS

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])

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM