0
db.run(`UPDATE moneyset SET answer = NULL WHERE userID = '${user.id}'`, (err) => {
   if (err) throw err;
   console.log(this)
   console.log(`Template literal ${this}`);
});

According to the tutorial on https://www.sqlitetutorial.net/sqlite-nodejs/update the results I should expect is at least something in this object but what I receive is empty object.

console log:

> {}
> Template literal [object Object]

The results of the .run() function can be seen in database so object should not be empty.

  • If it is important `.run()` method is nested in `.get()` callback which is bad design i am trying to resolve. Context hastebin: https://hastebin.com/ozevupuqit.js – Adrian Solarczyk Jan 07 '20 at 03:20

1 Answers1

0

The console.log is telling you that this is an object. Don't you want to interrogate the changes property of that object, à la this line from the tutorial?

console.log(`Row(s) updated: ${this.changes}`); 
DinoCoderSaurus
  • 6,110
  • 2
  • 10
  • 15
  • It is empty, no `changes` property even if there are changed rows. But as far I know it should never be empty, it should have `changes = null/undefined` and `lastid = null` properties if no rows have been affected. – Adrian Solarczyk Jan 07 '20 at 23:16
  • From a little research, the problem is using "this" in the "arrow function" as per [the answer to this post](https://stackoverflow.com/questions/34361379/are-arrow-functions-and-functions-equivalent-exchangeable). And since the example in the tutorial does not use an arrow function, try changing that and see what happens. – DinoCoderSaurus Jan 08 '20 at 12:56
  • I had this problem. I was calling db.run() inside an anonymous function. this didn't exist when the function was anonymous. I named the anonymous function and it worked – mazoula Dec 23 '20 at 13:06