chbm / level1

level1 is a JavaScript API over leveldb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

level 1 - A simple leveldb wrapper for nodejs

example

var level1 = require('./level1');
level1('ONE.db', function(err, db) {
	if (err) {	throw err;	}
	// stores a document
	db.set(
		{	// document to store
			name:	'Afonso Henriques',	// no id passed, stores on new id
			age:	19
		},
		function(err, id) {				// callback fn
			if (err) {	throw err;	}
			console.log(id);			// returns the id
		}
	);
});

level1 instance methods:

get / query

db.get(
	{String}			id,
	{Function(err, x)}	callback
)

db.getOrUndefined(
	{String}			id,
	{Function(err, x)}	callback
)

db.query(
	{Boolean Function(doc, index)}	filterFn,
	{Function(err, docs)}			callback
)

advanced query ops

db.count(
	[{Boolean Function(doc)}	filterFn],
	{Function(err, count)}		cb]
)

{Object[]} db.sortPaginate(
	{Object[]}						docs,
	[{Boolean Function(doc1, doc2)}	sortFn],
	[{Number}						docsPerPage],
	[{Number}						pageNr]
)

Synchronous function that receives a query result and applies sorting and/or pagination.


{Object[]} db.groupBy(
	{Object[]}						docs,
	{String|String Function(doc)}	propertyOrFn,
	[{Boolean}						asArray],
	[{Boolean}						skipDocs]
)

Synchronous function that receives a query result and groups it by a property or other criteria extracted via a function.

If asArray is trueish, the array of sorted results, each one {key, count, [docs[]]}.

Otherwise returns an object with propertyValues as keys and related docs as value.

set (create/update)

db.set(
	{Object}			doc,
	[{Function(err, x)}	callback]
)

db.setBulk(
	{Object[]}			docs,
	[{Function(err, x)}	callback]
)

db.updateQuery(
	{Boolean Function(doc, index)}	filterFn,
	{Function(doc)}					updateFn
)

delete

db.del(
	{String}			id,
	[{Function(err)}	callback]
)

db.delBulk(
	{String[]}			arrayOfIds,
	[{Function(err)}	callback]
)

db.delQuery(
	{Boolean Function(doc, index)}	filterFn,
	[{Function(err)}				callback]
)

About

level1 is a JavaScript API over leveldb