mafintosh / hyperdb

Distributed scalable database
MIT License
752 stars 75 forks source link

Added ifNotExists option to put #147

Closed andrewosh closed 5 years ago

andrewosh commented 5 years ago

For certain use-cases (particularly when keys are content-hashes of values), it'd be nice to be able to combine an existence check + the insertion into one operation. When the ifNotExists flag is set in put, the insertion will stop if it detects that the closest node has the same key as the one being inserted. With this approach, only one traversal is required to accomplish the above workflow.

The PR:

  1. Adds the ifNotExists flag to db.put
  2. Adds three tests (in test/basic.js) to ensure that this behavior works correctly (including in the presence of conflicts).
pfrazee commented 5 years ago

Ooh, neat feature.

mafintosh commented 5 years ago

3.5.0