hapi-level
LevelDB service provider for Hapi
Last updated 4 years ago by johnbrett .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hapi-level 
SYNC missed versions from official npm registry.

hapi-level

A simple LevelDB plugin for Hapi.

Build Status Dependency Status

Note: Sublevel has been updated to v6 in version 3.0.0 which has breaking changes which will corrupt a pre version 6 database, read about the sublevel breaking changes before updating, there is a migration tool to help with the upgrade.

NPM

Register plugin as follows, an optional options object can be passed in to specify data storage location 'path', and the config object supports all LevelUp options:

const Hapi = require('hapi');

var server = Hapi.createServer();
server.connection();

server.register([
    { 
        register: require('hapi-level'),
        options: {
            path: './data', // ./data by default
            config: {
                valueEncoding: 'json' // utf8 by default as with LevelUP
            }
        } 
    }
], (err) => {
    
    if (err) {
        throw err;
    }
    
    server.start((err) => {
    
        if (err) {
            throw err;
        }
        console.log('Server started at: ' + server.info.uri);
    })
};

To use plugin:


// New in 5.0: Make sure either `server.initialize()` or `server.start()` has been called 
// to have access to the db reference

// Accessing level object
const db = request.server.plugins['hapi-level'].db; // access from a request object

// or

const db = plugin.plugins['hapi-level'].db; // access in a hapi plugin

// Usage works just like LevelDB would
db.put('name', 'Level', (err) => {
    
        if (err) {
            return console.log('Ooops!', err); // some kind of I/O error
        }
    
        db.get('two', (err, value) => {
            
            if (err) {
                return console.log('Ooops!', err); // likely the key was not found
            }
    
            console.log('name=' + value);
        });
    });
});

// Sublevel is also available to use for sectioning of data, similar to SQL tables
users.put('two', {id: 2, name: 'Level'}, (err) => {
      
        if (err) {
            return console.log('Ooops!', err); // some kind of I/O error
        }
    
        users.get('two', (err, value) => {
            
            if (err) {
                return console.log('Ooops!', err); // likely the key was not found
            }
    
            console.log(value); // would output {id: 2, name: 'Level'}
        });
    });
});

Current Tags

  • 5.0.1                                ...           latest (4 years ago)

16 Versions

  • 5.0.1                                ...           4 years ago
  • 5.0.0                                ...           4 years ago
  • 4.0.0                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.4                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.0.8                                ...           6 years ago
  • 0.0.7                                ...           6 years ago
  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 16
Dependencies (2)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |