Detalhes do pacote

level

Level1.9mMIT10.0.0

Universal abstract-level database for Node.js and browsers

level, leveldb, stream, database

readme (leia-me)

level

Universal abstract-level database for Node.js and browsers. This is a convenience package that exports classic-level in Node.js and browser-level in browsers, making it an ideal entry point to start creating lexicographically sorted key-value databases.

:pushpin: Which module should I use? What is abstract-level? Head over to the FAQ.

level badge npm Node version Test Coverage Standard Common Changelog Community Donate

Usage

If you are upgrading: please see UPGRADING.md.

const { Level } = require('level')

// Create a database
const db = new Level('example', { valueEncoding: 'json' })

// Add an entry with key 'a' and value 1
await db.put('a', 1)

// Add multiple entries
await db.batch([{ type: 'put', key: 'b', value: 2 }])

// Get value of key 'a': 1
const value = await db.get('a')

// Iterate entries with keys that are greater than 'a'
for await (const [key, value] of db.iterator({ gt: 'a' })) {
  console.log(value) // 2
}

TypeScript type declarations are included and cover the methods that are common between classic-level and browser-level. Usage from TypeScript requires generic type parameters.

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

Install

With npm do:

npm install level

For use in browsers, this package is best used with browserify, webpack, rollup or similar bundlers. For a quick start, visit browserify-starter or webpack-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 to Node-API, including ARM platforms like Raspberry Pi and Android, as well as in Chromium, Firefox and Safari. For details, see Supported Platforms of classic-level and Browser Support of browser-level.

Binary keys and values are supported across the board.

API

The API of level follows that of abstract-level. For additional options and methods specific to classic-level or browser-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. The location argument must be a directory path (relative or absolute) where LevelDB will store its files, or in browsers, the name of the IDBDatabase to be opened.

Contributing

Level/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 Contribution Guide for more details.

Donate

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

License

MIT

changelog (log de mudanças)

Changelog

10.0.0 - 2025-04-20

If you are upgrading: please see UPGRADING.md.

Changed

  • Breaking: upgrade to abstract-level 3 (#248) (b27277c) (Vincent Weevers)

9.0.0 - 2024-12-01

If you are upgrading: please see UPGRADING.md.

Changed

  • Breaking: upgrade to abstract-level 2 (#247) (7d8c962) (Vincent Weevers)

8.0.1 - 2024-01-27

Fixed

  • Explicitly depend on abstract-level for TypeScript (#241) (c501868) (Hanxx).

8.0.0 - 2022-03-25

If you are upgrading: please see UPGRADING.md.

Changed

  • Breaking: switch to classic-level and browser-level (#215) (ad22b21) (Vincent Weevers).

7.0.1 - 2021-10-02

Added

  • Document new features (#207) (ad8f924) (Vincent Weevers)

Fixed

  • Bump dependencies to prevent dedupe (7083ec6) (Vincent Weevers)
  • Clarify close() documentation (#197) (c82fdbc) (Vincent Weevers)

7.0.0 - 2021-04-17

If you are upgrading: please see UPGRADING.md.

Changed

  • Breaking: bump leveldown and level-packager (53bd922) (Vincent Weevers)
  • Breaking: bump level-js from 5.x to 6.x (#194) (1f6c603) (Alex Potsides)
  • Breaking: modernize syntax (Level/community#98) (d001b2c) (Vincent Weevers)
  • Add files to package.json and remove .npmignore (329e1f5) (Vincent Weevers)

Added

Removed

6.0.1 - 2020-03-04

Changed

  • Switch from opencollective-postinstall to npm funding (#173) (@Richienb)
  • Upgrade nyc devDependency from ^14.0.0 to ^15.0.0 (#169) (@vweevers)
  • Upgrade airtap devDependency from ^2.0.1 to ^3.0.0 (#171) (@vweevers)

6.0.0 - 2019-10-19

If you are upgrading: please see UPGRADING.md.

Changed

Added

Fixed

5.0.1 - 2019-03-29

Fixed

  • Temporarily skip hallmark test because it breaks CITGM (#145) (@vweevers)

5.0.0 - 2019-03-29

If you are upgrading: please see UPGRADING.md.

Changed

Added

Removed

4.0.0 - 2018-05-23

If you are upgrading: please see UPGRADING.md.

Changed

Removed

3.0.2 - 2018-05-23

Changed

3.0.1 - 2018-05-05

Added

Changed

Fixed

  • Fix postinstall failures with OpenCollective (@vweevers)

3.0.0 - 2018-02-17

If you are upgrading: please see UPGRADING.md.

Added

Changed

2.1.2 - 2018-01-26

Added

Changed

2.1.1 - 2017-12-13

Changed

2.1.0 - 2017-12-06

Changed

2.0.1 - 2017-11-11

Changed

2.0.0 - 2017-10-17

If you are upgrading: please see UPGRADING.md.

Added

Changed

2.0.0-rc3 - 2017-09-16

Changed

2.0.0-rc2 - 2017-09-12

Changed

2.0.0-rc1 - 2017-09-06

Added

Changed

Removed

1.7.0 - 2017-05-17

Changed

1.6.0 - 2017-02-06

Added

Changed

Removed

1.5.0 - 2016-10-16

Added

Changed

  • Use gcc 4.8 on Travis
  • Update leveldown to ~1.5.0 (@juliangruber)

Removed

1.4.0 - 2015-11-27

Added

Changed

1.3.0 - 2015-07-29

Changed

1.2.0 - 2015-06-24

Changed

1.1.0 - 2015-06-02

Changed

1.0.0 - 2015-05-19

Changed

1.0.0-0 - 2015-05-16

Changed

0.19.1 - 2015-05-05

Changed

  • Use n instead of nvm on Travis for iojs support on native modules (@ralphtheninja)

0.19.0 - 2015-05-05

Changed

0.18.0 - 2013-11-18

Added

Changed

  • Update level-packager to ~0.18.0 (@rvagg)
  • Update leveldown to ~0.10.0 (@rvagg)

0.17.0 - 2013-10-01

0.17.0 and 0.17.0-1 are listed out of order here, due to 0.17.0-1 not adhering to the semver rules that we follow today.

Changed

  • Update levelup to ~0.17.0 (@rvagg)
  • Update leveldown to ~0.9.0 (@rvagg)

0.17.0-1 - 2013-10-09

Changed

  • Use level-packager instead of levelup (@rvagg)
  • Run tests in level-packager using tape (@rvagg)

0.16.0 - 2013-09-10

Added

Changed

  • Update levelup to ~0.16.0 (@rvagg)
  • Update repository and homepage in package.json (@rvagg)

0.15.0 - 2013-08-26

Changed

  • README: tweaks (@rvagg)
  • Update levelup to ~0.15.0 (@rvagg)
  • Update leveldown to ~0.8.0 (@rvagg)

0.14.0 - 2013-08-19

Added

  • README: add npm downloads badge (@rvagg)

Changed

  • Update levelup to ~0.14.0 (@rvagg)

0.13.0 - 2013-08-11

Changed

  • Update levelup to ~0.13.0 (@rvagg)
  • Update leveldown to ~0.7.0 (@rvagg)

0.12.0 - 2013-07-25

Changed

  • Update levelup to ~0.12.0 (@rvagg)
  • Update leveldown to ~0.6.2 (@rvagg)

0.11.0 - 2013-07-17

Added

Changed

  • Update levelup to ~0.11.0 (@rvagg)

0.10.0 - 2013-06-14

Changed

  • Update levelup to ~0.10.0 (@rvagg)
  • Update leveldown to ~0.6.0 (@rvagg)

0.9.0 - 2013-05-27

Changed

  • Update levelup to ~0.9.0 (@rvagg)
  • Update leveldown to ~0.5.0 (@rvagg)

0.8.0 - 2013-05-19

:seedling: Initial release.