fix: add notifications to generic client
This commit is contained in:
parent
c7abba1e13
commit
039be77d99
@ -1,13 +1,14 @@
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use tokio_postgres::Column;
|
||||
use fallible_iterator::FallibleIterator;
|
||||
use tokio_postgres::{Column, Notification};
|
||||
use tokio_postgres::row::RowIndex;
|
||||
use tokio_postgres::types::FromSql;
|
||||
|
||||
use crate::types::{BorrowToSql, ToSql, Type};
|
||||
use crate::{
|
||||
Client, CopyInWriter, CopyOutReader, Error, Row, RowIter, SimpleQueryMessage, Statement,
|
||||
ToStatement, Transaction
|
||||
ToStatement, Transaction, Notifications
|
||||
};
|
||||
|
||||
macro_rules! common {
|
||||
@ -106,6 +107,8 @@ pub trait GenericClient {
|
||||
type Row: GenericRow<Error = Self::Error>;
|
||||
|
||||
common!(Self::Transaction<'_>, Self::Error);
|
||||
|
||||
fn block_for_notify(&mut self) -> Result<Option<Notification>, Self::Error>;
|
||||
}
|
||||
|
||||
impl GenericClient for Client {
|
||||
@ -188,6 +191,12 @@ impl GenericClient for Client {
|
||||
fn transaction(&mut self) -> Result<Self::Transaction<'_>, Error> {
|
||||
self.transaction()
|
||||
}
|
||||
|
||||
fn block_for_notify(&mut self) -> Result<Option<Notification>, Error> {
|
||||
let mut n = self.notifications();
|
||||
let mut n = n.blocking_iter();
|
||||
n.next()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! transaction_common {
|
||||
@ -286,6 +295,10 @@ impl GenericClient for Transaction<'_> {
|
||||
type Transaction<'a> = Transaction<'a> where Self: 'a;
|
||||
type Row = Row;
|
||||
transaction_common!(Self::Transaction<'_>);
|
||||
|
||||
fn block_for_notify(&mut self) -> Result<Option<Notification>, Self::Error> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl GenericRow for Row {
|
||||
|
@ -201,10 +201,11 @@ where
|
||||
|
||||
/// An asynchronous notification.
|
||||
#[derive(Clone, Debug)]
|
||||
#[allow(missing_docs)]
|
||||
pub struct Notification {
|
||||
process_id: i32,
|
||||
channel: String,
|
||||
payload: String,
|
||||
pub process_id: i32,
|
||||
pub channel: String,
|
||||
pub payload: String,
|
||||
}
|
||||
|
||||
impl Notification {
|
||||
|
Loading…
Reference in New Issue
Block a user