drawers
Basic schema implementation for leveldb databases
Installation
npm install drawers
Usage
Drawers implements a schema for your leveldb database, allowing you to manage our indexes in a declarative way:
const Schema = ; { return index: "byId" schema: id: String name: String age: Number date: Date indexes: name: "byId" key: "person:$id" values name: "byDate" key: "byDate:$date:$id" valuesid name: "byAge" key: "byAge:$age:$id" valuesid ; }
The above example validates input and introduces a set of helper methods for querying your dataset:
const run = { let db = ; let values = id: name: "Matt" age: 36 date: "03-19-1979" ; let person = ; // validate input and stores indexes await person; // load person from db let myPerson = await person; // schema values have getters console; // deletes all keys and indexes await person; // stream key/values stored in the index "byAge" // we can query values between keys thanks to "bytewise" person ; }
Pagination
Pagination is supported. The last result will be a pagination key, see [./schema_test.js#L323].
person ;
Features
Drawers supports a bunch of handy features:
- Type validation using https://github.com/mvhenten/izza.
- Declarative indexes
- Tansform streams for results from indexes
- Pagination on streams
- Coerce values from input
- Stream JSON fragments (for http chunking)
- Stream utilities for transforming data
- sublevel indexes
see /fixtures/person.js for schema implemenation see /schema_test.js for tests