[−][src]Struct sqlx::postgres::PgListener
postgres
only.A stream of asynchronous notifications from Postgres.
This listener will auto-reconnect. If the active connection being used ever dies, this listener will detect that event, create a new connection, will re-subscribe to all of the originally specified channels, and will resume operations as normal.
Implementations
impl PgListener
[src]
pub async fn connect(uri: &'_ str) -> Result<PgListener, Error>
[src]
pub async fn connect_with(pool: &'_ Pool<Postgres>) -> Result<PgListener, Error>
[src]
pub async fn listen(&'_ mut self, channel: &'_ str) -> Result<(), Error>
[src]
Starts listening for notifications on a channel. The channel name is quoted here to ensure case sensitivity.
pub async fn listen_all<'_>(
&'_ mut self,
channels: impl IntoIterator<Item = &'_ str>
) -> Result<(), Error>
[src]
&'_ mut self,
channels: impl IntoIterator<Item = &'_ str>
) -> Result<(), Error>
Starts listening for notifications on all channels.
pub async fn unlisten(&'_ mut self, channel: &'_ str) -> Result<(), Error>
[src]
Stops listening for notifications on a channel. The channel name is quoted here to ensure case sensitivity.
pub async fn unlisten_all(&'_ mut self) -> Result<(), Error>
[src]
Stops listening for notifications on all channels.
pub async fn recv(&'_ mut self) -> Result<PgNotification, Error>
[src]
Receives the next notification available from any of the subscribed channels.
If the connection to PostgreSQL is lost, it is automatically reconnected on the next
call to recv()
, and should be entirely transparent (as long as it was just an
intermittent network failure or long-lived connection reaper).
As notifications are transient, any received while the connection was lost, will not
be returned. If you'd prefer the reconnection to be explicit and have a chance to
do something before, please see try_recv
.
Example
loop { // ask for next notification, re-connecting (transparently) if needed let notification = listener.recv().await?; // handle notification, do something interesting }
pub async fn try_recv(&'_ mut self) -> Result<Option<PgNotification>, Error>
[src]
Receives the next notification available from any of the subscribed channels.
If the connection to PostgreSQL is lost, None
is returned, and the connection is
reconnected on the next call to try_recv()
.
Example
loop { // start handling notifications, connecting if needed while let Some(notification) = listener.try_recv().await? { // handle notification } // connection lost, do something interesting }
pub fn into_stream(
self
) -> impl Unpin + Stream<Item = Result<PgNotification, Error>>
[src]
self
) -> impl Unpin + Stream<Item = Result<PgNotification, Error>>
Consume this listener, returning a Stream
of notifications.
The backing connection will be automatically reconnected should it be lost.
This has the same potential drawbacks as recv
.
Trait Implementations
impl Debug for PgListener
[src]
impl<'c> Executor<'c> for &'c mut PgListener
[src]
type Database = Postgres
pub fn fetch_many<'e, 'q, E>(
self,
query: E
) -> Pin<Box<dyn Stream<Item = Result<Either<PgDone, PgRow>, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, <&'c mut PgListener as Executor<'c>>::Database>,
[src]
self,
query: E
) -> Pin<Box<dyn Stream<Item = Result<Either<PgDone, PgRow>, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, <&'c mut PgListener as Executor<'c>>::Database>,
pub fn fetch_optional<'e, 'q, E>(
self,
query: E
) -> Pin<Box<dyn Future<Output = Result<Option<PgRow>, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, <&'c mut PgListener as Executor<'c>>::Database>,
[src]
self,
query: E
) -> Pin<Box<dyn Future<Output = Result<Option<PgRow>, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, <&'c mut PgListener as Executor<'c>>::Database>,
pub fn prepare_with<'e, 'q>(
self,
query: &'q str,
parameters: &'e [PgTypeInfo]
) -> Pin<Box<dyn Future<Output = Result<PgStatement<'q>, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
[src]
self,
query: &'q str,
parameters: &'e [PgTypeInfo]
) -> Pin<Box<dyn Future<Output = Result<PgStatement<'q>, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
fn execute<'e, 'q, E>(
self,
query: E
) -> Pin<Box<dyn Future<Output = Result<<Self::Database as Database>::Done, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
[src]
self,
query: E
) -> Pin<Box<dyn Future<Output = Result<<Self::Database as Database>::Done, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
fn execute_many<'e, 'q, E>(
self,
query: E
) -> Pin<Box<dyn Stream<Item = Result<<Self::Database as Database>::Done, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
[src]
self,
query: E
) -> Pin<Box<dyn Stream<Item = Result<<Self::Database as Database>::Done, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
fn fetch<'e, 'q, E>(
self,
query: E
) -> Pin<Box<dyn Stream<Item = Result<<Self::Database as Database>::Row, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
[src]
self,
query: E
) -> Pin<Box<dyn Stream<Item = Result<<Self::Database as Database>::Row, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
fn fetch_all<'e, 'q, E>(
self,
query: E
) -> Pin<Box<dyn Future<Output = Result<Vec<<Self::Database as Database>::Row>, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
[src]
self,
query: E
) -> Pin<Box<dyn Future<Output = Result<Vec<<Self::Database as Database>::Row>, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
fn fetch_one<'e, 'q, E>(
self,
query: E
) -> Pin<Box<dyn Future<Output = Result<<Self::Database as Database>::Row, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
[src]
self,
query: E
) -> Pin<Box<dyn Future<Output = Result<<Self::Database as Database>::Row, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
fn prepare<'e, 'q>(
self,
query: &'q str
) -> Pin<Box<dyn Future<Output = Result<<Self::Database as HasStatement<'q>>::Statement, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
[src]
self,
query: &'q str
) -> Pin<Box<dyn Future<Output = Result<<Self::Database as HasStatement<'q>>::Statement, Error>> + 'e + Send, Global>> where
'q: 'e,
'c: 'e,
Auto Trait Implementations
impl !RefUnwindSafe for PgListener
impl Send for PgListener
impl Sync for PgListener
impl Unpin for PgListener
impl !UnwindSafe for PgListener
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,