Database built for P2P and local indexing
npm install hyperdb
First generate your definition with the builder. The definition defines the schemas and collections you wanna use.
// TODO (see ./example here for now)
Then boot your db. You can use the same definition for a fully local db and a P2P one.
const HyperDB = require('hyperdb')
// first choose your engine
const db = HyperDB.rocks('./my-rocks.db', require('./my-definition'))
It is that simple.
Make a db backed by Hyperbee. P2P!
Make a db backed by RocksDB. Local only!
Query the database. collectionOrIndex
is the identifier you defined in your builder.
The query looks like this
{
gt: { ... },
gte: { ... },
lt: { ...},
lte: { ...}
}
And options include
{
limit, // how many max?
reverse // reverse stream?
}
See the basic tests for an easy example on how queries look like.
The queryStream
is a streamx readable stream that yields the documents you search for.
A query is always running on a snapshot, meaning any inserts/deletes you do while this is running will not impact the query stream itself.
Stream helper to simply get all the remaining entries in the stream.
Stream helper to simply get the last entry in the stream.
Alias for await find(...).one()
Get a document from a collection
Get stats, about a collection or index with stats enabled.
Insert a document into a collection. NOTE: you have to flush the db later for this to be persisted.
Delete a document from a collection. NOTE: you have to flush the db later for this to be persisted.
Returns a boolean indicating if this database was updated. Pass a collection and doc query to know if a specific record was updated.
Flush all changes to the db
Reload the internal snapshot. Clears the memory state.
Make a readonly snapshot of the database. All reads/streams are locked in time on a snapshot from the time you call the snapshot method.
Make a writable snapshot of the database. All reads/streams are locked in time on a snapshot from the time you call the snapshot method. When you flush this one, it updates the main instance also.
Close the database. You have to close any snapshots you use also.
See example.
Each field in the builder file is an object:
{
name: 'field-name',
type: 'uint', // a compact-encoding type, or a reference to another encoding defined in the builder file
required: true, // false for optional
array: false // Store an array of 'type', instead of just one (default false)
}
Apache-2.0