sqlorm_core/sb/
mod.rs

1use crate::{Condition, TableInfo, selectable::Selectable};
2
3pub struct Update;
4pub struct Delete;
5
6pub struct SB<T, Stage> {
7    /// Base table information and selected columns.
8    pub base: TableInfo,
9    /// Fields update
10    pub fields: Option<Vec<&'static str>>,
11    /// WHERE clause conditions combined with AND.
12    pub filters: Vec<Condition>,
13    /// The entity to operate on
14    pub entity: T,
15    _marker: std::marker::PhantomData<Stage>,
16}
17
18impl<T, Stage> SB<T, Stage> {
19    pub fn new(base: TableInfo, entity: T) -> SB<T, Stage> {
20        SB {
21            base,
22            filters: Vec::new(),
23            fields: None,
24            entity,
25            _marker: std::marker::PhantomData,
26        }
27    }
28}
29impl<T> SB<T, Update> {
30    pub fn columns(mut self, fields: impl Selectable) -> Self {
31        self.fields = Some(fields.collect());
32        self
33    }
34
35    pub fn filter(mut self, cond: Condition) -> Self {
36        self.filters.push(cond);
37        self
38    }
39}