Skip to content

Commit

Permalink
Merge PR #21 from 'nodech/async-iterator'
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Sep 1, 2023
2 parents 29087f9 + d95bfad commit c4d4fad
Show file tree
Hide file tree
Showing 6 changed files with 908 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run: npm i -g bslint

- name: Lint
run: npm run lint-ci
run: npm run lint

build:
name: Build & Test
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Database for bcoin (leveldown backend).

## Usage

``` js
```javascript
const bdb = require('bdb');
const db = bdb.create('/path/to/my.db');

Expand Down Expand Up @@ -40,6 +40,22 @@ await iter.each((key, value) => {
console.log('Value: %s', value.toString());
});

// Async Iterator is same, just used with for await syntax.:
// From: `rt[0000000000000000000000000000000000000000][00000000]`
// To: `rt[ffffffffffffffffffffffffffffffffffffffff][ffffffff]`
const asyncIter = bucket.iterator({
gte: myKey.min(),
lte: myKey.max(),
values: true
});

for await (const {key, value} of asyncIter) {
const [hash, index] = myKey.decode(key);
console.log('Hash: %s', hash.toString('hex'));
console.log('Index: %d', index);
console.log('Value: %s', value.toString());
}

await db.close();
```

Expand Down
Loading

0 comments on commit c4d4fad

Please sign in to comment.