npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pql

v0.0.14

Published

## 1. What is bitquery?

Downloads

8

Readme

bitqueryd

1. What is bitquery?

bitquery is a Turing complete query language for building immutable API on Bitcoin.

f

bitquery is a portable, self-contained, and programmable query language that lets you:

  1. Query bitcoin (via bitdb) using a mongodb query language
  2. Process the result using jq, a turing complete functional programming language
  3. All within a single self-contained declarative query language.

q

Top level attributes:

  • v: version
  • q: query (MongoDB query)
  • r: response handler (powered by jq)

Learn more here: https://docs.bitdb.network

With this combination, you can create your own custom API that's:

  • portable: written in JSON, it's natively supported by all devices, OS, programming languages, and databases.
  • self-contained: since the processing function can transform the query result into any format, the query can act as a high level API.
  • programmable: combine with other queries to build apps that talk to one another based on bitcoin state

2. Build your own API from Bitcoin!

Here's a simple bitquery (You can learn more about the syntax here)

{
  "v": 3,
  "q": {
    "find": { "out.h1": "6d0c" },
    "project": { "out.$": 1 }
  }
}

When you send the query to a bitdb node, it will respond with the following result:

raw

Already super useful, but it's still raw because every item in the response is a full transaction.

We can go further by adding a processing step:

{
  "v": 3,
  "q": {
    "find": { "out.h1": "6d0c" },
    "project": {
      "out.$": 1
    }
  },
  "r": {
    "f": "[ [ .[] | .out[0] ] | group_by(.s2)[] | { topic: .[0].s2, messages: [ .[] | .s3 ] } ]"
  }
}

The "r.f" is written in jq, a Turing complete data processing language.

Thanks to this additional step, this will respond with:

api

To summarize, with bitquery:

  1. Flexible Query: You can write a portable JSON query to read from the blockchain.
  2. Response Processing: You can also add additional step to represent the processing logic, which will return your own custom immutable stream of data from bitcoin, or also known as API.
  3. Interoperable: When you mix and match these APIs together, you can create applications that trigger and talk to one another in a deterministic manner.

bitqueryd

1. What is bitqueryd?

bitqueryd is a query engine that:

  1. Connects to a bitdb node and
  2. Let you interact with bitdb using the bitquery language.

2. prerequisites

bitqueryd is a query engine that directly interfaces with a BitDB node. You must have direct access to a BitDB node through either a local or remote MongoDB URL. (An HTTP based module to come soon)

This library is for connecting directly to a BitDB MongoDB instance through mongodb:// url and is not for HTTP access. If you're looking for a public HTTP endpoint, this library is not what you're looking for. You can instead use the HTTP-based API endpoint at bitdb.network, which takes only a couple of minutes to get your app up and running.

3. install

npm install --save bitqueryd

4. usage

First initialize, and use the returned db object to make the query.

A. Using Promises

var bitqueryd = require('bitqueryd')
var bql = {
  "v": 3,
  "q": {
    "find": { "out.h1": "6d02" },
    "limit": 50
  },
  "r": {
    "f": "[.[] | .out[0] | {h1: .h1, s2: .s2} ]"
  }
}
bitqueryd.init().then(function(db) {
  db.read(bql).then(function(response) {
    console.log("Response = ", response)
  })
})

B. Using Async-Await

var bitqueryd = require('bitqueryd')
var bql = {
  "v": 3,
  "q": {
    "find": { "out.h1": "6d02" },
    "limit": 50
  },
  "r": {
    "f": "[.[] | .out[0] | {h1: .h1, s2: .s2} ]"
  }
};
(async function () {
  let db = await bitqueryd.init();
  let response = await db.read(bql);
  console.log("Response = ", response)
})();

Note: By default bitquery connects to mongodb://localhost:27017 so you don't need to configure anything if you set up BitDB without changing anything.

5. configuration

You can set the following two options:

  1. url: BitDB Node URL
  2. timeout: Request timeout

A. url

Select the BitDB URL to connect to.

bitqueryd.init({
  url: "mongodb://localhost:27017"
}).then(function(db) {
  ...
})

B. timeout

Set request timeout in milliseconds. All BitDB requests will time out after this duration.

bitqueryd.init({
  timeout: 20000
}).then(function(db) {
  ...
})