-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Postgres] Add support for LISTEN/NOTIFY #131
Merged
Merged
Conversation
This file contains 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
* WAL * sync = NORMAL, thought on this for awhile, all signs point to this being a very good default for WAL usage * separate worker thread per SQLite connection
postgres, mysql: use derive for Debug for error types
This changeset introduces an interface for using PostgreSQL's LISTEN functionality from within sqlx. The listen interface is implemented over the PgConnection, PgPool & the PgPoolConnection types for ease of use. In the case of PgPool, a new connection is acquired, and is then used for LISTEN functionality. Closes #87
Extension traits are now being used for PgConnection, PgPoolConnection & PgPool for listen/notify functionality. Only two extension traits were introduced. Only a single trait method is present on the extension traits and it works for single or multi channel listening setups. Automatic reconnect behavior is implemented for PgPool based listeners. All logic has been cut over to the `recv` impls for the PgListener variants. Use async-stream for a nice Stream interface.
Broke up PgListener into two types. PgListener for basic one-off connections, and PgPoolListener for the listener created from the PgPool. The API is a bit more clear now with this change in terms of reconnect behavior and the like. Update `fn stream` to be `fn into_stream`, as that nomenclature is a bit more normative in the Rust ecosystem.
The basic PgListener stream impl now yields `Result<PgNotification>` elements without an `Option` in the result. The option condition originally represented the closure of the underlying connection. Now such conditions will terminate the stream, as one would expect. The `PgListener.recv()` method signature has not been changed. PgPoolListener has also been updated. The interfaces on this struct will never yield an inner `Option` as it will instead acquire a new connection and continue its work. Both the stream impl & the `recv` method have received an update to their signatures.
This is being removed as it was causing undesired behavior under some contexts.
…e owned or ref connections
…sed as an Executor; allow channels to be adjusted at run-time
8 tasks
@thedodd I wanted to move this to master as I was getting a bit overwhelmed with how much is not on master. This doesn't mean the API is final, so if you'd like to discuss the changes, please do so. |
Cool. I'll pull and give it an eye on master. |
@thedodd Just wrote up the changes in the opening comment here. Pinging you so you don't miss the overview. |
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.
Supersedes #98
@thedodd Take a look, I'll write up the differences more detailed soon.
https://github.com/launchbadge/sqlx/blob/e99e80cf94b46ed0e53fa314e5f6243b82a64fc3/examples/listen-postgres/src/main.rs
PgListener::new
andPgListener::from_pool
overPgPoolExt::listen
andPgConnectionExt::listen
PgListener
implementsExecutor
and it's internal connection may be re-used ( be careful though )Add
PgListener::listen
,PgListener::listen_all
,PgListener::unlisten
, andPgListener::unlisten_all
to allow run-time modification of listened channelsBorrow into the owned connection in
PgListener::recv
so the notifications are received without copy or allocation.