Level / level-js

An abstract-leveldown compliant store on top of IndexedDB.
MIT License
542 stars 44 forks source link

Drop support of key & value types other than string and Buffer #174

Closed vweevers closed 5 years ago

vweevers commented 5 years ago

Background: https://github.com/Level/memdown/issues/186.

vweevers commented 5 years ago

We can't do it exactly the way I proposed in https://github.com/Level/memdown/issues/186#issuecomment-520126288:

In level-js, store strings as (array)buffers

Because not all runtime environments support binary keys. In those we must use string keys only.

I'm thinking we'll replace:

https://github.com/Level/level-js/blob/86dd5e76b355c49b20d55c6d86c66381ad5cfd13/index.js#L143-L151

With:

Level.prototype._serializeKey = function (key) {
  if (Level.binaryKeys) {
    return Buffer.isBuffer(key) ? key : Buffer.from(String(key))
  } else {
    return String(key)
  }
}
vweevers commented 5 years ago

Also try to find a way to support reading/migrating existing data (that was stored as a string).