Look up documents by GSI value. Returns entries pointing to primary locations.
(&self, index_name: &str, value: &str)
| 235 | |
| 236 | /// Look up documents by GSI value. Returns entries pointing to primary locations. |
| 237 | pub fn lookup(&self, index_name: &str, value: &str) -> crate::Result<Vec<GsiEntry>> { |
| 238 | let key = format!("{index_name}:{value}"); |
| 239 | let read_txn = self.db.begin_read().map_err(|e| crate::Error::Storage { |
| 240 | engine: "gsi".into(), |
| 241 | detail: format!("read: {e}"), |
| 242 | })?; |
| 243 | let table = read_txn |
| 244 | .open_table(GSI_TABLE) |
| 245 | .map_err(|e| crate::Error::Storage { |
| 246 | engine: "gsi".into(), |
| 247 | detail: format!("open entries: {e}"), |
| 248 | })?; |
| 249 | |
| 250 | match table.get(key.as_str()) { |
| 251 | Ok(Some(guard)) => { |
| 252 | let entries: Vec<GsiEntry> = match zerompk::from_msgpack(guard.value()) { |
| 253 | Ok(v) => v, |
| 254 | Err(e) => { |
| 255 | tracing::warn!(index = %key, error = %e, "GSI lookup deserialization failed"); |
| 256 | Vec::new() |
| 257 | } |
| 258 | }; |
| 259 | Ok(entries) |
| 260 | } |
| 261 | Ok(None) => Ok(Vec::new()), |
| 262 | Err(e) => Err(crate::Error::Storage { |
| 263 | engine: "gsi".into(), |
| 264 | detail: format!("get: {e}"), |
| 265 | }), |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | /// List all GSIs declared for a collection. |
| 270 | pub fn list_indexes(&self, tenant_id: u64, collection: &str) -> crate::Result<Vec<GsiMeta>> { |