river icon indicating copy to clipboard operation
river copied to clipboard

Allow using database/sql driver with functioning pgx listener

Open bgentry opened this issue 1 year ago • 2 comments

Building on #351, this PR allows users to take advantage of the new riverdatabasesql driver while also keeping full support for LISTEN and avoiding poll-only mode.

This is accomplished through a riverdatabasesql.NewWithListener() constructor that allows the database/sql driver to be used with a functioning listener implementation. Also adds a riverpgxv5.NewListener() constructor to allow creating a listener with a raw pgx pool.

These can be combined to allow full listener support as long as the underlying database driver supports it, even when it's used within an abstraction like database/sql or Bun.

Needs tests if we want to proceed with this. I'm pleased with how little code it took to achieve though!

You could imagine this being used in the future with a non-Postgres listener implementation such as Redis, though for that to work we may need to loosen notifications to be emitted outside of a transaction (and may not be able to emit them automatically at all for the *Tx insert variants bc we cannot tell when a transaction completes).

bgentry avatar May 14 '24 02:05 bgentry

Any news on this? It would be incredible to get LISTEN/NOTIFY using the standard driver!

leaanthony-sc avatar Feb 28 '25 05:02 leaanthony-sc

Indeed, this would be nice to have. Is this being worked on?

dragondgold avatar Apr 08 '25 03:04 dragondgold