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

ssb-query

v2.4.5

Published

A scuttlebot plugin for querying data. With [map-filter-reduce](https://github.com/dominictarr/map-filter-reduce) you can write pretty flexible queries, similar to SQL, but more javascripty.

Downloads

338

Readme

ssb-query

A scuttlebot plugin for querying data. With map-filter-reduce you can write pretty flexible queries, similar to SQL, but more javascripty.

ssb-query is just a thin layer of glue, giving access to flumeview-query with secure-scuttlebutt data.

installation

ssb-query is included in the ssb-server distribution by default. see plugins documentation

usage

command line

if you are running ssb-server, run the following queries from another tab on the same machine.

ssb-server query.read --query '{MFR_QUERY}' options...

notice the json is inside single quotes ''. this is necessary, because " part of JSON but is handled specially on the command line.

see read api documentation for options

javascript

using ssb-client, connect to a locally running sbot and call query.read, which returns a pull-stream

require('ssb-client')(function (err, sbot) {
  if(err) throw err
  pull(
    sbot.query.read({
      query: MFR_QUERY,
      ...other options
      //limit: 10, reverse: true
    }),
    pull.collect(function (err, ary) {
      console.log(ary)
    })
  )
})

api

query.read ({query,limit,reverse,old,live})

perform a query. query is a map-filter-reduce query. limit,reverse,old and live are standard options supported by most ssb database stream apis, see createLogStream

query.explain ({query})

returns internal information about what index will be used my ssb-query. the name comes from the SQL "EXPLAIN" command

output might look like this:

{
  gte: [...], lte: [...] //if this is present, then the query will use an index.
  scan: true | false, //if scan is true, the entire database will be examined. this means a very slow query
  live, old, //wether to include new and old records
  sync: false//include a {sync: true} message after the old records have finished.
}

see flumeview-query for more information.

example queries

all messages in "solarpunk" channel.

[{
  "$filter": {
    value: {
      content: {channel: "solarpunk"}
    }
  }
}]

all replies in a thread

[{
  "$filter": {
    value: {
      content: {root: "%<msg_id>"}
    }
  }
}]

messages by a type by an author

[{
  "$filter": {
    value: {
	  author: "@<author_id>",
	  content: {
	    type: "<msg_type>"
	  }
	}
  }
}]

channels, with count and sort

most recently published channels, with timestamp and message count.

[
  {"$filter": {"value": {"content":{ "channel": {"$is": "string"}, "type": "post"}}}},
  {"$reduce": {
      "channel": ["value", "content", "channel"],
      "count": {"$count": true},
      "timestamp": {"$max": ["value", "timestamp"]}
  }},
  {"$sort": [["timestamp"], ["count"]]}
]

sample output:


{
  "channel": "heropunch",
  "count": 83,
  "timestamp": 1537465741596
}

{
  "channel": "walkaway",
  "count": 43,
  "timestamp": 1537471373721
}

{
  "channel": "music",
  "count": 635,
  "timestamp": 1537474414933
}

indexes

indexes make your queries much faster. read about flumeview-query indexes

currently supported indexes:

var indexes = [
  {key: 'log', value: ['timestamp']},
  {key: 'clk', value: [['value', 'author'], ['value', 'sequence']] },
  {key: 'typ', value: [['value', 'content', 'type'], ['timestamp']] },
  {key: 'tya', value: [['value', 'content', 'type'], ['value', 'timestamp']] },
  {key: 'cha', value: [['value', 'content', 'channel'], ['timestamp']] },
  {key: 'aty', value: [['value', 'author'], ['value', 'content', 'type'], ['timestamp']]},
  {key: 'ata', value: [['value', 'author'], ['value', 'content', 'type'], ['value', 'timestamp']]},
  {key: 'art', value: [['value', 'content', 'root'], ['value', 'timestamp']]},
  {key: 'lor', value: [['rts']]}
]

so, because the of cha index, a query for value.content.channel and timestamp would be quick.

License

MIT