Giter Club home page Giter Club logo

fastify-leveldb's Introduction

fastify-leveldb

CI NPM version Known Vulnerabilities js-standard-style

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

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

Install

npm i fastify-leveldb --save

Usage

Add it to you project with register, configure the database name and you are done!

You can access LevelDB via fastify.level[name].

const fastify = require('fastify')()

fastify.register(
  require('fastify-leveldb'),
  { name: 'db' }
)

fastify.get('/foo', async function (req, reply) {
  const val = await this.level.db.get(req.query.key)
  return val
})

fastify.post('/foo', async function (req, reply) {
  await this.level.db.put(req.body.key, req.body.value)
  return { status: 'ok' }
})

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

By default, Leveldown is used for the store but you can use any Abstact-leveldown compliant store, such as memdown.

First, you must install the store:

npm install memdown

Next, initialize the plugin with the given store:

fastify.register(require('fastify-leveldb'), {
  name: 'db',
  options: {
    store: require('memdown')
  }
})

By default the path where the db will be created is the name option, but you can also pass a custom path as well.

fastify.register(
  require('fastify-leveldb'),
  { name: 'db', path: '.local' }
)

Acknowledgements

This project is kindly sponsored by:

License

Licensed under MIT.

fastify-leveldb's People

Contributors

dependabot[bot] avatar delvedor avatar mcollina avatar greenkeeper[bot] avatar cemremengu avatar fdawgs avatar eomm avatar github-actions[bot] avatar appelgriebsch avatar neculaesei avatar millette avatar salmanm avatar zekth avatar lependu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.