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
}
);
});
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
)
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.
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
)
db.del(
{String} id,
[{Function(err)} callback]
)
db.delBulk(
{String[]} arrayOfIds,
[{Function(err)} callback]
)
db.delQuery(
{Boolean Function(doc, index)} filterFn,
[{Function(err)} callback]
)