@garbados/cubesat

1.0.0-alpha • Public • Published

CubeSat

stability

js-standard-style

An OrbitDB store that uses PouchDB for indexing, allowing you to perform flexible mango queries. It is based on orbit-db-docstore.

Install

Install using npm:

npm i -S @garbados/cubesat

Usage

Because CubeSat is not a core part of OrbitDB, you have to invoke it a little differently:

let name = 'test'
let ipfs = new IPFS({ EXPERIMENTAL: { pubsub: true } })
ipfs.on('ready', async (t) => {
  let orbit = new OrbitDB(ipfs, name)
  let cube = await CubeSat.create(orbit, name)
  assert(cube, 'Something went wrong?')
  await orbit.stop()
  await ipfs.stop()
  process.exit(0)
})

Once you have your cube ready to go, you can access these methods:

cube.all() -> Promise

Returns all documents in the database:

await cube.all()
> [{ _id: '...', _rev: '...' }, ...]

cube.find(query) -> Promise<Array[Object]>

Returns all documents that match the given mango query.

await cube.find({
  selector: {
    name: 'Mario'
  }
})
> [{ _id: '...', name: 'Mario'}, ...]

cube.query(query, options) -> Promise<Array[Object]>

Returns all documents that match the given map/reduce query.

await cube.query(function (doc) {
  if (doc.name === 'Luigi') {
    emit(doc._id)
  }
}.toString())
> [{ _id: '...', name: 'Luigi'}, ...]

cube.get(id) -> Promise<Object>

Returns the document with the given ID:

await cube.get('secret-recipe')
> { ingredients: [...] }

cube.del(doc) -> Promise

Deletes the given document from the database.

await cube.del({ _id: '...', _rev: '...', name: 'Mario' })

cube.put(doc) -> Promise

Same as in orbit-db-docstore:

db.put({ _id: 'QmAwesomeIpfsHash', name: 'shamb0t', followers: 500 }).then((hash) => ...)

Contributing

This library is experimental. All contributions are welcome: bug reports, feature requests, "why doesn't this work" questions, pull requests for fixes and features, etc. For all of the above, file an issue or submit a pull request.

License

Apache-2.0

Readme

Keywords

none

Package Sidebar

Install

npm i @garbados/cubesat

Weekly Downloads

1

Version

1.0.0-alpha

License

Apache-2.0

Last publish

Collaborators

  • garbados