mafintosh / hyperdb

Distributed scalable database
MIT License
753 stars 75 forks source link

Allow put to a specific head #42

Open gmaclennan opened 6 years ago

gmaclennan commented 6 years ago

Currently db.put will merge previous values for a key. It would be useful to be able to put to a specific head without merging. This would enable the user to delay decisions about merging until later. This would require that a property is exposed on db.get that allows the user to specify which record they are updating.

hackergrrl commented 6 years ago

So, something like

db.put('/foo', 'bar', function () {
  db.get('/foo', function (err, node) {
    db.put([node], '/foo', 'baz')
  })
})

Where you can explicitly replace one (or more?) nodes' values with a new one?

gmaclennan commented 6 years ago

yes. I was thinking something like opts.links in the hyperkv API

hackergrrl commented 6 years ago

@mafintosh what do you think would be involved in this? I'm starting to get to a point in hyperdb-osm dev where this feature would be handy, and I'm keen to start thinking it through together, if you can make the time!

hackergrrl commented 6 years ago

One idea is to specify an opts.links in the style of hyperkv, but each link is an object like

{
  feed: <Buffer a0 c3 ff ...>
  seq: 37
}

What I'm stymied on is: how do you encode this into the incremental index? Right now the implicit links work in two parts as I understand it:

  1. the vector clock of all other feeds, as encoded in node.clock, and
  2. the prefix trie used to walk backward to find other keys, as encoded in node.prefix.