# bdb

> Database for bcoin

Latest version **1.6.2** (published 2024-12-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install bdb
pnpm add bdb
yarn add bdb
bun add bdb
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.2 |
| Published | 2024-12-10 |
| First published | 2017-10-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 2 |
| Unpacked size | 843.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 17 |
| Author | Christopher Jeffrey |
| Maintainers | chjj, nodweber, pinheadmz |
| Keywords | database, db, leveldb |

## Links

- npm: https://www.npmjs.com/package/bdb
- Repository: https://github.com/bcoin-org/bdb
- Issues: https://github.com/bcoin-org/bdb/issues
- npm.io page: https://npm.io/package/bdb

## Dependencies (2)

- [bsert](https://npm.io/package/bsert.md) ~0.0.13
- [loady](https://npm.io/package/loady.md) ~0.0.5

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.6.2 (latest) — 2024-12-10
- 1.6.1 — 2024-11-05
- 1.6.0 — 2024-06-17
- 1.5.2 — 2024-04-26
- 1.5.1 — 2023-09-27
- 1.5.0 — 2023-09-01
- 1.4.0 — 2022-05-15
- 1.3.0 — 2020-08-17
- 1.2.2 — 2020-06-13
- 1.2.1 — 2020-03-05
- 1.1.7 — 2019-03-21
- 1.1.6 — 2019-03-21
- 1.1.5 — 2019-01-22
- 1.1.4 — 2019-01-22
- 1.1.3 — 2018-11-29
- … 14 more at https://npm.io/package/bdb/versions

## README

# bdb

Database for bcoin (leveldown backend).

## Usage

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

await db.open();

const myPrefix = bdb.key('r');
const myKey = bdb.key('t', ['hash160', 'uint32']);

const bucket = db.bucket(myPrefix.encode());
const batch = bucket.batch();

const hash = Buffer.alloc(20, 0x11);

// Write `foo` to `rt[1111111111111111111111111111111111111111][00000000]`.
batch.put(myKey.encode(hash, 0), Buffer.from('foo'));

await batch.write();

// Iterate:
// From: `rt[0000000000000000000000000000000000000000][00000000]`
// To: `rt[ffffffffffffffffffffffffffffffffffffffff][ffffffff]`
const iter = bucket.iterator({
  gte: myKey.min(),
  lte: myKey.max(),
  values: true
});

await iter.each((key, value) => {
  // Parse each key.
  const [hash, index] = myKey.decode(key);
  console.log('Hash: %s', hash);
  console.log('Index: %d', index);
  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();
```

## Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code
to be distributed under the MIT license. You are also implicitly verifying that
all code is your original work. `</legalese>`

## License

- Copyright (c) 2017, Christopher Jeffrey (MIT License).

Parts of this software are based on leveldown:

- Copyright (c) 2017, Rod Vagg (MIT License).

See LICENSE for more info.

---
_Source: https://npm.io/package/bdb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
