find().increment() throws error
Closed this issue · 6 comments
await db.table.find(id).increment('num');
throws an error, but the query did execute successfully.
await db.table.where({id : id }).increment('num');
do not throw an error.
And they generate exact the same sql
What is the error?
It throws not found error, but the increment did execute
That's how it's intended to be, find
is throwing when no record is found, there is findOptional
that doesn't throw on not found. where
doesn't throw on not found.
SQL may be the same, but we have different methods to handle the result differently.
So I don't see what could be changed or improved here, it's alright, do you have suggestions?
Well, I mean, there is a record to update, and the increment
action executed succeed(for both, even find
throws an error, the increment
action succeed).
I dump the sql log, they both generate the same sql, but I don't know why the find
statement throws an error.
Ah, so that's a bug, I'll try to find time for it in the near days.
That's weird, that functionality is well covered with tests, but apparently still not enough.
I published fixes for this, now it should work fine and be somewhat predictable.
// throws only when not found, returns count
db.table.find(1).increment('column')
db.table.findBy({ id: 1 }).increment('column')
// don't throw when not found, return count
db.table.findOptional(1).increment('column')
db.table.findByOptional({ id: 1 }).increment('column')
db.table.where({ key: 'value' }).increment('column')
// throw only when not found, return data
const record = db.table.selectAll().find(1).increment('column')
// don't throw when not found, return data
const many = db.table.selectAll().where({ key: 'value' }).increment('column')