levelable

0.4.3 • Public • Published

levelable Build Status Dependencies

Builds on sublevel and multilevel to expose a leveldb over the network

Getting Started

npm i -S levelable

Usage

Levelable is only just more than a convenience wrapper around multilevel so functionality its usage is the same.

Create the levelable object and use it to create a server:

var level = Levelable({
    port: 3000,
    path: '/.db/leveller.db'
});
 
level.listen()
    .then( server => {
        // ...
    })
    .catch( onErr );

Then create a client connected to that server:

level.connect()
    .then( con => {
        con.client.put( 'foo', { foo: 'bar' }, ( err ) => {
            con.client.get( 'foo', ( err, res ) => {
                // res = { foo: 'bar' }
            });
        });
    })
    .catch( onErr );

ES6?

Yep, its written in ES6 and uses babel to transpile so if you’ve installed via npm then its good to go.

If you want to compile it yourself then its not much of a chore:

git clone git@github.com:mattstyles/levelable.git && cd $_
npm i
npm run build

There’s also a watch task if you’re in the mood to hack.

There’s a modest set of tests so feel free to hack away, use npm test to run those tests.

API

new Levelable( opts )

{
    port: <Number>::?optional,
    host: <String>::?optional
    socket: <String>::?optional,
    db: <Level>::optional,
    path: <String>::?optional,
    sublevels: <Array:String>::optional
}

port the port to listen at, either socket or port is required

host the host to listen at, defaults to localhost

socket the socket address, either socket or port is required

db a leveldb instance, e.g. new Level() or Sublevel()

path the location on disk of the db, unnecessary if the db is passed in but is used to find the manifest

sublevels array of sublevels in the db

Multilevel uses a manifest file to ensure consistency when plugins (such as sublevel) extend the levelup api and levelable uses the path option to find this manifest. For accessing the root database the manifest is unnecessary, otherwise you would need the manifest created by the server, or path to an identical manifest, or pass a manifest when attempting to connect.

levelable.sublevel( sublevelid )

Creates a new sublevel in the db. Sublevel names are also stored in the db under the meta sublevel.

levelable.listen()

Creates a server listening on the port or socket passed in at creation time. Resolves with the server instance.

levelable.connect( sublevelid , opts )

{
    manifest: <Object>
}

manifest the manifest object to use to connect to the server

Connects to the database on the port or socket passed in at creation time, optionally connecting to a specific sublevel. Resolves with an object containing both the multilevel client and the raw socket it is connected with.

Contributing

Feel free to hack away, there’s (at least) a couple of things that would be really beneficial if this module handled for you.

npm i
npm test
npm watch

License

WTFPL

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.4.3
    0
    • latest

Version History

Package Sidebar

Install

npm i levelable

Weekly Downloads

6

Version

0.4.3

License

WTFPL

Last publish

Collaborators

  • mattstyles