Allow using database/sql driver with functioning pgx listener #352
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.
Building on #351, this PR allows users to take advantage of the new
riverdatabasesql
driver while also keeping full support forLISTEN
and avoiding poll-only mode.This is accomplished through a
riverdatabasesql.NewWithListener()
constructor that allows thedatabase/sql
driver to be used with a functioning listener implementation. Also adds ariverpgxv5.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).