level-json

LevelDB wrapper to avoid repeating encoding fields for just JSON

level-json

LevelDB wrapper to avoid repeating encoding fields for just JSON

$ npm install level-json
io = require('level-json')('./db')
 
io.set('foo', { foo: 123, bar: 456 }, function (error) {
  if (error) throw error
 
  io.get('foo', function (errorfoo) {
    if (error) throw error
 
    foo
    // => { foo: 123, bar: 456 } 
  })
})

Call level-json with a directory path to establish new LevelDB connection:

io = require('level-json')('./data')

A wrapper function with following methods will be returned:

  • del
  • get
  • set
  • batch
  • createReadStream
  • createWriteStream
  • destroy
  • close
  • isClosed
  • isOpen

The wrapper function can be called for getting and setting values like below:

io('foo', { foo: 123 }, function (error) {
 
  io('foo', function (errorfoo) {
 
    foo
    // => { foo: 123 } 
 
  })
 
})