mirrordb v1.0.1
mirrordb
P2P database for blind mirrors and relays, backed by RocksDB or an Hyperbee.
API
myDB = new MirrorDB(storage)
storage
is an Hypercore or a string with the path to where you want a RocksDB file to be created.
await myDB.insert(...records)
Inserts the records inside the database. Records should have the following schema:
{
key, // a fixed32 hypercore key
type, // an unsigned integer indicating the type of the key
description // optional, a string describing the mirror
}
keyStream = myDB.list()
The keyStream
is a streamx readable stream that yields the records in the database, ordered by key.
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.
keyStream = myDB.listByType(type)
Same as myDB.list()
, but yields only elements of the selected key type. Example:
const keyStream = myDB.listByType(1)
all = await keyStream.toArray()
Stream helper to simply get all the remaining entries in the stream.
record = await myDB.get(key)
Get a record from the database.
randomRecord = await myDB.random()
Get a random record from the database.
randomRecord = await myDB.randomByType(type)
Like myDB.random()
, but returns a random record of the selected key type. Example:
const randomRecord = await myDB.randomByType(0)
await myDB.delete(...keys)
Delete the keys records from the database.
CLI
mirrors insert [flags] <key>
Insert a key into the database
Flags:
--description | -d <description>
Add a description to the key
--type | -t <type>
Specify a type for the key, default is 0
mirrors get <key>
Get info about a specific key from the database
mirrors random [flags]
Get a random key from the database
Flags:
--type | -t <type>
Specify the type of the key to be randomly extracted
mirrors delete <key>
Remove a key from the database
mirrors list [flags]
Get a list of keys in the database
Flags:
--type | -t <type>
Show only keys of a specific type
mirrors replicate [key]
Seeds the database and prints its public key to console. If a database key argument is provided, it will replicate that.
License
Apache-2.0