2022-02-06 01:14:56 +00:00
|
|
|
use crate::dbs::Options;
|
|
|
|
use crate::dbs::Runtime;
|
|
|
|
use crate::dbs::Statement;
|
2022-02-15 01:00:30 +00:00
|
|
|
use crate::dbs::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,
|
|
|
|
ctx: &Runtime,
|
2022-02-06 21:06:52 +00:00
|
|
|
opt: &Options,
|
2022-02-15 03:33:16 +00:00
|
|
|
txn: &Transaction,
|
2022-02-26 23:30:19 +00:00
|
|
|
stm: &Statement,
|
2022-02-06 01:14:56 +00:00
|
|
|
) -> Result<(), Error> {
|
|
|
|
// Extract statement clause
|
|
|
|
let cond = match stm {
|
|
|
|
Statement::Select(stm) => stm.cond.as_ref(),
|
|
|
|
Statement::Update(stm) => stm.cond.as_ref(),
|
2022-02-14 22:20:11 +00:00
|
|
|
Statement::Delete(stm) => stm.cond.as_ref(),
|
2022-02-06 01:14:56 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
// Match clause
|
|
|
|
match cond {
|
|
|
|
Some(v) => {
|
2022-02-15 01:00:30 +00:00
|
|
|
match v.expr.compute(ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
|
2022-03-06 10:58:59 +00:00
|
|
|
false => Err(Error::Ignore),
|
2022-02-06 01:14:56 +00:00
|
|
|
true => Ok(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => Ok(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|