Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-major Changes that break backward compatibility
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant