pub struct PgNotifier { /* private fields */ }Expand description
PostgreSQL NOTIFY publisher for sending notifications
Publishes notifications to channels that listeners can receive.
Implementations§
Source§impl PgNotifier
impl PgNotifier
Sourcepub fn new(pool: PgPool) -> Self
pub fn new(pool: PgPool) -> Self
Create a new notifier using the provided connection pool
§Example
let notifier = PgNotifier::new(pool);Sourcepub async fn notify<T: Serialize>(
&self,
channel: &str,
payload: &T,
) -> Result<(), PgError>
pub async fn notify<T: Serialize>( &self, channel: &str, payload: &T, ) -> Result<(), PgError>
Send a notification to a channel
§Arguments
channel- Channel name to notifypayload- Serializable payload (will be converted to JSON)
§Errors
Returns error if:
- Payload cannot be serialized to JSON
- NOTIFY command fails
§Example
notifier.notify("warpdrive:cache:invalidate", &serde_json::json!({
"key": "user:123",
"event_type": "delete"
})).await?;Trait Implementations§
Source§impl Clone for PgNotifier
impl Clone for PgNotifier
Source§fn clone(&self) -> PgNotifier
fn clone(&self) -> PgNotifier
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PgNotifier
impl !RefUnwindSafe for PgNotifier
impl Send for PgNotifier
impl Sync for PgNotifier
impl Unpin for PgNotifier
impl !UnwindSafe for PgNotifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more