MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / handle_fetch

Method handle_fetch

nodedb/src/control/server/pgwire/handler/cursor_cmds.rs:15–55  ·  view source on GitHub ↗

Handle FETCH [ALL | FORWARD n | BACKWARD n | n] FROM cursor_name.

(
        &self,
        addr: &std::net::SocketAddr,
        sql: &str,
        upper: &str,
    )

Source from the content-addressed store, hash-verified

13impl 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(

Callers 1

execute_single_sqlMethod · 0.80

Calls 10

parse_fetchFunction · 0.85
cursor_errorFunction · 0.85
collectMethod · 0.80
fetch_cursorMethod · 0.80
to_stringMethod · 0.80
fetch_cursor_allMethod · 0.80
fetch_cursor_backwardMethod · 0.80
lenMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected