Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.
/ level-js Public archive
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

'json' encoding stringifies data before being inserted into db #33

@ianwremmel

Description

@ianwremmel

Since JSON is the native encoding to IndexedDB, it shouldn't be necessary to stringify data before storing it. Is it AbstractLevelDOWN that does the conversion? Does it make sense to replace 'json' encoding with raw:true when the database is opened?

I'm using the following to make sure I can cleanly work with JSON in both node and browser environments, but it feels like a hack:

package.json:

  ...
  "browser": {
    "leveldown": "level-js",
  }
  ...

index.js:

var levelup = require('levelup');
var leveldown = require('leveldown');
var leveljs = require('level-js');

var options = {
  db: leveldown
};
if (leveljs !== leveldown) {
  options.valueEncoding = 'json';
}
var db = levelup(name, options);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions