@@ -8,9 +8,9 @@ use postgres_types::FromSqlOwned;
88use tokio:: sync:: Mutex ;
99
1010use crate :: api:: Type ;
11- use crate :: api:: results:: { FieldInfo , QueryResponse } ;
11+ use crate :: api:: results:: QueryResponse ;
1212use crate :: error:: { PgWireError , PgWireResult } ;
13- use crate :: messages:: data:: { DataRow , FORMAT_CODE_BINARY } ;
13+ use crate :: messages:: data:: FORMAT_CODE_BINARY ;
1414use crate :: messages:: extendedquery:: Bind ;
1515use crate :: types:: FromSqlText ;
1616use crate :: types:: format:: FormatOptions ;
@@ -45,9 +45,7 @@ pub enum PortalExecutionState {
4545/// Result of fetching rows from a portal in `Suspended` state.
4646#[ derive( Debug ) ]
4747pub struct FetchResult {
48- pub command_tag : String ,
49- pub rows : Vec < DataRow > ,
50- pub row_schema : Arc < Vec < FieldInfo > > ,
48+ pub response : QueryResponse ,
5149 pub suspended : bool ,
5250}
5351
@@ -211,9 +209,7 @@ impl<S: Clone> Portal<S> {
211209 match state. deref_mut ( ) {
212210 PortalExecutionState :: Initial => Err ( PgWireError :: PortalNotStarted ) ,
213211 PortalExecutionState :: Finished => Ok ( FetchResult {
214- command_tag : String :: new ( ) ,
215- rows : vec ! [ ] ,
216- row_schema : Arc :: new ( vec ! [ ] ) ,
212+ response : QueryResponse :: new ( Arc :: new ( vec ! [ ] ) , futures:: stream:: empty ( ) ) ,
217213 suspended : false ,
218214 } ) ,
219215 PortalExecutionState :: Suspended ( response) => {
@@ -232,22 +228,20 @@ impl<S: Clone> Portal<S> {
232228 }
233229 }
234230
235- if suspended {
236- Ok ( FetchResult {
237- command_tag,
238- rows,
239- row_schema,
240- suspended : true ,
241- } )
242- } else {
231+ if !suspended {
243232 * state = PortalExecutionState :: Finished ;
244- Ok ( FetchResult {
245- command_tag,
246- rows,
247- row_schema,
248- suspended : false ,
249- } )
250233 }
234+
235+ let result_response = QueryResponse {
236+ command_tag,
237+ row_schema,
238+ data_rows : Box :: pin ( futures:: stream:: iter ( rows. into_iter ( ) . map ( Ok ) ) ) ,
239+ } ;
240+
241+ Ok ( FetchResult {
242+ response : result_response,
243+ suspended,
244+ } )
251245 }
252246 }
253247 }
0 commit comments