What is leveldown?
LevelDOWN is a Node.js binding for LevelDB, a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values. It is used as a backend for the LevelUP module, which provides a more user-friendly API.
What are leveldown's main functionalities?
Open a Database
This feature allows you to open a LevelDB database. The code sample demonstrates how to open a database located at './mydb'.
const leveldown = require('leveldown');
const db = leveldown('./mydb');
db.open(function (err) {
if (err) throw err;
console.log('Database opened');
});
Put Data
This feature allows you to store a key-value pair in the database. The code sample shows how to store the value 'value' under the key 'key'.
db.put('key', 'value', function (err) {
if (err) throw err;
console.log('Data written');
});
Get Data
This feature allows you to retrieve a value by its key from the database. The code sample demonstrates how to get the value associated with the key 'key'.
db.get('key', function (err, value) {
if (err) throw err;
console.log('Data retrieved:', value);
});
Delete Data
This feature allows you to delete a key-value pair from the database. The code sample shows how to delete the key 'key' from the database.
db.del('key', function (err) {
if (err) throw err;
console.log('Data deleted');
});
Batch Operations
This feature allows you to perform multiple operations in a single batch. The code sample demonstrates how to perform a batch operation that puts and deletes multiple key-value pairs.
db.batch()
.put('key1', 'value1')
.del('key2')
.put('key3', 'value3')
.write(function (err) {
if (err) throw err;
console.log('Batch operations completed');
});
Other packages similar to leveldown
levelup
LevelUP is a higher-level module that provides a more user-friendly API for LevelDB. It uses LevelDOWN as its default backend. Compared to LevelDOWN, LevelUP offers a more convenient and feature-rich interface for interacting with LevelDB.
rocksdb
RocksDB is a high-performance key-value store developed by Facebook. It is similar to LevelDB but offers better performance and more features, such as column families and transactions. The 'rocksdb' npm package provides Node.js bindings for RocksDB.
lmdb
LMDB (Lightning Memory-Mapped Database) is a fast memory-mapped key-value store. The 'lmdb' npm package provides Node.js bindings for LMDB. Compared to LevelDOWN, LMDB offers better performance for read-heavy workloads and supports ACID transactions.
LevelDOWN
Contributing
LevelDOWN 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.
Contributors
Licence & copyright
LevelDOWN is Copyright (c) 2012 Rod Vagg and other contributors listed above.
LevelDOWN is licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
LevelDOWN builds on the excellent work of the LevelDB and Snappy teams from Google and additional contributors. LevelDB and Snappy are both issued under the New BSD Licence.