Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the async iterators #21

Merged
merged 6 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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