(
&self,
collection: &str,
id: &str,
)
| 13 | |
| 14 | impl NativeClient { |
| 15 | pub(super) async fn document_get_impl( |
| 16 | &self, |
| 17 | collection: &str, |
| 18 | id: &str, |
| 19 | ) -> NodeDbResult<Option<Document>> { |
| 20 | let mut conn = self.pool.acquire().await?; |
| 21 | let resp = conn |
| 22 | .send( |
| 23 | OpCode::PointGet, |
| 24 | TextFields { |
| 25 | collection: Some(collection.to_string()), |
| 26 | document_id: Some(id.to_string()), |
| 27 | ..Default::default() |
| 28 | }, |
| 29 | ) |
| 30 | .await?; |
| 31 | |
| 32 | let rows = resp.rows.unwrap_or_default(); |
| 33 | if rows.is_empty() { |
| 34 | return Ok(None); |
| 35 | } |
| 36 | |
| 37 | let json_text = rows[0].first().and_then(|v| v.as_str()).unwrap_or("{}"); |
| 38 | let obj: HashMap<String, serde_json::Value> = |
| 39 | sonic_rs::from_str(json_text).map_err(|e| { |
| 40 | NodeDbError::serialization( |
| 41 | "json", |
| 42 | format!("document_get response for id '{id}': {e}"), |
| 43 | ) |
| 44 | })?; |
| 45 | let mut doc = Document::new(id); |
| 46 | for (k, v) in obj { |
| 47 | doc.set(&k, json_to_value(v)); |
| 48 | } |
| 49 | Ok(Some(doc)) |
| 50 | } |
| 51 | |
| 52 | pub(super) async fn document_put_impl( |
| 53 | &self, |
no test coverage detected