pubsubsql

node.js PubSubSql client library

Showing:

Popularity

Downloads/wk

1

GitHub Stars

2

Maintenance

Last Commit

6yrs ago

Contributors

3

Package

Dependencies

3

Size (min+gzip)

1.7KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

node_pubsubsql

node.js PubSubSql client library

Connecting

Minimal connection is without any options supplied. In this case, connection is attempted on default path: localhost:7777.

var pss = require('pubsubsql'),
    client = pss.createClient();

Connection options

Options are supplied to createClient method as an object.

Supported options:

  • path Complete server endpoint in format host:port, e.g. 127.0.0.1:7777
  • host Server host, e.g. 127.0.0.1
  • port Server port, e.g. 7777
  • family Connection type, either IPv6 or IPv4. Default is autodetected from host.

Extended example:

var pss = require('pubsubsql'),
    client = pss.createClient({
        path: "127.0.0.1:7777",
        family: "IPv4"
    });

Running commands

All commands are ran using query command which accepts two parameters: command itself and callback function. Callback function is triggered when server responds to the query. In case of subscription, callback is called repeatedly every time new data is published.

Function example:

client.query('tag Stocks MarketCap', function(err, response) {
    console.log("GOT RESPONSE for tag:", response, err);
});

Subscribing to data

The following example sets up client connection and once the connection is ready it subscribes to changes in Stocks table when MarketCap value is MEGA CAP.

var pss = require('pubsubsql'),
    client = pss.createClient();

client.on('error', function(err){
    console.error('Got error:', err.message);
});

client.on('end', function(){
    console.log('CONNECTION ENDED');
});

client.on('ready', function() {
    console.log('CONNECTION READY');

    client.query("subscribe * from Stocks where MarketCap = 'MEGA CAP'", function(err, response) {
        if (err) {
            console.error("[subscription] error:", err);
            return;
        }
        if (response.action === 'subscribe') {
            console.log('[subscription] subscription confirmed!');
        } else if (response.action === 'add'){
            console.log('[subscription] initial data!', response);
        } else if (response.action === 'insert'){
            console.log('[subscription] new data!', response);
        }
    });
})

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial