# level-memview

> in memory view on top of level.

Latest version **0.0.0** (published 2015-01-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install level-memview
pnpm add level-memview
yarn add level-memview
bun add level-memview
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2015-01-15 |
| First published | 2015-01-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Dominic Tarr |
| Maintainers | dominictarr |

## Links

- npm: https://www.npmjs.com/package/level-memview
- Repository: https://github.com/dominictarr/level-memview
- Issues: https://github.com/dominictarr/level-memview/issues
- npm.io page: https://npm.io/package/level-memview

## Dependencies (3)

- [pull-level](https://npm.io/package/pull-level.md) ~1.2.0
- [pull-stream](https://npm.io/package/pull-stream.md) ~2.26.0
- [level-live-stream](https://npm.io/package/level-live-stream.md) ~1.4.9

## Recent versions

- 0.0.0 (latest) — 2015-01-15

## README

# level-memview

in-memory view on a levelup that is always consistent.

## example

create a simple counter:

``` js
var db = level(pathToDbDir, {encoding: 'json'})
var memview = require('level-memview')

var counts = {}
var get =
  memview(db, function update (op) {
    //create some freeform datastructure that is the view.
    //sum the values by type.
    counts[op.value.type] = (counts[op.value.type] || 0) + op.value.value
  }, function get (arg, cb) {
    //query a value out of the view.
    //This function should take the arg
    //and then callback with data.
    //this function must be read-only and should not alter the view.

    return counts[arg]
  })

db.batch([
  { key: 'apple', value: { type: 'fruit', value: 6 }, type: 'put'},
  { key: 'carrot', value: { type: 'vegetable', value: 7 }, type: 'put'}
], function (err) {
  if(err) throw err
  //retrive values from the view
  get('fruit', function (err, v) {
    console.log('fruits:', v) // 6
  })
})
```

## consistency.

When initializing the view, the contents of the database will be
streamed through the update function. So that the view is always
consistent with the data, the `get` calls to retrive the value
must be a pure function, and not alter the view.

## License

MIT

---
_Source: https://npm.io/package/level-memview · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
