Reputation: 462
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
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