mafintosh / hyperdb

Distributed scalable database
MIT License
752 stars 75 forks source link

Pluggable adapter/encoder api [feature idea] #157

Open m-onz opened 5 years ago

m-onz commented 5 years ago

This is more a feature request / proposal... it would be nice if there was neat way to apply a transformation on incoming and outgoing data.

var hyperdb = require('hyperdb')

var db = hyperdb()

// pass through
db.setEncoder(function (input) { return input })
db.setDecoder(function (input) { return input })

The idea is that those functions are called before any data is inserted or retrieved (before the data is returned from streams and callbacks).

There may already be a nice way to do this stuff, and the API is just a proposal at this stage. All comments and thoughts welcome!

m-onz commented 5 years ago

I made a library to suit my needs: https://github.com/m-onz/hyperdb-plug-socket ... it only supports get/put/createReadStream... (thats all i need for now). It would be possible to use javascript Proxies or something more complicated.