kappa-view
Base for creating kappa-core views over LevelDB.
Materialized Views
A materialized view does two things:
- A
map
function, that maps a list of log entries to modifications to a view. In this case, a LevelDB database. - An
api
object, which are functions and variables that the view exposes in order to retrieve data from the LevelDB thatmap
writes to.
This module handles view lifecycle logic for you: normally a kappa view needs to manage storing and fetching the state of the indexer ("up to what log sequence numbers have I processed?"), as well as purging the view's LevelDB database when the version of the view gets bumped.
Example
This is a view for a very simple single-value key-value store, that maps log
entries like { key: 'foo', value: 'bar' }
to an API that allows get(key)
queries.
var kappa = var makeView = var ram = var memdb = var core = var lvl = var view = core core
outputs
null 'bar'
null 'baz'
NotFoundError: Key not found in database [nix]
API
var makeView =
var view = makeView(level, setupFunction)
Create a new view, backed by LevelDB.
Expects a LevelUP or LevelDOWN instance level
.
setupFunction
is a function that is given parameters db
(LevelDB instance)
and core
(kappa-core instance). It is called exactly once. A kappa view must
be returned, which is an object with the keys
map: function (entries, next)
: receives an array of log entries. Once you've persisted whatever changes you'd like todb
, callnext()
to signal the view is ready for the next batch of log entries.api: {}
: an object that defines API functions that the view exposes. These can have whatever names you want, be sync or async, and return whatever you'd like.
Install
With npm installed, run
$ npm install kappa-view
License
ISC