Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (32 sloc) 1.36 KB

Core API

Use the core API directly to use the key value store in a node.js process.

var db = level1.core({
	dbPath:'./mydb' // this is the only required option
	interceptor: function(v, k) { // optional interceptor
		if ('ignore' in v) { return; } // has ignore attribute? don't put such objects.
		if ('age' in v) { v.age = parseInt(v.age, 10); } // cast age attribute to integer if present
		return [v, k];
	}
});

db.put({hello:'world'}); // returns the autogenerated key

db.put({foo:'bar'}, 'k1'); // stores this one on key 'k1'

db.get('k1', function(err, o) {
	// err or the object
})

db.clear(cb); // clears db

db.list(cb); // returns array of {key:k, value:v}

// you must pass a filter function which receives the arguments: v(value) and k(key)
db.search(function(v) { return 'name' in v && v.name[0].toLowerCase() === 'a'; }, cb);
// this example returns values which have attribute 'name' and whose first character is an a.

db.count(function(v) { return 'name' in v; }, cb);
// counts values having 'name' attribute

db.keys(cb); // returns array of keys

db.values(cb); // returns array of values

db.uuids(2, cb); // returns 2 uuids for ad-hoc usage

By default sets attributes:

  • _key (key uuid string)
  • _createdAt (timestamp)
  • _modifiedAt (timestap)

back to main