My current setup is as such:
I have connected to my postgres database and i also have the websocket connected fine to the frontend.
But I am not sure how to use the postgres-adapter as its suggested in the documentation:
They say that you make a pool instead of a Client - thats fine for the db - then you say you use the io.adapter(createAdapter(pool));
The main functionality I want to get at is - when a change occurs on the postgresdb - then a notification gets send out just as I have currently - but then it should be connected inside the websocket for the websocket to send a message with the data to all connected clients. Has anyone implemented this?
client.connect(err => {
if (err) {
console.log("Error in connecting database: ", err);
} else {
console.log("Database connected");
client.on('notification', (msg) => {
console.log(msg.payload);
console.log(msg)
});
const query = client.query("LISTEN update_notification");
}
})
const webSocketSetup = (server) => {
var io = new Server(server, {
cors: {
origin: [
'http://localhost:3000',
]
}
});
io.on('connection', (socket) => {
console.log('a user connected');
socket.on('disconnect', () => {
console.log('user disconnected');
});
socket.on('my message', (msg) => {
"" I Want the postgres Notification to be setup here. ""
});
});
}