@@ -1227,33 +1227,14 @@ impl<'conn> Transaction<'conn> {
12271227 } )
12281228 }
12291229
1230- /// Executes a prepared statement, returning a lazily loaded iterator over
1231- /// the resulting rows.
1232- ///
1233- /// No more than `row_limit` rows will be stored in memory at a time. Rows
1234- /// will be pulled from the database in batches of `row_limit` as needed.
1235- /// If `row_limit` is less than or equal to 0, `lazy_query` is equivalent
1236- /// to `query`.
1230+ #[ deprecated = "call `lazy_query` on Statement instead" ]
1231+ #[ allow( missing_docs) ]
12371232 pub fn lazy_query < ' trans , ' stmt > ( & ' trans self ,
12381233 stmt : & ' stmt Statement ,
12391234 params : & [ & ToSql ] ,
12401235 row_limit : i32 )
12411236 -> Result < LazyRows < ' trans , ' stmt > > {
1242- if self . conn as * const _ != stmt. conn as * const _ {
1243- return Err ( Error :: WrongConnection ) ;
1244- }
1245- let conn = self . conn . conn . borrow ( ) ;
1246- check_desync ! ( conn) ;
1247- if conn. trans_depth != self . depth {
1248- return Err ( Error :: WrongTransaction ) ;
1249- }
1250- drop ( conn) ;
1251- stmt. lazy_query ( row_limit, params) . map ( |result| {
1252- LazyRows {
1253- _trans : self ,
1254- result : result
1255- }
1256- } )
1237+ stmt. lazy_query ( self , params, row_limit)
12571238 }
12581239
12591240 /// Determines if the transaction is currently set to commit or roll back.
@@ -1368,7 +1349,7 @@ impl<'conn> Statement<'conn> {
13681349 }
13691350 }
13701351
1371- fn lazy_query < ' a > ( & ' a self , row_limit : i32 , params : & [ & ToSql ] ) -> Result < Rows < ' a > > {
1352+ fn inner_lazy_query < ' a > ( & ' a self , row_limit : i32 , params : & [ & ToSql ] ) -> Result < Rows < ' a > > {
13721353 let id = self . next_portal_id . get ( ) ;
13731354 self . next_portal_id . set ( id + 1 ) ;
13741355 let portal_name = format ! ( "{}p{}" , self . name, id) ;
@@ -1475,7 +1456,40 @@ impl<'conn> Statement<'conn> {
14751456 /// ```
14761457 pub fn query < ' a > ( & ' a self , params : & [ & ToSql ] ) -> Result < Rows < ' a > > {
14771458 check_desync ! ( self . conn) ;
1478- self . lazy_query ( 0 , params)
1459+ self . inner_lazy_query ( 0 , params)
1460+ }
1461+
1462+ /// Executes the prepared statement, returning a lazily loaded iterator
1463+ /// over the resulting rows.
1464+ ///
1465+ /// No more than `row_limit` rows will be stored in memory at a time. Rows
1466+ /// will be pulled from the database in batches of `row_limit` as needed.
1467+ /// If `row_limit` is less than or equal to 0, `lazy_query` is equivalent
1468+ /// to `query`.
1469+ ///
1470+ /// This can only be called inside of a transaction, and the `Transaction`
1471+ /// object representing the active transaction must be passed to
1472+ /// `lazy_query`.
1473+ pub fn lazy_query < ' trans , ' stmt > ( & ' stmt self ,
1474+ trans : & ' trans Transaction ,
1475+ params : & [ & ToSql ] ,
1476+ row_limit : i32 )
1477+ -> Result < LazyRows < ' trans , ' stmt > > {
1478+ if self . conn as * const _ != trans. conn as * const _ {
1479+ return Err ( Error :: WrongConnection ) ;
1480+ }
1481+ let conn = self . conn . conn . borrow ( ) ;
1482+ check_desync ! ( conn) ;
1483+ if conn. trans_depth != trans. depth {
1484+ return Err ( Error :: WrongTransaction ) ;
1485+ }
1486+ drop ( conn) ;
1487+ self . inner_lazy_query ( row_limit, params) . map ( |result| {
1488+ LazyRows {
1489+ _trans : trans,
1490+ result : result
1491+ }
1492+ } )
14791493 }
14801494
14811495 /// Consumes the statement, clearing it from the Postgres session.
0 commit comments