mafintosh / hyperdb

Distributed scalable database
MIT License
752 stars 75 forks source link

Half-baked: JSON-to-hyperdb mapping #136

Open bnewbold opened 6 years ago

bnewbold commented 6 years ago

Does there already exist a deterministic 1-to-1 mapping between a JSON document and a key/value store like hyperdb? What I mean is taking one (possibly very large) JSON object and splitting it so each "atom" (integer, boolean, string, etc) ends up as a single Value in the database. Eg:

{
  "a": ["red", "blue"],
  "num": 1234,
}

mapping to something like:

/a[]/[0 -> '"red"'
/a[]/1 -> '"blue"'
/num -> '1234'

This could make for a nice high-level API to hyperdb, where applications just get a JSON-like object (whatever that maps to in their native language, eg nested dicts in python). I'm not proposing the opposite (hyperdb-to-JSON), though that might also be a desirable feature, and is trivial in the case of either a single flat JSON object (with full hyperdb paths as keys) or via nested Objects, one per path.

pfrazee commented 6 years ago

👍 I like this idea a lot

andrewosh commented 6 years ago

@bnewbold I'd really like something like this too, especially for large objects where only a subset of the fields change frequently.

I know there are a few things in leveldb-space that tackle this (thinking level-pathwise specifically). Could potentially use hyperdown for a quick 'n dirty prototype with level-pathwise.

e-e-e commented 6 years ago

I also like this idea - and think it would be pretty trivial to implement - although does it belong in hyperdb itself or could it be implemented as another module.

derhuerst commented 6 years ago

FYI I've built something similar: level-tree.

vsivsi commented 6 years ago

This reminds me very much of the functionality of something like Noms. Looks like the company behind that project got sold to Salesforce, but there are interesting ideas (and likely cautionary tales) in there for sure.

e-e-e commented 5 years ago

@bnewbold I started playing around with implementing this - https://github.com/e-e-e/hyperdb-json. Its just a quick little POC - but it works for simple cases. I have not implemented deletion or cleanly setting new values.