1.6.0 • Published 5 months ago

bdb v1.6.0

Weekly downloads
683
License
MIT
Repository
github
Last release
5 months ago

bdb

Database for bcoin (leveldown backend).

Usage

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.

1.6.0

5 months ago

1.5.2

6 months ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.0

2 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.1

5 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago