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 🙏

© 2026 – Pkg Stats / Ryan Hefner

leveldb-backbone-adapter

v0.1.6

Published

This is a backend for backbone, to have storage in LevelDB

Readme

Leveldb-backbone-adapter

This is a library to run BackboneJs Models and Collection on Nodejs with persistance to LevelDb(Using sublevel for each collection).


Installation

npm install leveldb-backbone-adapter

Set up

var Backbone = require('Backbone'),
	levelDbBackboneAdapter = require('leveldb-backbone-adapter');

levelDbBackboneAdapter(Backbone, {
	db : 'testDb'
});

This will modify Backbone.sync method to work with sublevel persistance for regular Backbone fetch and save functions. Also levelDbBackboneAdapter will add more functions to have query capabilities against our collection.

This will make all Backbone Models and Collections to have a _db that is the sublevel for the collection, its also available for each instance of you models and collections.

Extending the model and collection to have a db.

var ExampleModel = Backbone.Model.extend({
	dbName : 'example'
});

var ExampleCollection = Backbone.Collection.extend({
	dbName : 'example',
	model : ExampleModel
});

This way the collection and the model will have persistance to the sublevel example. You can have as many collections and models, each pointing to a diferent sublevel.


Api

Collection

All this api is for Collections instances, so the first step is

var exampleCollection = new ExampleCollection();

Note: Collection Api is heavy focus on promises.

Collection.fetch

Will get all items in the sublevel.

var q = exampleCollection.fetch();

q.then(function () {
	// Do something once the collection is loaded.
});

Collection.fetchFilter

Will get all items that match an object or a function.

var q = exampleCollection.fetchFilter(function(item){
	return !item.active;
});

q.then(function () {
	// Do something once the collection is loaded.
});

Or

var q = exampleCollection.fetchFilter({active:false});

Collection.fetchOne

This will fetch one element from the sublevel.

var q = exampleCollection.fetchOne(function(item){
	return !item.active;
});

q.then(function (model) {
	// Do something with the model
});

Note: Model is not added to the collection.

Model

Note: Model Api works with promises and callbacks.

Model.get()

Will get a model by key from the data base and return it as a model.

ExampleModel.get(key, function(err, model){
	// Do something with the model.
});

or

var q = ExampleModel.get(data.get('id'));

q.then(function(model){
	// Do something with the model.
});	

Model.find()

Will get a model that matches the object or function suplied as query. It will throw a error if you have more than one element matching the query.

With callback:

ExampleModel.find({name:'some name'}, function(err, model){
	// Do something with the model.
});

or

ExampleModel.find(function(data){
	return data.name === 'somename';
},function(err,model){
	// Do something with the model.
});

With promise

var q = ExampleModel.find({name:'Aaron Rodgers'});

q.then(function (model) {
	// Do something with the model.
});

or

var q = ExampleModel.find(function(data){
	return data.name === 'somename';
});

q.then(function(model){
	// Do something with the model.
});	

model instance

create a new model

With promise:

var model = new ExampleModel({/* Some data */});

var q = model.save();

q.then(function(model){
	// Do something with the model.
});

With callback[Not that clean]:

var model = new ExampleModel({/* Some data */});

var fn = function(){
	// Do something with the model.
}

model.save(null, {success:fn});

model.save()

model.save('attr', value, {success: function (/* model */) {
	// Do something with the model.
} } );

or

model.set('active', true);

var q = model.save();

q.then(function(model){
	// Do something with the model.
});	

Note: to handle errors with a promise use:

q.then(function(model){
	// Do something with the model.
}).fail(function(err){
	// Handle error.
});

or just handle errors with

q.fail(function(err){
	// Handle error.
});

You could make a generic error handler and pass it to all you promises.


To Dos

  • Allow to have levelDb persistance just in some collections.
  • Make collection take database form the model.
  • Implement callback api for Collection functions.