Put a document from raw MessagePack bytes.
(
&self,
collection: &str,
doc_id: &str,
msgpack_bytes: &[u8],
)
| 32 | |
| 33 | /// Put a document from raw MessagePack bytes. |
| 34 | pub fn put_raw( |
| 35 | &self, |
| 36 | collection: &str, |
| 37 | doc_id: &str, |
| 38 | msgpack_bytes: &[u8], |
| 39 | ) -> crate::Result<()> { |
| 40 | let bitemporal = self.is_bitemporal(collection); |
| 41 | |
| 42 | if bitemporal { |
| 43 | let sys_from = wall_now_ms(); |
| 44 | self.sparse |
| 45 | .versioned_put(crate::engine::sparse::btree_versioned::VersionedPut { |
| 46 | tenant: self.tenant_id, |
| 47 | coll: collection, |
| 48 | doc_id, |
| 49 | sys_from_ms: sys_from, |
| 50 | valid_from_ms: i64::MIN, |
| 51 | valid_until_ms: i64::MAX, |
| 52 | body: msgpack_bytes, |
| 53 | })?; |
| 54 | } else { |
| 55 | self.sparse |
| 56 | .put(self.tenant_id, collection, doc_id, msgpack_bytes)?; |
| 57 | } |
| 58 | |
| 59 | if let Some(config) = self.configs.get(collection) |
| 60 | && let Ok(value) = rmpv::decode::read_value(&mut &msgpack_bytes[..]) |
| 61 | { |
| 62 | for index_path in &config.index_paths { |
| 63 | let values = |
| 64 | extract_index_values_rmpv(&value, &index_path.path, index_path.is_array); |
| 65 | for v in values { |
| 66 | if bitemporal { |
| 67 | let sys_from = wall_now_ms(); |
| 68 | self.sparse.versioned_index_put( |
| 69 | self.tenant_id, |
| 70 | collection, |
| 71 | &index_path.path, |
| 72 | &v, |
| 73 | doc_id, |
| 74 | sys_from, |
| 75 | )?; |
| 76 | } else { |
| 77 | self.sparse.index_put( |
| 78 | self.tenant_id, |
| 79 | collection, |
| 80 | &index_path.path, |
| 81 | &v, |
| 82 | doc_id, |
| 83 | )?; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | let _ = rmpv_to_json; |
| 90 | Ok(()) |
| 91 | } |