Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

memdown

Level814.5kMITdeprecated6.1.1TypeScript support: definitely-typed

Superseded by memory-level (https://github.com/Level/community#faq)

An drop-in replacement for LevelDOWN that works in memory only

level, leveldb, leveldown, levelup, memory

readme

memdown

In-memory abstract-leveldown store for Node.js and browsers.

level badge npm Node version Test Coverage Standard Common Changelog Donate

Example

If you are upgrading: please see UPGRADING.md.

const levelup = require('levelup')
const memdown = require('memdown')

const db = levelup(memdown())

db.put('hey', 'you', (err) => {
  if (err) throw err

  db.get('hey', { asBuffer: false }, (err, value) => {
    if (err) throw err
    console.log(value) // 'you'
  })
})

With async/await:

await db.put('hey', 'you')
const value = await db.get('hey', { asBuffer: false })

Your data is discarded when the process ends or you release a reference to the store. Note as well, though the internals of memdown operate synchronously - levelup does not.

Browser support

Sauce Test Status

Data types

Keys and values can be strings or Buffers. Any other key type will be irreversibly stringified. The only exceptions are null and undefined. Keys and values of that type are rejected.

const db = levelup(memdown())

db.put('example', 123, (err) => {
  if (err) throw err

  db.createReadStream({
    keyAsBuffer: false,
    valueAsBuffer: false
  }).on('data', (entry) => {
    console.log(typeof entry.key) // 'string'
    console.log(typeof entry.value) // 'string'
  })
})

If you desire non-destructive encoding (e.g. to store and retrieve numbers as-is), wrap memdown with encoding-down. Alternatively install level-mem which conveniently bundles levelup, memdown and encoding-down. Such an approach is also recommended if you want to achieve universal (isomorphic) behavior. For example, you could have leveldown in a backend and memdown in the frontend.

const encode = require('encoding-down')
const db = levelup(encode(memdown(), { valueEncoding: 'json' }))

db.put('example', 123, (err) => {
  if (err) throw err

  db.createReadStream({
    keyAsBuffer: false,
    valueAsBuffer: false
  }).on('data', (entry) => {
    console.log(typeof entry.key) // 'string'
    console.log(typeof entry.value) // 'number'
  })
})

Snapshot guarantees

A memdown store is backed by a fully persistent data structure and thus has snapshot guarantees. Meaning that reads operate on a snapshot in time, unaffected by simultaneous writes.

Test

In addition to the regular npm test, you can test memdown in a browser of choice with:

npm run test-browser-local

To check code coverage:

npm run coverage

Contributing

Level/memdown 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.

Big Thanks

Cross-browser Testing Platform and Open Source ♥ Provided by Sauce Labs.

Sauce Labs logo

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

License

MIT

changelog

Changelog

6.1.1 - 2021-10-02

Fixed

  • Optimize db.clear() (#213) (a0856c4) (Vincent Weevers).

6.1.0 - 2021-09-28

Added

  • Add db.getMany(keys) (#212) (9d9691a) (Vincent Weevers).

6.0.0 - 2021-04-10

If you are upgrading: please see UPGRADING.md.

Changed

5.1.0 - 2019-10-04

Changed

  • Upgrade hallmark devDependency from ^1.0.0 to ^2.0.0 (#196) (@vweevers)
  • Upgrade standard devDependency from ^13.0.1 to ^14.0.0 (#195) (@vweevers)

Added

5.0.0 - 2019-08-18

If you are upgrading: please see UPGRADING.md.

Changed

  • Upgrade abstract-leveldown from ~6.0.1 to ~6.1.0 (#194) (@vweevers)
  • Upgrade safe-buffer from ~5.1.1 to ~5.2.0 (#187) (@vweevers)
  • Upgrade hallmark devDependency from ^0.1.0 to ^1.0.0 (#189) (@vweevers)
  • Upgrade standard devDependency from ^12.0.0 to ^13.0.1 (#188) (@vweevers)

Added

Removed

  • Drop support of key & value types other than string and Buffer (#191, #192) (@vweevers)

4.1.0 - 2019-06-28

Changed

  • Upgrade nyc devDependency from ^13.2.0 to ^14.0.0 (#182) (@vweevers)

Added

4.0.0 - 2019-03-29

If you are upgrading: please see UPGRADING.md.

Changed

Added

Removed

Fixed

3.0.0 - 2018-05-22

If you are upgrading: please see UPGRADING.md.

Added

Changed

Removed

2.0.0 - 2018-02-11

If you are upgrading: please see UPGRADING.md.

Added

Changed

  • Update abstract-leveldown to 4.0.0 (@vweevers)
  • Perform serialization through idiomatic _serializeKey and _serializeValue (@vweevers)
  • Don't stringify anything except nullish values (@vweevers)
  • Use Buffer.isBuffer() instead of AbstractLevelDOWN#isBuffer (@vweevers)
  • README: update instantiation instructions for latest levelup (@kumavis)
  • README: rename "database" to "store" (@ralphtheninja)
  • README: simplify example and prefer ES6 (@vweevers)
  • Configure Greenkeeper to ignore updates to @types/node (@ralphtheninja)

Fixed

  • Don't clone Buffer in iterator (@vweevers)
  • Stringify Buffer.from() argument in iterator (@vweevers)
  • README: use SVG rather than PNG badge for Travis (@ralphtheninja)
  • README: link to abstract-leveldown (@vweevers)
  • README: normalize markdown headers (@ralphtheninja)
  • README: fix license typos (@ralphtheninja)
  • README: fix code example (@ralphtheninja)
  • Rename iterator#_end to fix conflict with abstract-leveldown (@vweevers)
  • Set zuul --concurrency to 1 to avoid hitting Sauce Labs limit (@vweevers)
  • Test on Android 6.0 instead of latest (7.1) due to Sauce Labs issue (@vweevers)

Removed

  • Remove global store (@vweevers)
  • Remove skipping of falsy elements in MemDOWN#batch (@vweevers)
  • Remove obsolete benchmarks (@vweevers)
  • Remove obsolete testBuffer from test.js (@vweevers)
  • Remove redundant testCommon parameter from most tests (@vweevers)
  • Remove unnecessary rimraf replacement for Browserify (@vweevers)
  • README: remove Greenkeeper badge (@ralphtheninja)