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

ably-postgres-connector

v1.0.1

Published

Ably-Postgres connector publishes a message on a given Ably channel whenever any operations (insert/update/delete) are executed on the tables of your PostgreSQL database.

Downloads

2

Readme

Streaming PostgresDB changes to millions of clients in realtime

The Ably-Postgres connector publishes a message on a given Ably channel whenever any operations (insert/update/delete) are executed on the tables of your PostgreSQL database.

You can setup the connector with the configuration details of your database, as well as the Ably app, including your API Key, channel names for various types of updates, etc.

Check out the example config for more info.

Prerequisites

Installation

    npm install ably-postgres-connector --save

Setup config

  • The first step is to add in your configuration. You can do this via env file or a JSON file.

Option 1 - Adding config via a JSON file

  • Create config/default.json file (refer to the example JSON config).
  • Add your database and Ably account credentials as needed.
Example usage
    const { Connector } = require("ably-postgres-connector");
    const useWithJSONConfig = () => {
      const ablyconnector = new Connector("config/default.json");
      ablyconnector.start();
    };
    useWithJSONConfig();
Running
    node examples/with-json-config.js

Option 2 - Adding config via a env file

  • Create config/.env file (refer to the example env config).
  • Add your database and Ably account credentials as needed.
Example usage
    const { Connector } = require("ably-postgres-connector");
    const useWithEnvConfig = () => {
      const ablyconnector = new Connector("config/.env");
      ablyconnector.start();
    };
    useWithEnvConfig();
Running (Using the example file)
    node examples/with-env-config.js

Option 3 - Adding config via a env file through docker-compose

  • Create config/.env file (refer to the example env config).
  • Add your database and Ably account credentials as needed.
  • Add path of .env file to your docker-compose file (refer to the example docker-compose).
Example usage
    const { Connector } = require("ably-postgres-connector");
    const useWithEnvDockerCompose = () => {
      const ablyconnector = new Connector();
      ablyconnector.start();
    };
    useWithEnvDockerCompose();
    # connector-block
    connector:
      build:
        context: .
      env_file: ./config/.env
      depends_on:
        - db
      ports:
        - "3000:3000"
Running (Using the example docker-compose file)
  • Uses the Docker folder to setup the postgresql image with a dummy DB & users table.
  • Uses the Dockerfile to create the container with node, build the connector & add the config file.
    docker-compose run connector

Connector in Action!

Visit your Ably dev console and connect to the channel ably-users-added (or whichever channel you specified in your config). Try performing various operations (insert, update, delete) on your table. For every change, you should see a new message in the specific channel(s).

How does the connector work?

  • The config file contains the details related to the tables you want to listen for data changes on and your Ably API key.
  • Using that config file, the connector creates an Ably config table ablycontroltable to maintain the table to Ably channel mapping in the DB.
  • The connector then creates a DB procedure/function which performs the pg_notify function that publishes data changes on a data channel.
  • The connector then creates triggers for the table-operation combination specified in the config. The job of the trigger is to execute the procedure created above.
  • The connector is listening for changes on that particular data channel using the LISTEN feature. When it gets a notification it publishes the data on the appropriate Ably channel.