@@ -32,6 +32,35 @@ impl Cursor {
3232
3333#[ pymethods]
3434impl Cursor {
35+ #[ must_use]
36+ pub fn __aiter__ ( slf : PyRef < ' _ , Self > ) -> PyRef < ' _ , Self > {
37+ slf
38+ }
39+
40+ pub fn __anext__ ( & self , py : Python < ' _ > ) -> RustPSQLDriverPyResult < Option < PyObject > > {
41+ let db_client_arc = self . db_client . clone ( ) ;
42+ let cursor_name = self . cursor_name . clone ( ) ;
43+ let fetch_number = self . fetch_number ;
44+
45+ let future = rustengine_future ( py, async move {
46+ let db_client_guard = db_client_arc. read ( ) . await ;
47+ let result = db_client_guard
48+ . query (
49+ format ! ( "FETCH {fetch_number} FROM {cursor_name}" ) . as_str ( ) ,
50+ & [ ] ,
51+ )
52+ . await ?;
53+
54+ if result. is_empty ( ) {
55+ return Err ( PyStopAsyncIteration :: new_err ( "Error" ) . into ( ) ) ;
56+ } ;
57+
58+ Ok ( PSQLDriverPyQueryResult :: new ( result) )
59+ } ) ;
60+
61+ Ok ( Some ( future?. into ( ) ) )
62+ }
63+
3564 /// Fetch data from cursor.
3665 ///
3766 /// It's possible to specify fetch number.
@@ -190,33 +219,26 @@ impl Cursor {
190219 } )
191220 }
192221
193- #[ must_use]
194- pub fn __aiter__ ( slf : PyRef < ' _ , Self > ) -> PyRef < ' _ , Self > {
195- slf
196- }
197-
198- pub fn __anext__ ( & self , py : Python < ' _ > ) -> RustPSQLDriverPyResult < Option < PyObject > > {
222+ /// Fetch relative row from cursor.
223+ ///
224+ /// Execute FETCH RELATIVE<absolute_number>.
225+ ///
226+ /// # Errors
227+ /// May return Err Result if cannot execute query.
228+ pub fn fetch_forward_all < ' a > ( & ' a self , py : Python < ' a > ) -> RustPSQLDriverPyResult < & PyAny > {
199229 let db_client_arc = self . db_client . clone ( ) ;
200230 let cursor_name = self . cursor_name . clone ( ) ;
201- let fetch_number = self . fetch_number ;
202231
203- let future = rustengine_future ( py, async move {
232+ rustengine_future ( py, async move {
204233 let db_client_guard = db_client_arc. read ( ) . await ;
205234 let result = db_client_guard
206235 . query (
207- format ! ( "FETCH {fetch_number} FROM {cursor_name}" ) . as_str ( ) ,
236+ format ! ( "FETCH FORWARD ALL FROM {cursor_name}" ) . as_str ( ) ,
208237 & [ ] ,
209238 )
210239 . await ?;
211-
212- if result. is_empty ( ) {
213- return Err ( PyStopAsyncIteration :: new_err ( "Error" ) . into ( ) ) ;
214- } ;
215-
216240 Ok ( PSQLDriverPyQueryResult :: new ( result) )
217- } ) ;
218-
219- Ok ( Some ( future?. into ( ) ) )
241+ } )
220242 }
221243
222244 /// Close cursor.
0 commit comments