(
&self,
collection: &str,
from: &NodeId,
to: &NodeId,
edge_type: &str,
properties: Option<Document>,
)
| 92 | } |
| 93 | |
| 94 | pub(super) async fn graph_insert_edge_impl( |
| 95 | &self, |
| 96 | collection: &str, |
| 97 | from: &NodeId, |
| 98 | to: &NodeId, |
| 99 | edge_type: &str, |
| 100 | properties: Option<Document>, |
| 101 | ) -> NodeDbResult<EdgeId> { |
| 102 | // `GRAPH INSERT EDGE IN '<collection>' FROM '<src>' TO '<dst>' |
| 103 | // TYPE '<label>' [PROPERTIES '<json>']`. The DSL handler lives |
| 104 | // in `pgwire/ddl/graph_ops/edge.rs` and registers the edge in |
| 105 | // the collection's graph overlay. simple_query is required |
| 106 | // because the DSL doesn't fit the extended-query row-description |
| 107 | // shape (it returns CommandComplete only). |
| 108 | let props_clause = match properties { |
| 109 | Some(d) => { |
| 110 | let json = sonic_rs::to_string(&d) |
| 111 | .map_err(|e| NodeDbError::storage(format!("properties serialization: {e}")))?; |
| 112 | format!(" PROPERTIES {}", quote_string_literal(&json)) |
| 113 | } |
| 114 | None => String::new(), |
| 115 | }; |
| 116 | let coll = quote_string_literal(collection); |
| 117 | let from_s = quote_string_literal(from.as_str()); |
| 118 | let to_s = quote_string_literal(to.as_str()); |
| 119 | let label_s = quote_string_literal(edge_type); |
| 120 | let sql = format!( |
| 121 | "GRAPH INSERT EDGE IN {coll} FROM {from_s} TO {to_s} TYPE {label_s}{props_clause}" |
| 122 | ); |
| 123 | |
| 124 | self.simple_query_raw(&sql).await?; |
| 125 | |
| 126 | EdgeId::try_first(from.clone(), to.clone(), edge_type) |
| 127 | .map_err(|e| NodeDbError::storage(format!("invalid edge label: {e}"))) |
| 128 | } |
| 129 | |
| 130 | pub(super) async fn graph_delete_edge_impl( |
| 131 | &self, |
no test coverage detected