Skip to content

Commit

Permalink
add flush to ExtendedQueryHandler (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbicr authored Nov 29, 2024
1 parent a033265 commit 02156cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/api/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::api::PgWireConnectionState;
use crate::error::{PgWireError, PgWireResult};
use crate::messages::data::{NoData, ParameterDescription};
use crate::messages::extendedquery::{
Bind, BindComplete, Close, CloseComplete, Describe, Execute, Parse, ParseComplete,
Bind, BindComplete, Close, CloseComplete, Describe, Execute, Flush, Parse, ParseComplete,
Sync as PgSync, TARGET_TYPE_BYTE_PORTAL, TARGET_TYPE_BYTE_STATEMENT,
};
use crate::messages::response::{EmptyQueryResponse, ReadyForQuery, TransactionStatus};
Expand Down Expand Up @@ -300,6 +300,19 @@ pub trait ExtendedQueryHandler: Send + Sync {
Ok(())
}

/// Called when client sends `flush` command.
///
/// The default implementation flushes client buffer
async fn on_flush<C>(&self, client: &mut C, _message: Flush) -> PgWireResult<()>
where
C: ClientInfo + Sink<PgWireBackendMessage> + Unpin + Send + Sync,
C::Error: Debug,
PgWireError: From<<C as Sink<PgWireBackendMessage>>::Error>,
{
client.flush().await?;
Ok(())
}

/// Called when client sends `sync` command.
///
/// The default implementation flushes client buffer and sends
Expand Down
3 changes: 3 additions & 0 deletions src/tokio/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ where
PgWireFrontendMessage::Describe(describe) => {
extended_query_handler.on_describe(socket, describe).await?;
}
PgWireFrontendMessage::Flush(flush) => {
extended_query_handler.on_flush(socket, flush).await?;
}
PgWireFrontendMessage::Sync(sync) => {
extended_query_handler.on_sync(socket, sync).await?;
}
Expand Down

0 comments on commit 02156cc

Please sign in to comment.