From 9f7527c01a61d7f172b82172fab978b45f003b3f Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 25 Mar 2022 21:14:48 +0000 Subject: [PATCH] Make simple value fetching functions synchronous --- lib/src/dbs/iterator.rs | 13 ++++--------- lib/src/sql/subquery.rs | 4 ++-- lib/src/sql/value/all.rs | 13 ++----------- lib/src/sql/value/first.rs | 13 ++----------- lib/src/sql/value/get.rs | 3 +-- lib/src/sql/value/last.rs | 13 ++----------- 6 files changed, 13 insertions(+), 46 deletions(-) diff --git a/lib/src/dbs/iterator.rs b/lib/src/dbs/iterator.rs index b8334832..bc842613 100644 --- a/lib/src/dbs/iterator.rs +++ b/lib/src/dbs/iterator.rs @@ -238,15 +238,14 @@ impl Iterator { match v { Value::Function(f) if f.is_aggregate() => { let x = vals - .all(ctx, opt, txn) - .await? + .all() .get(ctx, opt, txn, v.to_idiom().as_ref()) .await?; let x = f.aggregate(x).compute(ctx, opt, txn, None).await?; obj.set(ctx, opt, txn, v.to_idiom().as_ref(), x).await?; } _ => { - let x = vals.first(ctx, opt, txn).await?; + let x = vals.first(); let x = v.compute(ctx, opt, txn, Some(&x)).await?; obj.set(ctx, opt, txn, v.to_idiom().as_ref(), x).await?; } @@ -256,16 +255,12 @@ impl Iterator { if let Field::Alias(v, i) = field { match v { Value::Function(f) if f.is_aggregate() => { - let x = vals - .all(ctx, opt, txn) - .await? - .get(ctx, opt, txn, i) - .await?; + let x = vals.all().get(ctx, opt, txn, i).await?; let x = f.aggregate(x).compute(ctx, opt, txn, None).await?; obj.set(ctx, opt, txn, i, x).await?; } _ => { - let x = vals.first(ctx, opt, txn).await?; + let x = vals.first(); let x = v.compute(ctx, opt, txn, Some(&x)).await?; obj.set(ctx, opt, txn, i, x).await?; } diff --git a/lib/src/sql/subquery.rs b/lib/src/sql/subquery.rs index 599e23a6..6fa5cbfa 100644 --- a/lib/src/sql/subquery.rs +++ b/lib/src/sql/subquery.rs @@ -67,8 +67,8 @@ impl Subquery { // Process result match v.limit() { 1 => match v.expr.single() { - Some(v) => res.first(&ctx, &opt, txn).await?.get(&ctx, &opt, txn, &v).await, - None => res.first(&ctx, &opt, txn).await, + Some(v) => res.first().get(&ctx, &opt, txn, &v).await, + None => res.first().ok(), }, _ => match v.expr.single() { Some(v) => res.get(&ctx, &opt, txn, &v).await, diff --git a/lib/src/sql/value/all.rs b/lib/src/sql/value/all.rs index 54145442..471b900c 100644 --- a/lib/src/sql/value/all.rs +++ b/lib/src/sql/value/all.rs @@ -1,17 +1,8 @@ -use crate::dbs::Options; -use crate::dbs::Runtime; -use crate::dbs::Transaction; -use crate::err::Error; use crate::sql::part::Part; use crate::sql::value::Value; impl Value { - pub async fn all( - &self, - ctx: &Runtime, - opt: &Options, - txn: &Transaction, - ) -> Result { - self.get(ctx, opt, txn, &[Part::All]).await + pub fn all(&self) -> Self { + self.pick(&[Part::All]) } } diff --git a/lib/src/sql/value/first.rs b/lib/src/sql/value/first.rs index 15356e42..15b4dcbf 100644 --- a/lib/src/sql/value/first.rs +++ b/lib/src/sql/value/first.rs @@ -1,17 +1,8 @@ -use crate::dbs::Options; -use crate::dbs::Runtime; -use crate::dbs::Transaction; -use crate::err::Error; use crate::sql::part::Part; use crate::sql::value::Value; impl Value { - pub async fn first( - &self, - ctx: &Runtime, - opt: &Options, - txn: &Transaction, - ) -> Result { - self.get(ctx, opt, txn, &[Part::First]).await + pub fn first(&self) -> Self { + self.pick(&[Part::First]) } } diff --git a/lib/src/sql/value/get.rs b/lib/src/sql/value/get.rs index fb46097b..e51d3a63 100644 --- a/lib/src/sql/value/get.rs +++ b/lib/src/sql/value/get.rs @@ -81,8 +81,7 @@ impl Value { Arc::new(stm) .compute(ctx, opt, txn, None) .await? - .first(ctx, opt, txn) - .await? + .first() .get(ctx, opt, txn, path) .await } diff --git a/lib/src/sql/value/last.rs b/lib/src/sql/value/last.rs index 15db157c..e4f02ef2 100644 --- a/lib/src/sql/value/last.rs +++ b/lib/src/sql/value/last.rs @@ -1,17 +1,8 @@ -use crate::dbs::Options; -use crate::dbs::Runtime; -use crate::dbs::Transaction; -use crate::err::Error; use crate::sql::part::Part; use crate::sql::value::Value; impl Value { - pub async fn last( - &self, - ctx: &Runtime, - opt: &Options, - txn: &Transaction, - ) -> Result { - self.get(ctx, opt, txn, &[Part::Last]).await + pub fn last(&self) -> Self { + self.pick(&[Part::Last]) } }