Skip to content

Instantly share code, notes, and snippets.

@mikeal
Created February 27, 2019 17:49
Show Gist options
  • Save mikeal/85e2f176092a6785d9f9fa5763706fcf to your computer and use it in GitHub Desktop.
Save mikeal/85e2f176092a6785d9f9fa5763706fcf to your computer and use it in GitHub Desktop.
stateless interface example
class Database {
constructor (storage) {
this.count = 0
this.storage = storage
}
async get (cid) {
this.count += 1
return this.storage.get(cid.toBaseEncodedString())
}
async put (block) {
this.count += 1
return this.storage.put(block.cid.toBaseEncodedString(), block.data)
}
}
let db = new Datebase()
let _get = cid => db.get(cid)
let selectorString = '/SOME-CID/path'
for await (let block of ipld.query(selectorString, _get)) {
await db.put(block)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment