Make simple value fetching functions synchronous

This commit is contained in:
Tobie Morgan Hitchcock 2022-03-25 21:14:48 +00:00
parent 2f033aa996
commit 9f7527c01a
6 changed files with 13 additions and 46 deletions

View file

@ -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?;
}

View file

@ -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,

View file

@ -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, Error> {
self.get(ctx, opt, txn, &[Part::All]).await
pub fn all(&self) -> Self {
self.pick(&[Part::All])
}
}

View file

@ -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, Error> {
self.get(ctx, opt, txn, &[Part::First]).await
pub fn first(&self) -> Self {
self.pick(&[Part::First])
}
}

View file

@ -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
}

View file

@ -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, Error> {
self.get(ctx, opt, txn, &[Part::Last]).await
pub fn last(&self) -> Self {
self.pick(&[Part::Last])
}
}