Skip to main content

sql_orm_query/
delete.rs

1use crate::expr::TableRef;
2use crate::predicate::Predicate;
3use sql_orm_core::Entity;
4
5#[derive(Debug, Clone, PartialEq)]
6pub struct DeleteQuery {
7    pub from: TableRef,
8    pub predicate: Option<Predicate>,
9    pub allow_all_rows: bool,
10}
11
12impl DeleteQuery {
13    pub fn from_entity<E: Entity>() -> Self {
14        Self {
15            from: TableRef::for_entity::<E>(),
16            predicate: None,
17            allow_all_rows: false,
18        }
19    }
20
21    pub fn filter(mut self, predicate: Predicate) -> Self {
22        self.predicate = Some(match self.predicate.take() {
23            Some(existing) => Predicate::and(vec![existing, predicate]),
24            None => predicate,
25        });
26        self
27    }
28
29    pub const fn allow_all_rows(mut self) -> Self {
30        self.allow_all_rows = true;
31        self
32    }
33}