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

new encoding schemes for backends that support JS types #84

Closed
timkuijsten opened this issue Feb 14, 2016 · 2 comments
Closed

new encoding schemes for backends that support JS types #84

timkuijsten opened this issue Feb 14, 2016 · 2 comments

Comments

@timkuijsten
Copy link
Contributor

For backends like IndexedDB that support native JS types, should we introduce something like none, js or native as a valid encoding for keyEncoding and valueEncoding?

related to #83

@timkuijsten timkuijsten changed the title support for extra encoding schemes for backends that can store native JS types new encoding schemes for backends that support native JS types Feb 14, 2016
@timkuijsten timkuijsten changed the title new encoding schemes for backends that support native JS types new encoding schemes for backends that support JS types Feb 14, 2016
timkuijsten pushed a commit to timkuijsten/level.js that referenced this issue Feb 14, 2016
@juliangruber
Copy link
Member

you can already write a custom encoding, a la

var noop = function(){};
var none = { encode: noop, decode: noop };
db({ valueEncoding: none, keyEncoding: none });

iirc that should work, but haven't tried it

@vweevers
Copy link
Member

vweevers commented Oct 2, 2017

This is supported, but note there's two layers to this.

  1. Encoding. The user of level(up) must use the none aka id encoding. E.g. valueEncoding: 'id'.
  2. Serialization. The backend must implement _serialize* as identity functions:
down.prototype._serializeKey = function (key){ return key }
down.prototype._serializeValue = function (value){ return value }

It's very likely we'll make this the default behavior. So in the future, only the backends that need to (because they can only store a subset of types - e.g. buffers and strings in leveldown) will have to implement _serialize*.

@vweevers vweevers closed this as completed Oct 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants