Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

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

Closed
vweevers opened this issue Aug 14, 2019 · 2 comments · Fixed by #179
Closed

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

vweevers opened this issue Aug 14, 2019 · 2 comments · Fixed by #179
Labels
semver-major Changes that break backward compatibility

Comments

@vweevers
Copy link
Member

Background: Level/memdown#186.

@vweevers vweevers added the semver-major Changes that break backward compatibility label Aug 14, 2019
@vweevers
Copy link
Member Author

We can't do it exactly the way I proposed in Level/memdown#186 (comment):

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:

level-js/index.js

Lines 143 to 151 in 86dd5e7

Level.prototype._serializeKey = function (key) {
if (Buffer.isBuffer(key)) {
return Level.binaryKeys ? key : key.toString()
} else if (Array.isArray(key)) {
return Level.arrayKeys ? key.map(this._serializeKey, this) : String(key)
} else {
return key
}
}

With:

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

@vweevers vweevers changed the title Drop support of key types other than string and Buffer Drop support of key & value types other than string and Buffer Aug 17, 2019
@vweevers
Copy link
Member Author

vweevers commented Sep 8, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
semver-major Changes that break backward compatibility
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant