mafintosh / mafintosh/hyperdb

hyperdb.del() should not add null value for already deleted or non-existent keys

Open
#94 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
748
Forks
56
PR merge metrics
No merged PRs in 30d

Description

Currently deleting keys adds a null value to the db regardless of if the key exists or not. It would be great to check if the key exists or not before deleting to avoid unnecessary data in the db.

I wrote some tests for this the first and last are currently failing.

tape('does not delete non existent keys', function (t) {
  var db = create.one()
  db.del('hello', function (err, node) {
    t.error(err, 'no error')
    t.same(db._writers[0].length(), 0)
    t.end()
  })
})

tape('does not delete non existent keys', function (t) {
  var db = create.one()
  db.put('hello', 'world', function (err, node) {
    t.error(err, 'no error')
    db.del('hello', function (err, node) {
      t.error(err, 'no error')
      t.same(db._writers[0].length(), 2)
      t.end()
    })
  })
})


tape('does not delete non existent keys', function (t) {
  var db = create.one()
  db.put('hello', 'world', function (err, node) {
    t.error(err, 'no error')
    db.del('hello', function (err, node) {
      t.error(err, 'no error')
      t.same(db._writers[0].length(), 2)
      db.del('hello', function (err, node) {
        t.error(err, 'no error')
        t.same(db._writers[0].length(), 2)
        t.end()
      })
    })
  })
})

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at hyperdb.del() and run the three tape tests included in the issue. Check the writer length after deleting a missing key, deleting an existing key, and deleting the same key twice; done means no null value is added for missing or already deleted keys while the expected single deletion remains recorded.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
database, distributed-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.