(
&self,
collection: &str,
doc: Document,
)
| 53 | } |
| 54 | |
| 55 | pub(super) async fn document_put_impl( |
| 56 | &self, |
| 57 | collection: &str, |
| 58 | doc: Document, |
| 59 | ) -> NodeDbResult<()> { |
| 60 | let collection = quote_identifier(collection); |
| 61 | let data_json = sonic_rs::to_string(&doc.fields) |
| 62 | .map_err(|e| NodeDbError::storage(format!("document serialization: {e}")))?; |
| 63 | // NodeDB's SQL planner accepts JSON text values directly into |
| 64 | // the document `data` column — no `::jsonb` cast on the |
| 65 | // expression side, which the planner currently rejects as an |
| 66 | // "unsupported value expression". The server interprets the |
| 67 | // string literal as document JSON when the target column is the |
| 68 | // doc-engine `data` column. |
| 69 | let sql = format!( |
| 70 | "INSERT INTO {collection} (id, data) VALUES ($1, $2) \ |
| 71 | ON CONFLICT (id) DO UPDATE SET data = $2" |
| 72 | ); |
| 73 | self.execute_raw(&sql, &[&doc.id, &data_json]).await?; |
| 74 | Ok(()) |
| 75 | } |
| 76 | |
| 77 | pub(super) async fn document_delete_impl( |
| 78 | &self, |
no test coverage detected