node-leveldb
This package provides a simple, lightweight binding for LevelDB to Node.js. LevelDB is an implementation of a log-structured merge-tree that provides fast key-value storage and lookup.
Installation
$ npm install node-leveldb
Documentation
LevelDB
A LevelDB object is constructed and returned when you require('node-leveldb')
. This object can be used for all operations on a single LevelDB database.
var LevelDB = ;
LevelDB.open(databasePath)
Before operating on a LevelDB object, you have to specify which database those operations apply to. If the specified database doesn't already exist, a new one will be created. If your process doesn't have the necessary permissions to create or open the database, this function will throw an exception.
LevelDB;
LevelDB.close()
Closes the database opened by a previous successful call to LevelDB.open(...)
.
LevelDB;
LevelDB.get(key)
Returns the value associated with key
. If key
doesn't exist in the database, this function returns null
.
console;
LevelDB.set(key, value)
Inserts data into the database. If there isn't already a value for key
in the database, this function creates a new entry and maps key
to value
. If key
already exists, it replaces the old value with value
.
LevelDB;
LevelDB.list([start], [end], callback)
Enumerates data stored in the database. This function takes two optional arguments, the start
and end
of the range of keys to enumerate. If start
is not specified, it is assumed to be from the first item. If end
is not specified, it is assumed to be until the last item. Both start
and end
are inclusive. It's not possible to specify end
without first specifying start
.
LevelDB;
LevelDB.delete(key)
Removes data from the database. If key
is found in the database, this function deletes the mapping from key
to its value. This function returns true
if key
was found and a mapping was deleted, false
otherwise.
LevelDB;
Example
var LevelDB = ; LevelDB; LevelDB; LevelDB; LevelDB; LevelDB; // Print the value associated with 'Frank Herbert'. console; LeveLDB; // Print all items stored in the database. LevelDB; // Print all items with 'F' <= key <= 'T'. LevelDB; LevelDB;
License
Apache 2.0