Handle FETCH [ALL | FORWARD n | BACKWARD n | n] FROM cursor_name.
(
&self,
addr: &std::net::SocketAddr,
sql: &str,
upper: &str,
)
| 13 | impl NodeDbPgHandler { |
| 14 | /// Handle FETCH [ALL | FORWARD n | BACKWARD n | n] FROM cursor_name. |
| 15 | pub(super) fn handle_fetch( |
| 16 | &self, |
| 17 | addr: &std::net::SocketAddr, |
| 18 | sql: &str, |
| 19 | upper: &str, |
| 20 | ) -> PgWireResult<Vec<Response>> { |
| 21 | let parts: Vec<&str> = sql.split_whitespace().collect(); |
| 22 | |
| 23 | // Parse fetch direction and count. |
| 24 | let (direction, count, cursor_name) = parse_fetch(upper, &parts)?; |
| 25 | |
| 26 | let rows = match direction { |
| 27 | FetchDirection::Forward => { |
| 28 | let (rows, _) = self |
| 29 | .sessions |
| 30 | .fetch_cursor(addr, &cursor_name, count) |
| 31 | .map_err(|e| cursor_error(&e.to_string()))?; |
| 32 | rows |
| 33 | } |
| 34 | FetchDirection::All => self |
| 35 | .sessions |
| 36 | .fetch_cursor_all(addr, &cursor_name) |
| 37 | .map_err(|e| cursor_error(&e.to_string()))?, |
| 38 | FetchDirection::Backward => self |
| 39 | .sessions |
| 40 | .fetch_cursor_backward(addr, &cursor_name, count) |
| 41 | .map_err(|e| cursor_error(&e.to_string()))?, |
| 42 | }; |
| 43 | |
| 44 | let schema = Arc::new(vec![text_field("result")]); |
| 45 | let mut encoded_rows = Vec::with_capacity(rows.len()); |
| 46 | for row_json in &rows { |
| 47 | let mut encoder = DataRowEncoder::new(schema.clone()); |
| 48 | let _ = encoder.encode_field(row_json); |
| 49 | encoded_rows.push(Ok(encoder.take_row())); |
| 50 | } |
| 51 | Ok(vec![Response::Query(QueryResponse::new( |
| 52 | schema, |
| 53 | futures::stream::iter(encoded_rows), |
| 54 | ))]) |
| 55 | } |
| 56 | |
| 57 | /// Handle MOVE [FORWARD | BACKWARD] n IN cursor_name. |
| 58 | pub(super) fn handle_move( |
no test coverage detected