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

epiquery2-client

v0.0.15

Published

Client for epiquery2

Downloads

29

Readme

Overview

TL;DR - Go use the EpiBufferingClient.

Get it

npm install epiquery2-client

These are the clients that are available for the epiquery2 service.

  1. EpiBufferingClient (recommended)
  2. EpiClient

Out of the box, they feature automatic reconnect, failover and socket hunting. Due to this, all clients can be configured with either a single epiquery endpoint or multiple endpoints.

var EpiClient = require("epiquery2-client").EpiClient;

var singleServerClient = new EpiBufferingClient('ws://localhost:7171/sockjs/websocket');

var multiServerClient = new EpiBufferingClient([
    'ws://localhost:7171/sockjs/websocket',
    'ws://localhost:8181/sockjs/websocket',
]);

EpiBufferingClient

This is probably the simplest way to start querying. You can either specify a call back for querying or you can use promises.

var EpiBufferingClient = require("epiquery2-client").EpiBufferingClient;

var client = new EpiBufferingClient('ws://localhost:7171/sockjs/websocket');

//Use a promise
p = client.exec("glglive", 'councilMember/game/getAchievements.mustache', {cmId: 28})
p.then(function(results) { console.log(results); });
p.fail(function(err) { console.log(err); })

//Use a callback
client.exec("glglive", 'councilMember/game/getAchievements.mustache', {cmId: 28}, function(err, results){
    console.log(err, results);
});

The results returned to the callback and promise is an array of row sets. Each row set is an array of rows. Each row is an object whose fields are named after the columns of the query. Each field contains the value of its associated column.

To visualize,

[ //Row Sets
    [ //Row Set 0
        { //Row 0
            "USER_ID": "4321", //Column 0
            "FAVORITE_COLOR": "Red" //Column 1
        }, 
        { //Row 1
            "USER_ID": "6789", //Column 0
            "FAVORITE_COLOR": "Blue" //Column 1
        } 
    ],
    [ //Row Set 1
        { "COUNTRY": "USA" }, //Row 0
        { "COUNTRY": "Canada" } //Row 1
    ]
]

As a warning, uniquely name all of your columns. Otherwise, the last identically named column to be read will "win" and you'll never see the other values.

EpiClient

The vanilla EpiClient gives you more control over the lifecycle of the query. The main difference with the EpiBufferingClient is that you pass a queryId to the query function and then monitor the events of the client so that you can correlate the original query to the data you're building.

Most of the time, you probably don't need this level of control. Use discretion. Here's an example of multiple, concurrent queries (this is not an issue with the EpiBufferingClient).

var EpiClient = require("epiquery2-client").EpiClient;

var client = new EpiClient('ws://localhost:7171/sockjs/websocket');

var oneRows = [];
var twoRows = [];
var queryOne = '1';
var queryTwo = '2';

client.onrow = function(msg){
    if(msg.queryId == queryOne){
        oneRows.push(msg.columns);
    } 
    if(msg.queryId == queryTwo) {
        twoRows.push(msg.columns);
    }
};

client.onendquery = function(msg){
    if(msg.queryId == queryOne){
        console.log("All done with query one", oneRows);
    } 
    if(msg.queryId == queryTwo) {
        console.log("All done with query two", twoRows);
    }
};

client.query("glglive", 'councilMember/game/getAchievements.mustache', {cmId: 1}, queryOne);

client.query("glglive", 'councilMember/game/getAchievements.mustache', {cmId: 2}, queryTwo);

The rows are collected in the onrow callback outlined above. The message passed to this event contains a field called columns that is an array of key/value pairs. The key is the name of the column and the value is the value of that column being returned. Here is an example message.

{
    "queryId": "1234",  //Optional
    "columns": [
        {
            "USER_ID": "4321"
        },
        {
            "ACTIVE_IND": 1
        },
        {
            "FAVORITE_COLOR": "Red"
        }
    ]
}