• Stars
    star
    285
  • Rank 145,115 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

memdown

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

📌 This module will soon be deprecated, because it is superseded by memory-level.

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

Donate

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

License

MIT

More Repositories

1

levelup

A wrapper for abstract-leveldown compliant stores, for Node.js and browsers.
JavaScript
4,079
star
2

level

Universal abstract-level database for Node.js and browsers.
JavaScript
1,544
star
3

leveldown

Pure C++ Node.js LevelDB binding. An abstract-leveldown compliant store.
C++
773
star
4

level-js

An abstract-leveldown compliant store on top of IndexedDB.
JavaScript
542
star
5

awesome

An open list of awesome Level modules and resources.
JavaScript
287
star
6

rocksdb

Pure C++ Node.js RocksDB binding. An abstract-leveldown compliant store.
C++
229
star
7

abstract-leveldown

An abstract prototype matching the leveldown API.
JavaScript
146
star
8

party

Open a leveldb handle multiple times.
JavaScript
146
star
9

level-rocksdb

A convenience package bundling levelup and rocksdb.
JavaScript
146
star
10

abstract-level

Abstract class for a lexicographically sorted key-value database.
JavaScript
120
star
11

subleveldown

Split a levelup database into sublevels with their own keyspace, encoding and events.
JavaScript
119
star
12

electron-demo

Demo app loading LevelDB into an Electron context.
JavaScript
79
star
13

level-ttl

Add a 'ttl' (time-to-live) option to levelup for put() and batch().
JavaScript
69
star
14

level-browserify

No longer maintained: superseded by level v5.0.0.
JavaScript
63
star
15

classic-level

An abstract-level database backed by LevelDB.
JavaScript
58
star
16

multileveldown

multilevel implemented using leveldowns with reconnect support.
JavaScript
58
star
17

browser-level

An abstract-level database for browsers, backed by IndexedDB.
JavaScript
45
star
18

leveljs.org

Source code of leveljs.org
Pug
43
star
19

community

Discussion, support and common information for projects in the community.
42
star
20

encoding-down

An abstract-leveldown implementation that wraps another store to encode keys and values.
JavaScript
41
star
21

level-hyper

A convenience package bundling levelup and leveldown-hyper.
JavaScript
30
star
22

leveldown-mobile

This project has been abandoned.
C++
27
star
23

codec

Encode keys, values and range options, with built-in or custom encodings.
JavaScript
27
star
24

memory-level

In-memory abstract-level database for Node.js and browsers.
JavaScript
25
star
25

mem

A convenience package bundling levelup and memdown.
JavaScript
24
star
26

level-ws

A basic writable stream for abstract-level databases.
JavaScript
22
star
27

packager

A levelup package helper for distributing with an abstract-leveldown compatible back-end.
JavaScript
20
star
28

level-test

Inject temporary and isolated level stores (leveldown, level-js, memdown or custom) into your tests.
JavaScript
20
star
29

deferred-leveldown

An abstract-leveldown implementation that queues operations while a real abstract-leveldown instance is being opened.
JavaScript
19
star
30

many-level

Share an abstract-level database over the network or other kind of stream.
JavaScript
17
star
31

leveldown-hyper

Pure C++ Node.js HyperLevelDB binding. An abstract-leveldown compliant store.
C++
15
star
32

errors

Error types for levelup.
JavaScript
13
star
33

web-stream

Read from an abstract-level database using Web Streams.
JavaScript
12
star
34

iterator-stream

Turn an abstract-leveldown iterator into a readable stream.
JavaScript
12
star
35

level-lmdb

This project has been abandoned.
JavaScript
11
star
36

bench

Benchmark abstract-level databases.
JavaScript
8
star
37

level-mobile

[Currently not actively maintained] Fast & simple storage - a Node.js-style LevelDB wrapper (a convenience package bundling levelup & leveldown-mobile) [requires JXcore 0.3.0.3+]
JavaScript
8
star
38

read-stream

Read from an abstract-level database using Node.js streams.
JavaScript
6
star
39

rave-level

Use a LevelDB database from multiple processes with seamless failover.
JavaScript
6
star
40

level-basho

This project has been abandoned.
JavaScript
5
star
41

webpack-starter

Demonstrates bundling level for browsers using webpack.
JavaScript
5
star
42

concat-iterator

Concatenate entries from an iterator into an array.
JavaScript
5
star
43

compose

Compose a database factory from abstract-leveldown and levelup layers.
JavaScript
4
star
44

transcoder

Encode data with built-in or custom encodings.
JavaScript
4
star
45

supports

Create a manifest describing the abilities of an abstract-level database.
JavaScript
4
star
46

level-fstream

This project has been abandoned.
JavaScript
3
star
47

lazy-open

This project has been abandoned.
JavaScript
3
star
48

typings

Experimental typing development for level repositories. Deprecated.
TypeScript
3
star
49

database

2
star
50

browserify-starter

Demonstrates bundling level for browsers using browserify.
JavaScript
2
star
51

.github

Default community health files.
1
star