mafintosh / hyperdb

Distributed scalable database
MIT License
753 stars 75 forks source link

proposal: createKeyStream #67

Closed m-onz closed 6 years ago

m-onz commented 6 years ago

It would be really handy to be able to see all the keys that have been set with something like...

var r = db.createKeyStream()
r.pipe(process.stdout)

or

db.getKeys('/prefix', function (e, keys) {
    if (!e) console.log('these keys have been set ', keys);
})

BTW createHistoryStream seems to be missing from the latest version. I guess the library API is changing but it would be nice to be able to build an "explorer" / visualization tool that lets you see all the data inside a HyperDB

I am planning to build an electron app that can do this once the library API becomes static.

hackergrrl commented 6 years ago

Is createReadStream is what you're after?

mafintosh commented 6 years ago

Yea, read stream should do the trick. We could add a .createValueStream + .createKeyStream that are simple through streams on top that uses map to map the nodes for ease of use

HyperDB.prototype.createKeyStream = function () {
  return this.createReadStream({map: node => node.key, reduce: (a, b) => a})
}
m-onz commented 6 years ago

Derp! Quite possibly yes. I will close this issue tommorow once I've investigated a bit more.

m-onz commented 6 years ago

Perfect! Thanks 👍