Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/frando/subhyperdb
Namespace a hyperdb into prefixed sections that may have different valueEncodings.
https://github.com/frando/subhyperdb
hyperdb
Last synced: about 1 month ago
JSON representation
Namespace a hyperdb into prefixed sections that may have different valueEncodings.
- Host: GitHub
- URL: https://github.com/frando/subhyperdb
- Owner: Frando
- License: mit
- Created: 2018-03-23T15:00:09.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-23T19:08:01.000Z (almost 7 years ago)
- Last Synced: 2024-04-25T10:21:47.963Z (8 months ago)
- Topics: hyperdb
- Language: JavaScript
- Size: 53.7 KB
- Stars: 32
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SubHyperDB
Split a [HyperDB](https://github.com/mafintosh/hyperdb) into namespaces or sections. Each SubHyperDB may have a different value encoding.
## Usage
``` js
var hyperdb = require('hyperdb')
var sub = require('subhyperdb')var db = hyperdb('./db', {valueEncoding: 'binary'})
var sub1 = sub(db, 'sub1', {valueEncoding: 'utf8'})
var sub2 = sub(db, {valueEncoding: 'json'})sub1.put('hello', 'world', function() {
sub2.put('hello', {where: 'moon'}, function() {
sub1.get('hello', function(err, node) {
console.log('sub1: ' + node.value) // world
})
sub2.get('hello', function(err, node) {
console.log('sub2: ' + JSON.stringify(node.value)) // {where: 'moon'}
})
})
})console.log('Prefix for sub1: ' + sub1.prefix) // prefix for sub1 was set manually
console.log('Prefix for sub2: ' + sub2.prefix) // prefix for sub2 was autocreated```
## API
#### `var subDb = sub(db, [prefix], [opts])`
Create a new sub database.
`db` has to be a hyperdb instance that was created with a `valueEncoding: 'binary'` option.
`prefix` sets the prefix to be used. If not set, a random prefix will be created.
`opts` So far the only option is `valueEncoding`.
Public API is a subset of the HyperDB API. Supported methods are:
`get`, `put`, `del`, `batch`, `list`, `createReadStream`, `createWriteStream`, `replicate`
Support for more methods (e.g. `createDiffStream`, `createHistoryStream`) is TODO.
## License
MIT