2022-05-14 12:35:08 +00:00
|
|
|
use crate::ctx::Context;
|
2024-05-28 10:43:45 +00:00
|
|
|
use crate::dbs::Options;
|
2022-02-06 01:14:56 +00:00
|
|
|
use crate::dbs::Statement;
|
2024-05-24 13:45:21 +00:00
|
|
|
use crate::doc::{CursorDoc, Document};
|
2022-02-06 01:14:56 +00:00
|
|
|
use crate::err::Error;
|
2024-05-24 13:45:21 +00:00
|
|
|
use crate::sql::Cond;
|
2024-04-18 15:51:47 +00:00
|
|
|
use reblessive::tree::Stk;
|
2021-03-29 15:43:37 +00:00
|
|
|
|
2024-08-15 16:01:02 +00:00
|
|
|
impl Document {
|
2022-02-06 01:14:56 +00:00
|
|
|
pub async fn check(
|
|
|
|
&self,
|
2024-04-18 15:51:47 +00:00
|
|
|
stk: &mut Stk,
|
2024-08-15 16:01:02 +00:00
|
|
|
ctx: &Context,
|
2022-02-06 21:06:52 +00:00
|
|
|
opt: &Options,
|
2022-05-13 20:46:56 +00:00
|
|
|
stm: &Statement<'_>,
|
2024-05-24 13:45:21 +00:00
|
|
|
) -> Result<(), Error> {
|
2024-05-28 10:43:45 +00:00
|
|
|
Self::check_cond(stk, ctx, opt, stm.conds(), &self.current).await
|
2024-05-24 13:45:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) async fn check_cond(
|
|
|
|
stk: &mut Stk,
|
2024-08-15 16:01:02 +00:00
|
|
|
ctx: &Context,
|
2024-05-24 13:45:21 +00:00
|
|
|
opt: &Options,
|
|
|
|
cond: Option<&Cond>,
|
2024-08-15 16:01:02 +00:00
|
|
|
doc: &CursorDoc,
|
2022-02-06 01:14:56 +00:00
|
|
|
) -> Result<(), Error> {
|
2022-04-01 09:15:52 +00:00
|
|
|
// Check where condition
|
2024-05-24 13:45:21 +00:00
|
|
|
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
|
2022-04-01 09:15:52 +00:00
|
|
|
return Err(Error::Ignore);
|
2022-02-06 01:14:56 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-01 09:15:52 +00:00
|
|
|
// Carry on
|
|
|
|
Ok(())
|
2022-02-06 01:14:56 +00:00
|
|
|
}
|
|
|
|
}
|