npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

leveldb-addon

v2.0.5

Published

A Node.js LevelDB binding

Downloads

7

Readme

Leveldb-addon

Leveldb addon for Node.js, supports synchronous and asynchronous invocation, and supports event emitter

FEATURES

  • Support synchronization method call Leveldb, code logic more clear
  • Also supports asynchronous method call Leveldb to make running more efficient
  • Asynchronous calls use Promise to make the code clearer

INSTALLATION

npm install leveldb-addon --save

API

new Leveldb([options])

const Leveldb = require('leveldb-addon');
let options = {
  // base settings
  "location" : './test.db',
  "writeSync" : false,
  "readFillCache" : true,
  
  // Levedb default settings
  "createIfMissing" : true,
  "errorIfExists" : false,
  "compression" : true,
  "writeBufferSize" : 4194304,
  "blockSize" : 4096,
  "maxOpenFiles" : 1000,
  "blockRestartInterval" :16,
  "maxFileSize" : 2097152,
  "block_cache" : 8388608,
  "filterPolicy" : 10,
  
  // EventListener
  "onReady" : ()=>{},
  "onCreate" : ()=>{},
  "onChanged" : ()=> {},
  "onError" : ()=>{},
  "onClosed" : ()=>{}
};

let ldb = new Leveldb(options);

For information about setting items, see the Leveldb documentation

Leveldb.prototype.open(location, [options])

ldb.open('./test.db', {});

Leveldb.prototype.close()

ldb.close();

Leveldb.prototype.put( key, value ) or Leveldb.prototype.put( json )

if (ldb.put("abc", 123)) {
    console.log('ok');
}
ldb.put({
  "abc": null, // delete abc
  "def": 456,
  "ghi": [7, 8, 9]
});

Leveldb.prototype.del( key ) or Leveldb.prototype.del( keys )

ldb.del("abc");
ldb.del(["abc", "def"]);

Leveldb.prototype.get( key ) or Leveldb.prototype.get( keys )

let value = ldb.get("abc");
let value_json = ldb.get(["abc", "def", "ghi"]);

Leveldb.prototype.forEach( callback, [iteratorOptions] )

ldb.put({"a1": 1, "a2": 2, "b1": 3, "b2": 4, "c1": 5, "c2" : 6, "d.1": 7, "d.2": 8});

ldb.forEach((iter)=>{
  	if(!/b/.test(iter.key)){
        iter.break();
    }else{
       	console.log(iter.key, iter.value); 
    }
});

let callback = (iter) => {console.log(iter.key, ":", iter.value);}

ldb.forEach(callback, {start: "b"});
// print: b1:3, b2:4, c1:5, c2:6, d.1:7, d.2:8

ldb.forEach(callback, {start: "b", end:"c"});
// print: b1:3, b2:4

ldb.forEach(callback, {start: "c", end:"b", reverse:true});
// print: c1:5, c2:6

ldb.forEach(callback, {prefix: "d."});
// print: d.1:7, d.2:8

Leveldb.prototype.asyncPut()

ldb.asyncPut("abc", 123).then(()=>{
    ...
}).catch((error)=>{
  	console.log(error);  
});
(async ()=>{
  await ldb.asyncPut("abc", 1234);
})()

Leveldb.prototype.asyncDel()

ldb.asyncDel("abc").then(()=>{
    ...
});
(async ()=>{
  await ldb.asyncDel("abc")
})()

Leveldb.prototype.asyncGet()

ldb.asyncGet("abc", 123).then((value)=>{
    console.log(value)
});
(async ()=>{
  let value = await ldb.asyncGet("abc");
})()

Leveldb.prototype.asyncForEach( callback, [iterator_options] )

ldb.forEach((iter)=>{
    console.log(iter.key, iter.value);
});

Leveldb.prototype.getIterator([iterator_options])

let iter = ldb.getIterator({start: "b"});
while(iter.read()){
    console.log(iter.key, iter.value);
}

Leveldb.prototype.addListener( type, callback, once )

  • type :
    • ready Trigger event after database open
    • create Triggers an event when the database is created
    • changed Triggers an event when the put or del operation is executed
    • error Triggers an event when an error occurs
    • closed Trigger event after database shutdown
ldb.addEventListener("changed", (info)=>{
  	console.log( info.from, info.key );
  	// print: put "abc"
});

ldb.put("abc", 123);

Leveldb.prototype.removeListener( type, callback )

ldb.removeEventListener("ready", func);

Leveldb.open(location, options)

let ldb = Leveldb.open("./test.db")

Leveldb.destroy(location)

Leveldb.destroy("./test.db")

Leveldb.repair(location)

Leveldb.repair("./test.db")

Iterator Options

let options = {
    "start":"a",
  	"end": "b",
  	"prefix": "c",
  	"reverse": true,
  	"limit":
}