use crate::ctx::Context;
use crate::dbs::Statement;
use crate::dbs::{Options, Transaction};
use crate::doc::Document;
use crate::err::Error;
use crate::idiom::Idiom;
impl<'a> Document<'a> {
pub async fn clean(
&mut self,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_stm: &Statement<'_>,
) -> Result<(), Error> {
let tb = self.tb(opt, txn).await?;
if tb.full {
let mut keys: Vec<Idiom> = vec![];
for fd in self.fd(opt, txn).await?.iter() {
match fd.flex {
false => {
for k in self.current.doc.each(&fd.name).into_iter() {
keys.push(k);
}
}
true => {
for k in self.current.doc.every(Some(&fd.name), true, true).into_iter() {
keys.push(k);
}
}
}
}
for fd in self.current.doc.every(None, true, true).iter() {
if !keys.contains(fd) {
match fd {
fd if fd.is_id() => continue,
fd if fd.is_in() => continue,
fd if fd.is_out() => continue,
fd if fd.is_meta() => continue,
fd => self.current.doc.to_mut().del(ctx, opt, txn, fd).await?,
}
}
}
}
Ok(())
}
}