GithubHelp home page GithubHelp logo

theanmolsharma / bdb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bcoin-org/bdb

0.0 0.0 0.0 2.11 MB

Database for bcoin

License: Other

JavaScript 59.40% Python 4.79% C++ 35.32% CMake 0.49%

bdb's Introduction

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());
});

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.

bdb's People

Contributors

braydonf avatar chjj avatar nodech avatar tynes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.