{"name":"subleveldown","version":"1.0.0","description":"sublevels implemented using leveldowns","main":"index.js","dependencies":{"abstract-leveldown":"^2.1.0","level-option-wrap":"^1.1.0","levelup":"^0.19.0"},"devDependencies":{"memdb":"^0.2.0"},"repository":{"type":"git","url":"https://github.com/mafintosh/subleveldown.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/subleveldown/issues"},"homepage":"https://github.com/mafintosh/subleveldown","directories":{"test":"test"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"gitHead":"b80259d64c773868e97eca024090b3cf6993d105","_id":"subleveldown@1.0.0","_shasum":"ec0c9010e1362343039078bede0c17726c2e1174","_from":".","_npmVersion":"2.1.8","_nodeVersion":"0.10.33","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"dist":{"shasum":"ec0c9010e1362343039078bede0c17726c2e1174","tarball":"http://registry-npm.ywwl.com/subleveldown/download/subleveldown-1.0.0.tgz","integrity":"sha512-2PFt/p56WqN36SRHO6xrLtTt+Nt8bdgFwmPTGKZqbTLjbUvHSr7i7CfwUh0ERDeGRC+x6JYgxINL+0XuRwdcZg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA48oEnSYlnArStR/9YHAoVT0D4Pxr6QBUxoRWl98CsXAiEAyPaCAeZMsN+CzPajjQxl7xg+TsWUR+kdTzp3CZnAzF4="}],"size":3398,"noattachment":false,"key":"/subleveldown/-/subleveldown-1.0.0.tgz"},"readme":"# subleveldown\n\n> Split a [`levelup`][levelup] database into _sublevels_ with their own keyspace, encoding and events.\n\n[![level badge][level-badge]](https://github.com/Level/awesome)\n[![npm](https://img.shields.io/npm/v/subleveldown.svg)](https://www.npmjs.com/package/subleveldown)\n[![Node version](https://img.shields.io/node/v/subleveldown.svg)](https://www.npmjs.com/package/subleveldown)\n[![Test](https://img.shields.io/github/workflow/status/Level/subleveldown/Test?label=test)](https://github.com/Level/subleveldown/actions/workflows/test.yml)\n[![Coverage](https://img.shields.io/codecov/c/github/Level/subleveldown?label=&logo=codecov&logoColor=fff)](https://codecov.io/gh/Level/subleveldown)\n[![Standard](https://img.shields.io/badge/standard-informational?logo=javascript&logoColor=fff)](https://standardjs.com)\n[![Common Changelog](https://common-changelog.org/badge.svg)](https://common-changelog.org)\n[![Donate](https://img.shields.io/badge/donate-orange?logo=open-collective&logoColor=fff)](https://opencollective.com/level)\n\n## Table of Contents\n\n<details><summary>Click to expand</summary>\n\n- [Usage](#usage)\n- [Background](#background)\n- [API](#api)\n  - [`subdb = sub(db[, prefix][, options])`](#subdb--subdb-prefix-options)\n- [Install](#install)\n- [Contributing](#contributing)\n- [Donate](#donate)\n- [License](#license)\n\n</details>\n\n## Usage\n\n_If you are upgrading: please see [UPGRADING.md](UPGRADING.md)._\n\n```js\nconst sub = require('subleveldown')\nconst level = require('level')\n\nconst db = level('db')\nconst example = sub(db, 'example')\nconst nested = sub(example, 'nested')\n```\n\nThe `example` and `nested` db's are just regular [`levelup`][levelup] instances:\n\n```js\nexample.put('hello', 'world', function () {\n  nested.put('hi', 'welt', function () {\n    // Prints { key: 'hi', value: 'welt' }\n    nested.createReadStream().on('data', console.log)\n  })\n})\n```\n\nOr with promises and iterators:\n\n```js\nawait example.put('hello', 'world')\nawait nested.put('hi', 'welt')\n\nfor await (const [key, value] of nested.iterator()) {\n  // Prints ['hi', 'welt']\n  console.log([key, value])\n}\n```\n\nSublevels see their own keys as well as keys of any nested sublevels:\n\n```js\n// Prints:\n// { key: '!nested!hi', value: 'welt' }\n// { key: 'hello', value: 'world' }\nexample.createReadStream().on('data', console.log)\n```\n\nThey also support `db.clear()` which is very useful to empty a bucket of stuff:\n\n```js\nexample.clear(function (err) {})\n\n// Or delete a range within `example`\nexample.clear({ gt: 'hello' }, function (err) {})\n\n// With promises\nawait example.clear()\n```\n\n## Background\n\n`subleveldown` separates a [`levelup`][levelup] database into sections - or _sublevels_ from here on out. Think SQL tables, but evented, ranged and realtime!\n\nEach sublevel is a `levelup` of its own. This means it has the exact same interface as its parent database, but its own keyspace and [events](https://github.com/Level/levelup#events). In addition, sublevels are individually wrapped with [`encoding-down`][encoding-down], giving us per-sublevel encodings. For example, it's possible to have one sublevel with Buffer keys and another with `'utf8'` encoded keys. The same goes for values. Like so:\n\n```js\nsub(db, 'one', { valueEncoding: 'json' })\nsub(db, 'two', { keyEncoding: 'binary' })\n```\n\nThere is one limitation, however: keys must _encode to_ either strings or Buffers. This is not likely to affect you, unless you use custom encodings or the `id` encoding (which bypasses encodings and thus makes it your responsibility to ensure keys are either strings or Buffers). If in that case you do pass in a key that is not a string or Buffer, it will be irreversibly converted to a string.\n\nAuthored by [@mafintosh](https://github.com/mafintosh) and inspired by [`level-sublevel`][level-sublevel] by [@dominictarr](https://github.com/dominictarr), `subleveldown` has become an official part of [Level][level-org]. As `level-sublevel` is no longer under active development, we recommend switching to `subleveldown` to get the latest and greatest of the Level ecosystem. These two modules largely offer the same functionality, except for [hooks](https://github.com/dominictarr/level-sublevel#hooks) and [per-batch prefixes](https://github.com/dominictarr/level-sublevel#batches).\n\n## API\n\n### `subdb = sub(db[, prefix][, options])`\n\nReturns a `levelup` instance that uses subleveldown to prefix the keys of the underlying store of `db`. The required `db` parameter must be a `levelup` instance. Any layers that this instance may have (like `encoding-down` or `subleveldown` itself) are peeled off to get to the innermost [`abstract-leveldown`][abstract-leveldown] compliant store (like `leveldown`). This ensures there is no double encoding step.\n\nThe `prefix` must be a string. If omitted, the effective prefix is two separators, e.g. `'!!'`. If `db` is already a subleveldown-powered instance, the effective prefix is a combined prefix, e.g. `'!one!!two!'`.\n\nThe optional `options` parameter has the following `subleveldown` specific properties:\n\n- `separator` _(string, default: `'!'`)_ Character for separating sublevel prefixes from user keys and each other. Must sort before characters used in prefixes. An error will be thrown if that's not the case.\n- `open` _(function)_ Optional open hook called when the underlying `levelup` instance has been opened. The hook receives a callback which must be called to finish opening.\n\nAny other `options` are passed along to the underlying [`levelup`][levelup] and [`encoding-down`][encoding-down] constructors. See their documentation for further details.\n\n## Install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm i subleveldown -S\n```\n\n## Contributing\n\n[`Level/subleveldown`](https://github.com/Level/subleveldown) is an **OPEN Open Source Project**. This means that:\n\n> 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.\n\nSee the [Contribution Guide](https://github.com/Level/community/blob/master/CONTRIBUTING.md) for more details.\n\n## Donate\n\nSupport us with a monthly donation on [Open Collective](https://opencollective.com/level) and help us continue our work.\n\n## License\n\n[MIT](LICENSE)\n\n[level-badge]: https://leveljs.org/img/badge.svg\n\n[levelup]: https://github.com/Level/levelup\n\n[encoding-down]: https://github.com/Level/encoding-down\n\n[abstract-leveldown]: https://github.com/Level/abstract-leveldown\n\n[level-sublevel]: https://github.com/dominictarr/level-sublevel\n\n[level-org]: https://github.com/Level\n","publish_time":1419292587614,"deprecated":"Superseded by abstract-level (https://github.com/Level/community#faq)","_cnpm_publish_time":1419292587614,"dist-tags":{"latest":"6.0.1"}}