https://github.com/e-e-e/hyperdb-stage
A staging area for hyperdb.
https://github.com/e-e-e/hyperdb-stage
Last synced: 10 months ago
JSON representation
A staging area for hyperdb.
- Host: GitHub
- URL: https://github.com/e-e-e/hyperdb-stage
- Owner: e-e-e
- Created: 2018-08-08T11:15:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-09T11:38:31.000Z (over 7 years ago)
- Last Synced: 2025-04-20T15:07:34.758Z (10 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/hyperdb-stage
- Size: 104 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# hyperdb-stage
[](https://travis-ci.org/e-e-e/hyperdb-stage) [](https://coveralls.io/github/e-e-e/hyperdb-stage?branch=master)
A staging area for [hyperdb](https://github.com/mafintosh/hyperdb).
This enables you to interact with the stage as if it is the actual hyperdb instance. Put, delete, get, create a stream of data, or whatever, exactly as you would normally. However any changes you make to the stage will not effect the actual db until you commit them.
**hyperdb-stage is not multi writer enabled.**
## Installation
```
npm install hyperdb-stage
```
## Usage
A super simple example:
```js
const hyperdb = require('hyperdb')
const createStage = require('hyperdb-stage')
const ram = require('random-access-memory')
const db = hyperdb(() => ram())
db.put('a', 'value', () => {
// simply wrap any db in stage to create a staging area
const tmp = createStage(db)
tmp.put('b', 'next value', () => {
// b is not yet available in the db until you commit
tmp.commit(() => {
// b is now committed added to the db
})
})
})
```
## API
Stage has mostly the same api as [hyperdb](https://github.com/mafintosh/hyperdb#api).
### Stage specific functions
In addition to hyperdb there are these special stage methods.
#### `stage = createStage(db)`
Takes a hyperdb instance and returns a staging area.
#### `stage.commit(callback)`
This commits staged changes to the hyperdb.
**Note:** hyperdb-stage commits the state of the staging area, not its history. Changes are committed in key hash order *not* in the order that they were added.
Callback is fired once all changes have been committed.
#### `stage.revert()`
Destroy all staged changes.
### Unsupported Hyperdb methods
The Staging area is not intended to be replicated or shared. It is a temporary in memory database for staging changes before committing them to your db instance.
As such the following methods are unsupported.
- db.key
- db.discoveryKey
- db.local
- db.on()
- db.version()
- db.checkout(version)
- db.authorize(key, [callback])
- db.authorized(key, [callback])
- db.replicate([options])
**Note:** You can still access these methods via `staging.db` or on the original hyperdb instance.