From cf20cd439678c62262e4384ba245668975d9fe88 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 6 Apr 2022 00:11:33 +0100 Subject: [PATCH] Treat $this param as a special case --- lib/src/sql/param.rs | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/src/sql/param.rs b/lib/src/sql/param.rs index 1babdada..b5f4f1ed 100644 --- a/lib/src/sql/param.rs +++ b/lib/src/sql/param.rs @@ -37,18 +37,33 @@ impl Param { // Find a base variable by name match self.name.parts.first() { // The first part will be a field - Some(Part::Field(v)) => match ctx.value::(&v.name) { - // The base variable exists - Some(v) => { - // Get the path parts - let pth: &[Part] = &self.name; - // Process the paramater value - let res = v.compute(ctx, opt, txn, doc).await?; - // Return the desired field - res.get(ctx, opt, txn, pth.next()).await - } - // The base variable does not exist - None => Ok(Value::None), + Some(Part::Field(v)) => match &v.name[..] { + "this" => match doc { + // The base document exists + Some(v) => { + // Get the path parts + let pth: &[Part] = &self.name; + // Process the paramater value + let res = v.compute(ctx, opt, txn, doc).await?; + // Return the desired field + res.get(ctx, opt, txn, pth.next()).await + } + // The base document does not exist + None => Ok(Value::None), + }, + _ => match ctx.value::(&v.name) { + // The base variable exists + Some(v) => { + // Get the path parts + let pth: &[Part] = &self.name; + // Process the paramater value + let res = v.compute(ctx, opt, txn, doc).await?; + // Return the desired field + res.get(ctx, opt, txn, pth.next()).await + } + // The base variable does not exist + None => Ok(Value::None), + }, }, _ => unreachable!(), }