Is there any way to make this piece of SQLite3 code shorter & more efficient? I'd like to add integers to an existing integer in a column.
I've tried the code below.
(db is defined as my SQLite3 db connection)
db.all(`SELECT * FROM coins WHERE userId = ?`, '28978936', async (err, resp) => {
if (resp.length === 0) resp[0].balance = 0;
var earnings = resp[0].balance + 100;
db.run(`INSERT INTO coins (userId, balance) VALUES (?, ?)`, '28978936', earnings, (err) => {
console.log('100 coins have been added to user "28978936"')
})
})
The code worked for me, however is there a better way to do it?