diff --git a/lib/src/doc/field.rs b/lib/src/doc/field.rs index ddd462eb..62ebf382 100644 --- a/lib/src/doc/field.rs +++ b/lib/src/doc/field.rs @@ -20,11 +20,11 @@ impl<'a> Document<'a> { // Loop through all field statements for fd in self.fd(opt, txn).await?.iter() { // Loop over each field in document - for k in self.current.each(&fd.name).into_iter() { + for k in self.current.each(&fd.name).iter() { // Get the initial value - let old = self.initial.pick(&k); + let old = self.initial.pick(k); // Get the current value - let mut val = self.current.pick(&k); + let mut val = self.current.pick(k); // Check for a VALUE clause if let Some(expr) = &fd.value { // Configure the context @@ -113,9 +113,9 @@ impl<'a> Document<'a> { } // Set the value of the field match val { - Value::None => self.current.to_mut().del(ctx, opt, txn, &k).await?, - Value::Void => self.current.to_mut().del(ctx, opt, txn, &k).await?, - _ => self.current.to_mut().set(ctx, opt, txn, &k, val).await?, + Value::None => self.current.to_mut().del(ctx, opt, txn, k).await?, + Value::Void => self.current.to_mut().del(ctx, opt, txn, k).await?, + _ => self.current.to_mut().set(ctx, opt, txn, k, val).await?, }; } } diff --git a/lib/src/doc/pluck.rs b/lib/src/doc/pluck.rs index da5c0b98..17a590dd 100644 --- a/lib/src/doc/pluck.rs +++ b/lib/src/doc/pluck.rs @@ -115,21 +115,21 @@ impl<'a> Document<'a> { // Loop through all field statements for fd in self.fd(opt, txn).await?.iter() { // Loop over each field in document - for k in out.each(&fd.name).into_iter() { + for k in out.each(&fd.name).iter() { // Process field permissions match &fd.permissions.select { Permission::Full => (), - Permission::None => out.del(ctx, opt, txn, &k).await?, + Permission::None => out.del(ctx, opt, txn, k).await?, Permission::Specific(e) => { // Get the current value - let val = self.current.pick(&k); + let val = self.current.pick(k); // Configure the context let mut ctx = Context::new(ctx); ctx.add_value("value".into(), val); let ctx = ctx.freeze(); // Process the PERMISSION clause if !e.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() { - out.del(&ctx, opt, txn, &k).await? + out.del(&ctx, opt, txn, k).await? } } } diff --git a/lib/src/sql/idiom.rs b/lib/src/sql/idiom.rs index 96ff1781..a73766bb 100644 --- a/lib/src/sql/idiom.rs +++ b/lib/src/sql/idiom.rs @@ -57,10 +57,9 @@ impl From> for Idiom { } impl Idiom { - pub fn add(&self, n: Part) -> Idiom { - let mut p = self.parts.to_vec(); - p.push(n); - Idiom::from(p) + pub fn add(mut self, n: Part) -> Idiom { + self.parts.push(n); + self } pub fn to_path(&self) -> String { diff --git a/lib/src/sql/value/diff.rs b/lib/src/sql/value/diff.rs index 190021ad..32ab73ad 100644 --- a/lib/src/sql/value/diff.rs +++ b/lib/src/sql/value/diff.rs @@ -13,7 +13,7 @@ impl Value { if !b.value.contains_key(key) { ops.push(Operation { op: Op::Remove, - path: path.add(key.clone().into()), + path: path.clone().add(key.clone().into()), value: Value::Null, }) } @@ -23,11 +23,11 @@ impl Value { match a.value.get(key) { None => ops.push(Operation { op: Op::Add, - path: path.add(key.clone().into()), + path: path.clone().add(key.clone().into()), value: val.clone(), }), Some(old) => { - let path = path.add(key.clone().into()); + let path = path.clone().add(key.clone().into()); ops.append(&mut old.diff(val, path)) } } @@ -36,7 +36,7 @@ impl Value { (Value::Array(a), Value::Array(b)) if a != b => { let mut n = 0; while n < min(a.len(), b.len()) { - let path = path.add(n.into()); + let path = path.clone().add(n.into()); ops.append(&mut a.value[n].diff(&b.value[n], path)); n += 1; } @@ -44,7 +44,7 @@ impl Value { if n >= a.len() { ops.push(Operation { op: Op::Add, - path: path.add(n.into()), + path: path.clone().add(n.into()), value: b.value[n].clone(), }) } @@ -54,7 +54,7 @@ impl Value { if n >= b.len() { ops.push(Operation { op: Op::Remove, - path: path.add(n.into()), + path: path.clone().add(n.into()), value: Value::Null, }) } diff --git a/lib/src/sql/value/each.rs b/lib/src/sql/value/each.rs index 93e55e96..9834e4f4 100644 --- a/lib/src/sql/value/each.rs +++ b/lib/src/sql/value/each.rs @@ -26,7 +26,7 @@ impl Value { .value .iter() .enumerate() - .flat_map(|(i, v)| v._each(path.next(), prev.add(Part::from(i)))) + .flat_map(|(i, v)| v._each(path.next(), prev.clone().add(Part::from(i)))) .collect::>(), Part::First => match v.value.first() { Some(v) => v._each(path.next(), prev.add(p.clone())), @@ -44,7 +44,7 @@ impl Value { .value .iter() .enumerate() - .flat_map(|(i, v)| v._each(path.next(), prev.add(Part::from(i)))) + .flat_map(|(i, v)| v._each(path.next(), prev.clone().add(Part::from(i)))) .collect::>(), }, // Ignore everything else diff --git a/lib/src/sql/value/every.rs b/lib/src/sql/value/every.rs index e86c9cd8..7f77f6de 100644 --- a/lib/src/sql/value/every.rs +++ b/lib/src/sql/value/every.rs @@ -12,14 +12,14 @@ impl Value { Value::Object(v) => v .value .iter() - .flat_map(|(k, v)| v._every(prev.add(Part::from(k)))) + .flat_map(|(k, v)| v._every(prev.clone().add(Part::from(k)))) .collect::>(), // Current path part is an array Value::Array(v) => v .value .iter() .enumerate() - .flat_map(|(i, v)| v._every(prev.add(Part::from(i)))) + .flat_map(|(i, v)| v._every(prev.clone().add(Part::from(i)))) .collect::>(), // Process everything else _ => vec![prev],