MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / field_value_exists

Method field_value_exists

nodedb-crdt/src/state/core.rs:168–185  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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`).

Callers 1

check_uniqueMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected