2022-02-06 01:14:56 +00:00
|
|
|
use crate::dbs::Executor;
|
|
|
|
use crate::dbs::Options;
|
|
|
|
use crate::dbs::Runtime;
|
|
|
|
use crate::dbs::Statement;
|
|
|
|
use crate::doc::Document;
|
|
|
|
use crate::err::Error;
|
2021-03-29 15:43:37 +00:00
|
|
|
|
2022-02-06 01:14:56 +00:00
|
|
|
impl Document {
|
|
|
|
pub async fn check(
|
|
|
|
&self,
|
|
|
|
ctx: &Runtime,
|
|
|
|
opt: &Options<'_>,
|
|
|
|
exe: &Executor<'_>,
|
|
|
|
stm: &Statement<'_>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
// Extract statement clause
|
|
|
|
let cond = match stm {
|
|
|
|
Statement::Select(stm) => stm.cond.as_ref(),
|
|
|
|
Statement::Update(stm) => stm.cond.as_ref(),
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
// Match clause
|
|
|
|
match cond {
|
|
|
|
Some(v) => {
|
|
|
|
match v.expr.compute(ctx, opt, exe, Some(&self.current)).await?.is_truthy() {
|
|
|
|
false => Err(Error::IgnoreError),
|
|
|
|
true => Ok(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => Ok(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|