diff --git a/src/api/client/query.rs b/src/api/client/query.rs index 302db633..28feb316 100644 --- a/src/api/client/query.rs +++ b/src/api/client/query.rs @@ -7,6 +7,7 @@ use postgres_types::Oid; use crate::api::results::{FieldInfo, Tag}; use crate::error::{ErrorInfo, PgWireClientError, PgWireClientResult}; use crate::messages::data::{DataRow, RowDescription}; +use crate::messages::extendedquery::{Bind, Close, Execute, Flush, Parse, Sync}; use crate::messages::response::{CommandComplete, EmptyQueryResponse, ReadyForQuery}; use crate::messages::simplequery::Query; use crate::messages::{PgWireBackendMessage, PgWireFrontendMessage}; @@ -102,6 +103,47 @@ pub trait SimpleQueryHandler: Send { PgWireClientError: From<>::Error>; } +#[async_trait] +pub trait ExtendedQueryHandler: Send { + type QueryResponse; + + // TODO: do we need to cover message building here, to pass raw message or + // pass statement name and id? + async fn parse(&mut self, client: &mut C, query: Parse) -> PgWireClientResult<()> + where + C: ClientInfo + Sink + Unpin + Send, + PgWireClientError: From<>::Error>; + + async fn bind(&mut self, client: &mut C, bind: Bind) -> PgWireClientResult<()> + where + C: ClientInfo + Sink + Unpin + Send, + PgWireClientError: From<>::Error>; + + async fn execute( + &mut self, + client: &mut C, + execute: Execute, + ) -> PgWireClientResult + where + C: ClientInfo + Sink + Unpin + Send, + PgWireClientError: From<>::Error>; + + async fn close(&mut self, client: &mut C, close: Close) -> PgWireClientResult<()> + where + C: ClientInfo + Sink + Unpin + Send, + PgWireClientError: From<>::Error>; + + async fn sync(&mut self, client: &mut C, sync: Sync) -> PgWireClientResult<()> + where + C: ClientInfo + Sink + Unpin + Send, + PgWireClientError: From<>::Error>; + + async fn flush(&mut self, client: &mut C, flush: Flush) -> PgWireClientResult<()> + where + C: ClientInfo + Sink + Unpin + Send, + PgWireClientError: From<>::Error>; +} + #[derive(Debug)] pub enum Response { EmptyQuery, diff --git a/src/tokio/client.rs b/src/tokio/client.rs index 6bd35bdb..976679fb 100644 --- a/src/tokio/client.rs +++ b/src/tokio/client.rs @@ -162,6 +162,26 @@ impl PgWireClient { Err(PgWireClientError::UnexpectedEOF) } + + /// Parse a query to server side + pub async fn parse( + &mut self, + mut extended_query_handler: H, + name: Option<&str>, + query: &str, + ) -> PgWireClientResult<()> { + todo!() + } + + /// Execute the query + pub async fn execute( + &mut self, + mut extended_query_handler: H, + name: Option<&str>, + parameters: Vec, //TODO + ) -> PgWireClientResult<()> { + todo!() + } } #[pin_project(project = ClientSocketProj)]