I am trying to perform a delete of a row in sqlite db using nodejs and node-sqlite3 package.
When I run the delete command, and manually check the entries, I can see that the query successfully deleted that row but I cant seem to write the code that confirms this.
This is the query
db.run("DELETE FROM Table1 WHERE id=? AND username=?", [id, user], function(error) {
console.log(error);
});
Regardless of a wrong or right input, it outputs null to the console. If the right details are given, it deletes it and prints null, if wrong id and user are given, it still prints null.
Any ideas on what might be wrong?
Thanks
There is nothing wrong in the node and node-sqlite3 behaviour here.
Here are two parts to explain first regarding node and other regarding Sqlite.
NodeYour callback is getting called after execution of the statement. So nothing wrong here, since your callback is getting called (as proved by ‘null’ as output).
SqliteDelete query in Sqlite deletes if condition given in
whereclause evaluates to true, otherwise nothing is deleted.Referring from node-sqlite3 documentation’s Database#run api:
So, in your case query execution succeeds without any error, resulting in
errorargument to callback functionnullas you see in output.Further, if you want to check if any row was actually removed, you can use
changesproperty as mentioned in the documentation:Hope it helps…