supabase-community / realtime-go

2 stars 3 forks source link

Handle Postgres Changes Events #4

Open IcedTea2K opened 3 months ago

IcedTea2K commented 3 months ago

What kind of change does this PR introduce?

This PR is part one of many parts to the issue https://github.com/supabase-community/realtime-go/issues/2. It implements the following few functionalities:

What is the current behavior?

None. The RealtimeClient is only able to establish and maintain the connection with the server.

What is the new behavior?

The following demo shows a simple program listening to the 4 types of events: * | UPDATE | INSERT | DELETE. After 20 seconds or so, the program unsubscribes, and stop receiving events. Demo

This is a sample response of the payload passed into the callback.

{
    "data": {
        "schema": "public",
        "table": "sample",
        "commit_timestamp": "2024-06-14T23:17:00.348Z",
        "record": {
            "age": 200,
            "created_at": "2024-06-11T03:23:28.851861+00:00",
            "id": 22
        },
        "columns": [
            {
                "name": "id",
                "type": "int8"
            },
            {
                "name": "created_at",
                "type": "timestamptz"
            },
            {
                "name": "age",
                "type": "int8"
            }
        ],
        "type": "UPDATE",
        "old_record": {
            "id": 22
        },
        "errors": ""
    },
    "ids": [
        17277040,
        49337105,
        7548478,
        24028530
    ]
}

Additional context

Apologies for a massive of a PR. A lot of these components have to come with each other before we could have a working code :(

A small comparison with the JavaScript counterpart:

groud commented 2 weeks ago

Hey! Thanks a lot for this PR, it helps us a lot!

We are creating a micro-service that would greatly benefit from realtime-go being actually usable in production. So, as it seems that this PR goes a huge step towards this goal, I'd like to know if it is currently in a working / mergeable state, and if so, whether there's a chance it gets merged soon-ish or not. In any case, I'll check the PR and see if I manage to make it work. I'll leave an approval/review here once I'm done.

@muratmirgun I see you are the maintainer the project. Pinging you to know if you still wish / have the time to work on it. No pressure, it just allows us to decide if it is worth maintaining our own fork or not.