Fetch N rows forward from a cursor. Returns (rows, exhausted).
(
&self,
addr: &SocketAddr,
name: &str,
count: usize,
)
| 32 | |
| 33 | /// Fetch N rows forward from a cursor. Returns (rows, exhausted). |
| 34 | pub fn fetch_cursor( |
| 35 | &self, |
| 36 | addr: &SocketAddr, |
| 37 | name: &str, |
| 38 | count: usize, |
| 39 | ) -> crate::Result<(Vec<String>, bool)> { |
| 40 | self.write_session(addr, |session| { |
| 41 | let cursor = session |
| 42 | .cursors |
| 43 | .get_mut(name) |
| 44 | .ok_or_else(|| crate::Error::BadRequest { |
| 45 | detail: format!("cursor \"{name}\" does not exist"), |
| 46 | })?; |
| 47 | |
| 48 | let start = cursor.position; |
| 49 | let end = (start + count).min(cursor.rows.len()); |
| 50 | let rows: Vec<String> = cursor.rows[start..end].to_vec(); |
| 51 | cursor.position = end; |
| 52 | let exhausted = end >= cursor.rows.len(); |
| 53 | Ok((rows, exhausted)) |
| 54 | }) |
| 55 | .unwrap_or_else(|| { |
| 56 | Err(crate::Error::BadRequest { |
| 57 | detail: "no active session".to_string(), |
| 58 | }) |
| 59 | }) |
| 60 | } |
| 61 | |
| 62 | /// Fetch all remaining rows from a cursor. |
| 63 | pub fn fetch_cursor_all(&self, addr: &SocketAddr, name: &str) -> crate::Result<Vec<String>> { |
no test coverage detected