2022-05-14 12:35:08 +00:00
|
|
|
use crate::ctx::Context;
|
2022-02-06 01:14:56 +00:00
|
|
|
use crate::dbs::Statement;
|
2023-07-06 14:57:42 +00:00
|
|
|
use crate::dbs::{Options, Transaction};
|
2022-02-06 01:14:56 +00:00
|
|
|
use crate::doc::Document;
|
|
|
|
use crate::err::Error;
|
2021-03-29 15:43:37 +00:00
|
|
|
|
2022-02-13 19:03:00 +00:00
|
|
|
impl<'a> Document<'a> {
|
2022-02-06 01:14:56 +00:00
|
|
|
pub async fn check(
|
|
|
|
&self,
|
2022-05-14 12:35:08 +00:00
|
|
|
ctx: &Context<'_>,
|
2022-02-06 21:06:52 +00:00
|
|
|
opt: &Options,
|
2023-07-06 14:57:42 +00:00
|
|
|
txn: &Transaction,
|
2022-05-13 20:46:56 +00:00
|
|
|
stm: &Statement<'_>,
|
2022-02-06 01:14:56 +00:00
|
|
|
) -> Result<(), Error> {
|
2022-04-01 09:15:52 +00:00
|
|
|
// Check where condition
|
|
|
|
if let Some(cond) = stm.conds() {
|
2022-04-06 18:44:55 +00:00
|
|
|
// Check if the expression is truthy
|
2023-07-06 14:57:42 +00:00
|
|
|
if !cond.compute(ctx, opt, txn, Some(&self.current)).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
|
|
|
}
|
|
|
|
}
|