surrealpatch/lib/src/doc/check.rs

28 lines
593 B
Rust
Raw Normal View History

use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Statement;
use crate::doc::Document;
use crate::err::Error;
2021-03-29 15:43:37 +00:00
impl<'a> Document<'a> {
pub async fn check(
&self,
ctx: &Context<'_>,
opt: &Options,
stm: &Statement<'_>,
) -> Result<(), Error> {
// Check where condition
if let Some(cond) = stm.conds() {
let mut ctx = Context::new(ctx);
ctx.add_cursor_doc(&self.current);
2022-04-06 18:44:55 +00:00
// Check if the expression is truthy
if !cond.compute(&ctx, opt).await?.is_truthy() {
2022-04-06 18:44:55 +00:00
// Ignore this document
return Err(Error::Ignore);
}
}
// Carry on
Ok(())
}
}