psqlpy icon indicating copy to clipboard operation
psqlpy copied to clipboard

Support LISTEN/NOTIFY callback handlers

Open oliverlambson opened this issue 1 year ago • 6 comments

I'd like to be able to add a callback handler similar to asyncpg's connection.add_listener(...)

I'm agnostic on the API, if there is a more idiomatic PSQLPy abstraction or interface that's cool—I just think it would be great to have the LISTEN/NOTIFY functionality exposed

oliverlambson avatar Jan 06 '25 03:01 oliverlambson

Thanks for the feature request, we'll implement it.

chandr-andr avatar Jan 06 '25 07:01 chandr-andr

@oliverlambson Hello!

If it's possible could you please describe how you usually use this functionality?

chandr-andr avatar Jan 07 '25 09:01 chandr-andr

I use it to send notifications like events that a listener can then react to.

Being able to do that means I can implement an asynchronous message queue. I've implemented it from scratch in https://www.github.com/oliverlambson/pgmq (there are explanations there if it's helpful), and as a taskiq plugin https://www.github.com/karoo-ca/taskiq-pg

oliverlambson avatar Jan 14 '25 15:01 oliverlambson

Okay, thank you very much

I've started implementing it but it'll be different in API from asyncpg.

chandr-andr avatar Jan 14 '25 15:01 chandr-andr

Exciting!

oliverlambson avatar Jan 14 '25 17:01 oliverlambson

@oliverlambson Hello!

I've made a new release 0.9.0 with support for LISTEN functionality. It's the first variant of API, so if you have any ideas on how to make it better, please let me know.
You can read new documentation about it here - https://psqlpy-python.github.io/components/listener.html

chandr-andr avatar Jan 25 '25 19:01 chandr-andr