fix: add notifications to generic client

This commit is contained in:
orion 2023-07-23 21:26:29 -05:00
parent c7abba1e13
commit 039be77d99
Signed by: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 19 additions and 5 deletions

View File

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

View File

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