Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using database/sql driver with functioning pgx listener #352

Draft
wants to merge 1 commit into
base: brandur-functional-database-sql
Choose a base branch
from

Conversation

bgentry
Copy link
Contributor

@bgentry bgentry commented May 14, 2024

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).

Add a `NewWithListener` constructor to `riverdatabasesql` that allows
the `database/sql` driver to be used with a functioning listener
implementation. Also add a `NewListener` constructor to the `riverpgxv5`
driver 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant