All Projects → frafra → Postgresql2websocket

frafra / Postgresql2websocket

Licence: gpl-3.0
Send PostgreSQL notifications over websockets

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects
python36
32 projects

Projects that are alternatives of or similar to Postgresql2websocket

Sockjs
SockJS Server
Stars: ✭ 105 (+81.03%)
Mutual labels:  aiohttp, websockets
Nodebb
Node.js based forum software built for the modern web
Stars: ✭ 12,303 (+21112.07%)
Mutual labels:  postgresql, websockets
Bolt Python
A framework to build Slack apps using Python
Stars: ✭ 190 (+227.59%)
Mutual labels:  aiohttp, websockets
Django Notifs
Modular Notifications (InApp, Email, SMS, CustomBackend etc) for Django
Stars: ✭ 105 (+81.03%)
Mutual labels:  notifications, websockets
Plgo
easily create postgresql extensions in golang; moved to gitlab.com/microo8/plgo
Stars: ✭ 286 (+393.1%)
Mutual labels:  postgresql, trigger
Crypto Coin Alerts
An application that let you set alerts for the prices of several cryptocurrencies
Stars: ✭ 72 (+24.14%)
Mutual labels:  postgresql, notifications
Plsh
PL/sh is a procedural language handler for PostgreSQL that allows you to write stored procedures in a shell of your choice.
Stars: ✭ 111 (+91.38%)
Mutual labels:  postgresql, trigger
Pgdeltastream
Streaming Postgres logical replication changes atleast-once over websockets
Stars: ✭ 197 (+239.66%)
Mutual labels:  postgresql, websockets
stream video server
demonstrates how to create video streaming server with the help of aiohttp and opencv
Stars: ✭ 15 (-74.14%)
Mutual labels:  websockets, aiohttp
Devicehive Java Server
DeviceHive Java Server
Stars: ✭ 241 (+315.52%)
Mutual labels:  postgresql, websockets
Pg Listen
📡 PostgreSQL LISTEN & NOTIFY for node.js that finally works.
Stars: ✭ 348 (+500%)
Mutual labels:  postgresql, notifications
Python Slack Sdk
Slack Developer Kit for Python
Stars: ✭ 3,307 (+5601.72%)
Mutual labels:  aiohttp, websockets
Supabase
The open source Firebase alternative. Follow to stay updated about our public Beta.
Stars: ✭ 25,142 (+43248.28%)
Mutual labels:  postgresql, websockets
Pg partman
Partition management extension for PostgreSQL
Stars: ✭ 1,085 (+1770.69%)
Mutual labels:  postgresql
Spring Boot Vault Demo
Demo project to show the integration of spring-boot and Hashicorp Vault
Stars: ✭ 57 (-1.72%)
Mutual labels:  postgresql
Gitlab Notifications
👍 Notifications Center for GitLab
Stars: ✭ 55 (-5.17%)
Mutual labels:  notifications
Go Websocket
🔈 Deprecated. Use https://github.com/kataras/neffos instead
Stars: ✭ 55 (-5.17%)
Mutual labels:  websockets
Aiopg
aiopg is a library for accessing a PostgreSQL database from the asyncio
Stars: ✭ 1,097 (+1791.38%)
Mutual labels:  postgresql
Postbird
Open source PostgreSQL GUI client for macOS, Linux and Windows
Stars: ✭ 1,089 (+1777.59%)
Mutual labels:  postgresql
Ptgo
PostgreSQL Triggers in Go
Stars: ✭ 55 (-5.17%)
Mutual labels:  postgresql

postgresql2websocket

CircleCI

How does it work?

Execute postgresql2websocket.py and connect to ws://localhost:8080/channel where channel is the channel name of the selected database (see PostgreSQL documentation - NOTIFY).

How to configure it?

Copy postgresql2websocket.conf.example as postgresql2websocket.conf and change the values according to your needs.

What technologies are you using?

What can I do with it?

You can create a trigger on a table in order to get notifications over a websocket in real time. For example, this function send a notification using the postgresql2websocket channel containing the action that has been performed and a JSON representation of the row.

CREATE OR REPLACE FUNCTION table_update_notify() RETURNS trigger AS $$
DECLARE
  rec RECORD;
BEGIN
  IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
    rec = NEW;
  ELSE
    rec = OLD;
  END IF;
  -- postgresql2websocket is the default channel name
  PERFORM pg_notify('postgresql2websocket', json_build_object('table', TG_TABLE_NAME, 'type', TG_OP, 'row', row_to_json(rec))::text);
  RETURN NEW;
END;
$$ LANGUAGE plpgsql;

Then you can trigger this function when something happens on mytable:

CREATE TRIGGER mytable_notify_update AFTER UPDATE ON mytable FOR EACH ROW EXECUTE PROCEDURE table_update_notify();
CREATE TRIGGER mytable_notify_insert AFTER INSERT ON mytable FOR EACH ROW EXECUTE PROCEDURE table_update_notify();
CREATE TRIGGER mytable_notify_delete AFTER DELETE ON mytable FOR EACH ROW EXECUTE PROCEDURE table_update_notify();

Bidirectional communication

The websocket channel can be used to execute remote functions too:

For example:

CREATE FUNCTION add(integer, integer) RETURNS integer
    AS 'select $1 + $2;'
    LANGUAGE SQL
    IMMUTABLE
    RETURNS NULL ON NULL INPUT;

Executing ws.send('select add(1, 2);') will return a JSON response containing {"add": 3}.

How to use it?

Execute postgresql2websocket.py, open examples/console.html and execute some operations on the table.

Limitations

The "payload" string to be communicated along with the notification. This must be specified as a simple string literal. In the default configuration it must be shorter than 8000 bytes. (If binary data or large amounts of information need to be communicated, it's best to put it in a database table and send the key of the record.)

Source: https://www.postgresql.org/docs/current/static/sql-notify.html

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].