newpdv
newpdv

Reputation: 462

sqlite3 in Node.js does not return the lastID from INSERT callback

db.run("INSERT INTO test VALUES (?)", [testVal], function(err) {
      console.log(err);
      console.log(this.lastId);
      console.log(this);
})

err - return null, this.lastID - return undefined, this - return Window object

How do I get the last insert identifier?

Upvotes: 5

Views: 3605

Answers (1)

Marty
Marty

Reputation: 156

Actually you have to use the lastID (capital D).

db.run("INSERT INTO foo ...", function(err) {
    // err is null if insertion was successful
    console.warn("inserted id:", this.**lastID**);
});

Source: https://github.com/mapbox/node-sqlite3/issues/206

Upvotes: 5

Related Questions