surrealpatch/core/src/doc/check.rs

39 lines
818 B
Rust
Raw Normal View History

use crate::ctx::Context;
2024-05-28 10:43:45 +00:00
use crate::dbs::Options;
use crate::dbs::Statement;
use crate::doc::{CursorDoc, Document};
use crate::err::Error;
use crate::sql::Cond;
use reblessive::tree::Stk;
2021-03-29 15:43:37 +00:00
2024-08-15 16:01:02 +00:00
impl Document {
pub async fn check(
&self,
stk: &mut Stk,
2024-08-15 16:01:02 +00:00
ctx: &Context,
opt: &Options,
stm: &Statement<'_>,
) -> Result<(), Error> {
2024-05-28 10:43:45 +00:00
Self::check_cond(stk, ctx, opt, stm.conds(), &self.current).await
}
pub(crate) async fn check_cond(
stk: &mut Stk,
2024-08-15 16:01:02 +00:00
ctx: &Context,
opt: &Options,
cond: Option<&Cond>,
2024-08-15 16:01:02 +00:00
doc: &CursorDoc,
) -> Result<(), Error> {
// Check where condition
if let Some(cond) = cond {
2022-04-06 18:44:55 +00:00
// Check if the expression is truthy
2024-05-28 10:43:45 +00:00
if !cond.compute(stk, ctx, opt, Some(doc)).await?.is_truthy() {
2022-04-06 18:44:55 +00:00
// Ignore this document
return Err(Error::Ignore);
}
}
// Carry on
Ok(())
}
}