mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-08 23:26:37 +00:00
Update usage in README
This commit is contained in:
parent
085cf4775f
commit
cbb149ffa1
28
README.md
28
README.md
@ -40,7 +40,7 @@ _See Usage below_
|
|||||||
|
|
||||||
.get(key) // Retrieve value
|
.get(key) // Retrieve value
|
||||||
|
|
||||||
.remove({ key: <key or hash> }) // Remove entry
|
.del({ key: <key or hash> }) // Remove entry
|
||||||
|
|
||||||
.setMode(modes) // Set channel modes, can be an object or an array of objects
|
.setMode(modes) // Set channel modes, can be an object or an array of objects
|
||||||
|
|
||||||
@ -65,16 +65,19 @@ async(() => {
|
|||||||
const orbit = OrbitClient.connect(host, username, password);
|
const orbit = OrbitClient.connect(host, username, password);
|
||||||
|
|
||||||
const channelName = 'hello-world';
|
const channelName = 'hello-world';
|
||||||
|
const db = orbit.channel(channelName);
|
||||||
|
|
||||||
/* Event Log */
|
/* Event Log */
|
||||||
const hash = orbit.channel(channelName).add('hello'); // <ipfs-hash>
|
const hash = db.add('hello'); // <ipfs-hash>
|
||||||
orbit.channel(channelName).remove({ key: hash });
|
|
||||||
|
// Remove event
|
||||||
|
db.remove(hash);
|
||||||
|
|
||||||
// Iterator options
|
// Iterator options
|
||||||
const options = { limit: -1 }; // fetch all messages
|
const options = { limit: -1 }; // fetch all messages
|
||||||
|
|
||||||
// Get events
|
// Get events
|
||||||
const iter = orbit.channel(channelName).iterator(options); // Symbol.iterator
|
const iter = db.iterator(options); // Symbol.iterator
|
||||||
const next = iter.next(); // { value: <item>, done: false|true}
|
const next = iter.next(); // { value: <item>, done: false|true}
|
||||||
|
|
||||||
// OR:
|
// OR:
|
||||||
@ -85,20 +88,21 @@ async(() => {
|
|||||||
// console.log(i.hash, i.item);
|
// console.log(i.hash, i.item);
|
||||||
|
|
||||||
/* KV Store */
|
/* KV Store */
|
||||||
orbit.channel(channelName).put("key1", "hello world");
|
db.put('key1', 'hello world');
|
||||||
orbit.channel(channelName).get("key1"); // returns "hello world"
|
db.get('key1'); // returns "hello world"
|
||||||
orbit.channel(channelName).remove("key1");
|
db.remove('key1');
|
||||||
|
|
||||||
/* Modes */
|
/* Modes */
|
||||||
const password = 'hello';
|
const password = 'hello';
|
||||||
let channelModes;
|
let channelModes;
|
||||||
channelModes = orbit.channel(channel).setMode({ mode: "+r", params: { password: password } }); // { modes: { r: { password: 'hello' } } }
|
channelModes = db.setMode({ mode: '+r', params: { password: password } }); // { modes: { r: { password: 'hello' } } }
|
||||||
channelModes = orbit.channel(channel, password).setMode({ mode: "+w", params: { ops: [orbit.user.id] } }); // { modes: { ... } }
|
const privateChannel = orbit.channel(channel, password);
|
||||||
channelModes = orbit.channel(channel, password).setMode({ mode: "-r" }); // { modes: { ... } }
|
channelModes = privateChannel.setMode({ mode: '+w', params: { ops: [orbit.user.id] } }); // { modes: { ... } }
|
||||||
channelModes = orbit.channel(channel, '').setMode({ mode: "-w" }); // { modes: {} }
|
channelModes = privateChannel.setMode({ mode: '-r' }); // { modes: { ... } }
|
||||||
|
channelModes = privateChannel.setMode({ mode: '-w' }); // { modes: {} }
|
||||||
|
|
||||||
/* Delete channel */
|
/* Delete channel */
|
||||||
const result = orbit.channel(channelName, channelPwd).delete(); // true | false
|
const result = db.delete(); // true | false
|
||||||
})();
|
})();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user