Created
February 27, 2019 17:49
-
-
Save mikeal/85e2f176092a6785d9f9fa5763706fcf to your computer and use it in GitHub Desktop.
stateless interface example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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