Plugin to share a common LevelDB connection across Fastify.
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Updated .gitignore Jul 9, 2017
.travis.yml Update to node 10 in .travis.yml (#16) Apr 29, 2018
LICENSE Initial commit Jul 9, 2017
README.md docs(readme): add Greenkeeper badge Mar 4, 2018
index.js Bumped fastify dependency to 1.0.0-rc.1 Feb 12, 2018
package.json chore(package): update tap to version 12.1.1 (#21) Dec 12, 2018
test.js First commit Jul 9, 2017

README.md

fastify-leveldb

Greenkeeper badge

js-standard-style Build Status

Fastify LevelDB connection plugin, with this you can share the same Level connection in every part of your server.

Under the hood Level is used, the options that you pass to register will be passed to Level.

Install

npm i fastify-leveldb --save

Usage

Add it to you project with register and you are done!
You can access LevelDB via fastify.level.

const fastify = require('fastify')

fastify.register(require('fastify-leveldb'), {
  name: 'db'
}, err => {
  if (err) throw err
})

fastify.get('/foo', (req, reply) => {
  const { level } = fastify
  level.get(req.query.key, (err, val) => {
    reply.send(err || val)
  })
})

fastify.post('/foo', (req, reply) => {
  const { level } = fastify
  level.put(req.body.key, req.body.value, (err) => {
    reply.send(err || { status: 'ok' })
  })
})

fastify.listen(3000, err => {
  if (err) throw err
  console.log(`server listening on ${fastify.server.address().port}`)
})

Acknowledgements

This project is kindly sponsored by:

License

Licensed under MIT.