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

[Postgres] Add support for LISTEN/NOTIFY #131

Merged
merged 51 commits into from
Mar 17, 2020
Merged

[Postgres] Add support for LISTEN/NOTIFY #131

merged 51 commits into from
Mar 17, 2020

Conversation

mehcode
Copy link
Member

@mehcode mehcode commented Mar 17, 2020

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 and PgListener::from_pool over PgPoolExt::listen and PgConnectionExt::listen

  • PgListener implements Executor and it's internal connection may be re-used ( be careful though )

  • Add PgListener::listen, PgListener::listen_all, PgListener::unlisten, and PgListener::unlisten_all to allow run-time modification of listened channels

  • Borrow into the owned connection in PgListener::recv so the notifications are received without copy or allocation.

mehcode and others added 30 commits March 14, 2020 17:43
 * 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
thedodd and others added 21 commits March 15, 2020 02:17
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.
…sed as an Executor; allow channels to be adjusted at run-time
@mehcode mehcode merged commit c44084d into master Mar 17, 2020
@mehcode mehcode mentioned this pull request Mar 17, 2020
8 tasks
@mehcode
Copy link
Member Author

mehcode commented Mar 17, 2020

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

@thedodd
Copy link
Contributor

thedodd commented Mar 17, 2020

Cool. I'll pull and give it an eye on master.

@mehcode
Copy link
Member Author

mehcode commented Mar 17, 2020

@thedodd Just wrote up the changes in the opening comment here. Pinging you so you don't miss the overview.

@mehcode mehcode deleted the pg-listen-notify branch March 19, 2020 12:42
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.

2 participants