1 | # MemDOWN
|
2 |
|
3 | <img alt="LevelDB Logo" height="100" src="http://leveldb.org/img/logo.svg">
|
4 |
|
5 | **A drop-in replacement for [LevelDOWN](https://github.com/rvagg/node-leveldown) that works in memory only. Can be used as a back-end for [LevelUP](https://github.com/rvagg/node-levelup) rather than an actual LevelDB store.**
|
6 |
|
7 | [![NPM](https://nodei.co/npm/memdown.png?downloads=true)](https://nodei.co/npm/memdown/)
|
8 |
|
9 | [![Travis](https://secure.travis-ci.org/Level/memdown.png)](http://travis-ci.org/Level/memdown)
|
10 |
|
11 | [![testling](http://ci.testling.com/rvagg/memdown.png)](http://ci.testling.com/rvagg/memdown)
|
12 |
|
13 | As of version 0.7, LevelUP allows you to pass a `'db'` option when you create a new instance. This will override the default LevelDOWN store with a LevelDOWN API compatible object. MemDOWN conforms exactly to the LevelDOWN API but only performs operations in memory, so your data is discarded when the process ends or you release a reference to the database.
|
14 |
|
15 | ## Example
|
16 |
|
17 | ```js
|
18 | var levelup = require('levelup')
|
19 | // note that if multiple instances point to the same location,
|
20 | // the db will be shared, but only per process
|
21 | , db = levelup('/some/location', { db: require('memdown') })
|
22 |
|
23 | db.put('name', 'Yuri Irsenovich Kim')
|
24 | db.put('dob', '16 February 1941')
|
25 | db.put('spouse', 'Kim Young-sook')
|
26 | db.put('occupation', 'Clown')
|
27 |
|
28 | db.readStream()
|
29 | .on('data', console.log)
|
30 | .on('close', function () { console.log('Show\'s over folks!') })
|
31 | ```
|
32 |
|
33 | Note in this example we're not even bothering to use callbacks on our `.put()` methods even though they are async. We know that MemDOWN operates immediately so the data will go straight into the store.
|
34 |
|
35 | Running our example gives:
|
36 |
|
37 | ```
|
38 | { key: 'dob', value: '16 February 1941' }
|
39 | { key: 'name', value: 'Yuri Irsenovich Kim' }
|
40 | { key: 'occupation', value: 'Clown' }
|
41 | { key: 'spouse', value: 'Kim Young-sook' }
|
42 | Show's over folks!
|
43 | ```
|
44 |
|
45 | Global Store
|
46 | ---
|
47 |
|
48 | Even though it's in memory the location parameter does do something. Memdown
|
49 | has a global cache which it uses to save databases by the path string. You may
|
50 | clear this via the Memdown.clearGlobalStore function. By default it doesn't delete
|
51 | the store but replaces it with a new one, open instance of memdown will not be affected. `clearGlobalStore` takes a single parameter, which if truthy clears the store strictly by deleting each individual key. If there is an in use instance of memdown this will
|
52 | cause the in use memdown instance to error.
|
53 |
|
54 | ## Licence
|
55 |
|
56 | MemDOWN is Copyright (c) 2013-2015 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
|