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