Check if a value exists for the given field across all rows in a collection. Used for UNIQUE constraint checking.
(&self, collection: &str, field: &str, value: &LoroValue)
| 166 | /// Check if a value exists for the given field across all rows in a collection. |
| 167 | /// Used for UNIQUE constraint checking. |
| 168 | pub fn field_value_exists(&self, collection: &str, field: &str, value: &LoroValue) -> bool { |
| 169 | let coll = self.doc.get_map(collection); |
| 170 | for key in coll.keys() { |
| 171 | let path = format!("{collection}/{key}/{field}"); |
| 172 | if let Some(voc) = self.doc.get_by_str_path(&path) { |
| 173 | let field_val = match voc { |
| 174 | ValueOrContainer::Value(v) => v, |
| 175 | ValueOrContainer::Container(_) => { |
| 176 | continue; |
| 177 | } |
| 178 | }; |
| 179 | if &field_val == value { |
| 180 | return true; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | false |
| 185 | } |
| 186 | |
| 187 | /// Bitemporal variant of [`field_value_exists`]: only considers rows |
| 188 | /// whose `_ts_valid_until` is open (absent or `i64::MAX`). |