Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Universal abstract-level database for Node.js and browsers.

License

NotificationsYou must be signed in to change notification settings

Level/level

Repository files navigation

Universalabstract-level database for Node.js and browsers. This is a convenience package that exportsclassic-level in Node.js andbrowser-level in browsers, making it an ideal entry point to start creating lexicographically sorted key-value databases.

📌 Which module should I use? What isabstract-level? Head over to theFAQ.

level badgenpmNode versionTestCoverageStandardCommon ChangelogCommunityDonate

Usage

If you are upgrading: please seeUPGRADING.md.

const{ Level}=require('level')// Create a databaseconstdb=newLevel('example',{valueEncoding:'json'})// Add an entry with key 'a' and value 1awaitdb.put('a',1)// Add multiple entriesawaitdb.batch([{type:'put',key:'b',value:2}])// Get value of key 'a': 1constvalue=awaitdb.get('a')// Iterate entries with keys that are greater than 'a'forawait(const[key,value]ofdb.iterator({gt:'a'})){console.log(value)// 2}

TypeScript type declarations are included and cover the methods that are common betweenclassic-level andbrowser-level. Usage from TypeScript requires generic type parameters.

TypeScript example
// Specify types of keys and values (any, in the case of json).// The generic type parameters default to Level<string, string>.constdb=newLevel<string,any>('./db',{valueEncoding:'json'})// All relevant methods then use those typesawaitdb.put('a',{x:123})// Specify different types when overriding encoding per operationawaitdb.get<string,string>('a',{valueEncoding:'utf8'})// Though in some cases TypeScript can infer themawaitdb.get('a',{valueEncoding:db.valueEncoding('utf8')})// It works the same for sublevelsconstabc=db.sublevel('abc')constxyz=db.sublevel<string,any>('xyz',{valueEncoding:'json'})

Install

Withnpm do:

npm install level

For use in browsers, this package is best used withbrowserify,webpack,rollup or similar bundlers. For a quick start, visitbrowserify-starter orwebpack-starter.

Supported Platforms

At the time of writing,level works in Node.js 18+ and Electron 30+ on Linux, Mac OS and Windows, including any future Node.js and Electron release thanks toNode-API, including ARM platforms like Raspberry Pi and Android, as well as in Chromium, Firefox and Safari. For details, seeSupported Platforms ofclassic-level andBrowser Support ofbrowser-level.

Binary keys and values are supported across the board.

API

The API oflevel follows that ofabstract-level. For additional options and methods specific toclassic-level orbrowser-level, please see their respective READMEs. The documentation below only covers the common constructor.

db = new Level(location[, options])

Create a new database or open an existing database. Thelocation argument must be a directory path (relative or absolute) where LevelDB will store its files, or in browsers, the name of theIDBDatabase to be opened.

Contributing

Level/level is anOPEN 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 theContribution Guide for more details.

Donate

Support us with a monthly donation onOpen Collective and help us continue our work.

License

MIT


[8]ページ先頭

©2009-2025 Movatter.jp