sqlorm_core/sb/
mod.rs

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