What is level?
The 'level' npm package is a fast and simple key-value storage library for Node.js. It provides a persistent storage solution that is easy to use and integrates well with other Node.js modules. It is built on top of LevelDB, a fast key-value storage library developed by Google.
What are level's main functionalities?
Basic CRUD Operations
This feature allows you to perform basic Create, Read, Update, and Delete (CRUD) operations on the database. The code sample demonstrates how to put a key-value pair, retrieve a value by key, and delete a key-value pair.
const level = require('level');
const db = level('./mydb');
// Put a key-value pair
await db.put('name', 'Alice');
// Get a value by key
const value = await db.get('name');
console.log(value); // 'Alice'
// Delete a key-value pair
await db.del('name');
Batch Operations
Batch operations allow you to perform multiple operations in a single atomic action. The code sample demonstrates how to use the batch method to put and delete multiple key-value pairs in one go.
const level = require('level');
const db = level('./mydb');
// Perform batch operations
await db.batch()
.put('name', 'Alice')
.put('age', 30)
.del('name')
.write();
Streams
Streams provide a way to read and write data in a continuous flow. The code sample demonstrates how to create a read stream to iterate over all key-value pairs in the database.
const level = require('level');
const db = level('./mydb');
// Create a read stream
const stream = db.createReadStream();
stream.on('data', ({ key, value }) => {
console.log(`${key} = ${value}`);
});
Other packages similar to level
nedb
NeDB is a lightweight, in-memory database that provides a MongoDB-like API. It is suitable for small projects and can be used as an embedded database. Unlike Level, NeDB stores data in memory by default, which can be less performant for large datasets.
sqlite3
SQLite3 is a self-contained, serverless, and zero-configuration SQL database engine. It is more feature-rich compared to Level, offering SQL query capabilities. However, it may be overkill for simple key-value storage needs.
pouchdb
PouchDB is an open-source JavaScript database inspired by CouchDB. It is designed to run in the browser and Node.js, providing a NoSQL database solution. PouchDB offers more advanced features like synchronization with CouchDB, which Level does not provide.
Level
Fast & simple storage - a Node.js-style LevelDB wrapper
This is a convenience package that bundles the current release of LevelUP and LevelDOWN and exposes LevelUP on its export.
Use this package to avoid having to explicitly install LevelDOWN when you just want plain old LevelDB from LevelUP.
var level = require('level')
var db = level('./mydb')
db.put('name', 'Level', function (err) {
if (err) return console.log('Ooops!', err)
db.get('name', function (err, value) {
if (err) return console.log('Ooops!', err)
console.log('name=' + value)
})
})
See LevelUP and LevelDOWN for more details.
Contributing
Level 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.
License & Copyright
Copyright (c) 2012-2017 Level contributors.
Level is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md
file for more details.