retrieves the current version of a collection
(lmdb: &MetaDb)
| 152 | |
| 153 | /// retrieves the current version of a collection |
| 154 | pub fn retrieve_background_version(lmdb: &MetaDb) -> Result<VersionNumber, WaCustomError> { |
| 155 | let env = lmdb.env.clone(); |
| 156 | let db = lmdb.db; |
| 157 | let txn = env |
| 158 | .begin_ro_txn() |
| 159 | .map_err(|e| WaCustomError::DatabaseError(format!("Failed to begin transaction: {}", e)))?; |
| 160 | let current_version_key = key!(m:background_version); |
| 161 | |
| 162 | let serialized_hash = txn.get(db, ¤t_version_key).map_err(|e| match e { |
| 163 | lmdb::Error::NotFound => { |
| 164 | WaCustomError::DatabaseError("Record not found: current_version".to_string()) |
| 165 | } |
| 166 | _ => WaCustomError::DatabaseError(e.to_string()), |
| 167 | })?; |
| 168 | |
| 169 | let bytes: [u8; 4] = serialized_hash.try_into().map_err(|_| { |
| 170 | WaCustomError::DeserializationError( |
| 171 | "Failed to deserialize Hash: length mismatch".to_string(), |
| 172 | ) |
| 173 | })?; |
| 174 | let hash = VersionNumber::from(u32::from_le_bytes(bytes)); |
| 175 | |
| 176 | Ok(hash) |
| 177 | } |
| 178 | |
| 179 | pub fn retrieve_values_range(lmdb: &MetaDb) -> Result<Option<(f32, f32)>, WaCustomError> { |
| 180 | let env = lmdb.env.clone(); |