Basic bindings to the recently implemented pgo_notifications.#78
Open
foxfriends wants to merge 2 commits intolpil:mainfrom
Open
Basic bindings to the recently implemented pgo_notifications.#78foxfriends wants to merge 2 commits intolpil:mainfrom
pgo_notifications.#78foxfriends wants to merge 2 commits intolpil:mainfrom
Conversation
4184091 to
dae5cc3
Compare
Added support for PostgreSQL `LISTEN/NOTIFY` by lightly wrapping the
implementation in `pgo`.
As in `pgo`:
* The notifications listener is started as a new process, different from a regular connection.
* The `listen(conn, channel)` function subscribes to a Postgres channel.
* `unlisten(conn, reference)` can be used to unsubscribe.
* Notifications from Postgres are sent to the process that called `listen` as the `Notify` type. Receive these using the `pog.notification_selector()`.
General usage example:
```gleam
let assert Ok(db) = pog.default_config("db")
|> pog.start()
let assert Ok(notifications) = pog.default_config("notifications")
|> pog.start_notifications()
let assert Ok(reference) = pog.listen(notifications.data, "some_channel")
let selector = pog.notification_selector()
let assert Ok(_) = pog.query("NOTIFY some_channel, 'some_payload'")
|> pog.execute(db.data)
let assert Ok(Notify(pid, ref, chan, data)) = process.selector_receive(selector, 100)
assert pid == notifications.pid
assert ref == reference
assert chan == "some_channel"
assert data = "some_payload"
pog.unlisten(notifications.data, reference)
```
Author
|
I found and patched a bug in the underlying pgo implementation, so I suggest waiting until that's merged before considering accepting this PR. Having been trying out my patch for a few days in a project, I am finding it to work fine, but maybe is not the most idiomatic Gleam; pretty new to it all, and not sure the best way to represent this system, I went with a "light" approach so far, mimicking the pgo interface, but open to suggestions to make it more "Gleam" flavoured for sure. :) |
lpil
reviewed
Feb 5, 2026
Owner
lpil
left a comment
There was a problem hiding this comment.
Thank you! I've left some questions inline
Author
|
Thanks for the notes, I have updated it, let me know if anything else :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added support for PostgreSQL
LISTEN/NOTIFYby lightly wrapping the implementation inpgo.As in
pgo:listen(conn, channel)function subscribes to a Postgres channel.unlisten(conn, reference)can be used to unsubscribe.listenas theNotifytype. Receive these using thepog.notification_selector().General usage example:
Closes #13