diff --git a/datastore/datastore.nim b/datastore/datastore.nim index 47f339b..7dfa992 100644 --- a/datastore/datastore.nim +++ b/datastore/datastore.nim @@ -71,6 +71,9 @@ method modifyGet*(self: Datastore, key: Key, fn: ModifyGet): Future[?!seq[byte]] ## | some(u) | none | delete u | ## | some(u) | some(v) | replace u with v (if u != v) | ## + ## If `fn` raises an error, the value associated with `key` remains unchanged and raised error is wrapped + ## into a failure and returned as a result. + ## ## Note that `fn` can be called multiple times (when concurrent modification was detected). In such case ## only the last auxillary value is returned. ## diff --git a/datastore/defaultimpl.nim b/datastore/defaultimpl.nim index be7178a..475d627 100644 --- a/datastore/defaultimpl.nim +++ b/datastore/defaultimpl.nim @@ -37,6 +37,10 @@ proc defaultModifyGetImpl*( except CatchableError as err: return failure(err) + if maybeCurrentData == maybeNewData: + # no need to change currently stored value (if any) + return aux.success + if newData =? maybeNewData: if err =? (await self.put(key, newData)).errorOption: return failure(err) diff --git a/datastore/sql/sqliteds.nim b/datastore/sql/sqliteds.nim index 8f16f07..70bc06f 100644 --- a/datastore/sql/sqliteds.nim +++ b/datastore/sql/sqliteds.nim @@ -66,7 +66,7 @@ method modifyGet*(self: SQLiteDatastore, key: Key, fn: ModifyGet): Future[?!seq[ return failure(err) if maybeCurrentData == maybeNewData: - # no need to change currently stored value + # no need to change currently stored value (if any) break if err =? self.db.beginStmt.exec().errorOption: