@@ -7,12 +7,14 @@ use crate::models::helpers::with_count::*;
77use  crate :: util:: errors:: { bad_request,  AppResult } ; 
88use  crate :: util:: { HeaderMapExt ,  RequestUtils } ; 
99
10- use  crate :: util:: diesel:: prelude:: * ; 
1110use  base64:: { engine:: general_purpose,  Engine } ; 
1211use  diesel:: pg:: Pg ; 
12+ use  diesel:: prelude:: * ; 
1313use  diesel:: query_builder:: { AstPass ,  Query ,  QueryFragment ,  QueryId } ; 
14- use  diesel:: query_dsl:: LoadQuery ; 
1514use  diesel:: sql_types:: BigInt ; 
15+ use  diesel_async:: AsyncPgConnection ; 
16+ use  futures_util:: future:: BoxFuture ; 
17+ use  futures_util:: { FutureExt ,  TryStreamExt } ; 
1618use  http:: header; 
1719use  indexmap:: IndexMap ; 
1820use  serde:: { Deserialize ,  Serialize } ; 
@@ -250,16 +252,29 @@ pub(crate) struct PaginatedQuery<T> {
250252} 
251253
252254impl < T >  PaginatedQuery < T >  { 
253-     pub ( crate )  fn  load < ' a ,  U ,  Conn > ( self ,  conn :  & mut  Conn )  -> QueryResult < Paginated < U > > 
255+     pub  fn  load < ' a ,  U > ( 
256+         self , 
257+         conn :  & ' a  mut  AsyncPgConnection , 
258+     )  -> BoxFuture < ' a ,  QueryResult < Paginated < U > > > 
254259    where 
255-         Self :  LoadQuery < ' a ,  Conn ,  WithCount < U > > , 
260+         Self :  diesel_async:: methods:: LoadQuery < ' a ,  AsyncPgConnection ,  WithCount < U > > , 
261+         T :  ' a , 
262+         U :  Send  + ' a , 
256263    { 
264+         use  diesel_async:: methods:: LoadQuery ; 
265+ 
257266        let  options = self . options . clone ( ) ; 
258-         let  records_and_total = self . internal_load ( conn) ?. collect :: < QueryResult < _ > > ( ) ?; 
259-         Ok ( Paginated  { 
260-             records_and_total, 
261-             options, 
262-         } ) 
267+         let  future = self . internal_load ( conn) ; 
268+ 
269+         async  move  { 
270+             let  records_and_total = future. await ?. try_collect ( ) . await ?; 
271+ 
272+             Ok ( Paginated  { 
273+                 records_and_total, 
274+                 options, 
275+             } ) 
276+         } 
277+         . boxed ( ) 
263278    } 
264279} 
265280
@@ -272,8 +287,6 @@ impl<T: Query> Query for PaginatedQuery<T> {
272287    type  SqlType  = ( T :: SqlType ,  BigInt ) ; 
273288} 
274289
275- impl < T ,  DB >  diesel:: RunQueryDsl < DB >  for  PaginatedQuery < T >  { } 
276- 
277290impl < T >  QueryFragment < Pg >  for  PaginatedQuery < T > 
278291where 
279292    T :  QueryFragment < Pg > , 
@@ -366,8 +379,6 @@ impl<
366379    type  SqlType  = ( T :: SqlType ,  BigInt ) ; 
367380} 
368381
369- impl < T ,  C ,  DB >  diesel:: RunQueryDsl < DB >  for  PaginatedQueryWithCountSubq < T ,  C >  { } 
370- 
371382impl < T ,  C >  QueryFragment < Pg >  for  PaginatedQueryWithCountSubq < T ,  C > 
372383where 
373384    T :  QueryFragment < Pg > , 
@@ -390,16 +401,30 @@ where
390401} 
391402
392403impl < T ,  C >  PaginatedQueryWithCountSubq < T ,  C >  { 
393-     pub ( crate )  fn  load < ' a ,  U ,  Conn > ( self ,  conn :  & mut  Conn )  -> QueryResult < Paginated < U > > 
404+     pub  fn  load < ' a ,  U > ( 
405+         self , 
406+         conn :  & ' a  mut  AsyncPgConnection , 
407+     )  -> BoxFuture < ' a ,  QueryResult < Paginated < U > > > 
394408    where 
395-         Self :  LoadQuery < ' a ,  Conn ,  WithCount < U > > , 
409+         Self :  diesel_async:: methods:: LoadQuery < ' a ,  AsyncPgConnection ,  WithCount < U > >  + Send , 
410+         C :  ' a , 
411+         T :  ' a , 
412+         U :  Send  + ' a , 
396413    { 
414+         use  diesel_async:: methods:: LoadQuery ; 
415+ 
397416        let  options = self . options . clone ( ) ; 
398-         let  records_and_total = self . internal_load ( conn) ?. collect :: < QueryResult < _ > > ( ) ?; 
399-         Ok ( Paginated  { 
400-             records_and_total, 
401-             options, 
402-         } ) 
417+         let  future = self . internal_load ( conn) ; 
418+ 
419+         async  move  { 
420+             let  records_and_total = future. await ?. try_collect ( ) . await ?; 
421+ 
422+             Ok ( Paginated  { 
423+                 records_and_total, 
424+                 options, 
425+             } ) 
426+         } 
427+         . boxed ( ) 
403428    } 
404429} 
405430
0 commit comments