sqlorm_core/sb/
mod.rs

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