Home

Awesome

LMDB for Node.js

A Low-level, LevelDOWN-compatible, Node.js LMDB binding

NPM NPM

"LMDB" is Symas Lightning Memory-Mapped Database.

LMDB is an ultra-fast, ultra-compact key-value embedded data store developed by Symas for the OpenLDAP Project. It uses memory-mapped files, so it has the read performance of a pure in-memory database while still offering the persistence of standard disk-based databases, and is only limited to the size of the virtual address space, (it is not limited to the size of physical RAM). Note: LMDB was originally called MDB, but was renamed to avoid confusion with other software associated with the name MDB

LMDB for Node.js, is primarily designed to serve as a back-end to LevelUP, it is strongly recommended that you use LevelUP in preference to this library directly.

<a name="platforms"></a> Tested & supported platforms

<a name="api"></a>

API


<a name="ctor"></a>

lmdb(location)

<code>lmdb()</code> returns a new Node.js LMDB instance. location is a String pointing to the LMDB store to be opened or created.


<a name="lmdb_open"></a>

lmdb#open([options, ]callback)

<code>open()</code> is an instance method on an existing database object.

The callback function will be called with no arguments when the database has been successfully opened, or with a single error argument if the open operation failed for any reason.

options

The optional options argument may contain:


<a name="lmdb_close"></a>

lmdb#close(callback)

<code>close()</code> is an instance method on an existing database object. The underlying LMDB database will be closed and the callback function will be called with no arguments if the operation is successful or with a single error argument if the operation failed for any reason.


<a name="lmdb_put"></a>

lmdb#put(key, value[, options], callback)

<code>put()</code> is an instance method on an existing database object, used to store new entries, or overwrite existing entries in the LMDB store.

The key and value objects may either be Strings or Node.js Buffer objects and cannot be undefined or null. Other object types are converted to JavaScript Strings with the toString() method and the resulting String may not be a zero-length. A richer set of data-types are catered for in LevelUP.

The callback function will be called with no arguments if the operation is successful or with a single error argument if the operation failed for any reason.


<a name="lmdb_get"></a>

lmdb#get(key[, options], callback)

<code>get()</code> is an instance method on an existing database object, used to fetch individual entries from the LMDB store.

The key object may either be a String or a Node.js Buffer object and cannot be undefined or null. Other object types are converted to JavaScript Strings with the toString() method and the resulting String may not be a zero-length. A richer set of data-types are catered for in LevelUP.

options

The callback function will be called with a single error if the operation failed for any reason. If successful the first argument will be null and the second argument will be the value as a String or Buffer depending on the asBuffer option.


<a name="lmdb_del"></a>

lmdb#del(key[, options], callback)

<code>del()</code> is an instance method on an existing database object, used to delete entries from the LMDB store.

The key object may either be a String or a Node.js Buffer object and cannot be undefined or null. Other object types are converted to JavaScript Strings with the toString() method and the resulting String may not be a zero-length. A richer set of data-types are catered for in LevelUP.

The callback function will be called with no arguments if the operation is successful or with a single error argument if the operation failed for any reason.


<a name="lmdb_batch"></a>

lmdb#batch(operations[, options], callback)

<code>batch()</code> is an instance method on an existing database object. Used for very fast bulk-write operations (both put and delete). The operations argument should be an Array containing a list of operations to be executed sequentially, although as a whole they are executed within a single transaction on LMDB. Each operation is contained in an object having the following properties: type, key, value, where the type is either 'put' or 'del'. In the case of 'del' the 'value' property is ignored. Any entries with a 'key' of null or undefined will cause an error to be returned on the callback and any 'type': 'put' entry with a 'value' of null or undefined will return an error. See LevelUP for full documentation on how this works in practice.

The callback function will be called with no arguments if the operation is successful or with a single error argument if the operation failed for any reason.


<a name="lmdb_iterator"></a>

lmdb#iterator([options])

<code>iterator()</code> is an instance method on an existing database object. It returns a new Iterator instance which abstracts an LMDB "cursor".

options

The optional options object may contain:


<a name="iterator_next"></a>

iterator#next(callback)

<code>next()</code> is an instance method on an existing iterator object, used to increment the underlying LMDB cursor and return the entry at that location.

the callback function will be called with no arguments in any of the following situations:

Otherwise, the callback function will be called with the following 3 arguments:


<a name="iterator_end"></a>

iterator#end(callback)

<code>end()</code> is an instance method on an existing iterator object. The underlying LMDB cursor will be deleted and the callback function will be called with no arguments if the operation is successful or with a single error argument if the operation failed for any reason.

<a name="support"></a> Getting support

There are multiple ways you can find help in using LMDB / LevelUP / LevelDB in Node.js:

<a name="contributing"></a> Contributing

Node.js LMDB is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the CONTRIBUTING.md file for more details.

<a name="licence"></a> Licence & copyright

Copyright (c) 2012-2013 Node.js LMDB contributors.

Node.js LMDB is licensed under an MIT +no-false-attribs license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.

Node.js LMDB builds on the excellent work of the Howard Chu of Symas Corp and additional contributors. LMDB are both issued under the The OpenLDAP Public License.