Skip to main content

sql_builder/query/
mod.rs

1//! The statements the builder renders; [`Query`] starts any of them.
2//!
3//! [`SelectStatement`], [`InsertStatement`], [`UpdateStatement`] and [`DeleteStatement`],
4//! with `WITH` queries and the clauses they share: conditions, `CASE`, `ORDER BY`, window
5//! frames, `ON CONFLICT` and `RETURNING`.
6
7mod case;
8mod condition;
9mod delete;
10mod insert;
11mod on_conflict;
12mod ordered;
13mod returning;
14mod select;
15mod traits;
16mod update;
17mod window;
18mod with;
19
20pub use case::*;
21pub use condition::*;
22pub use delete::*;
23pub use insert::*;
24pub use on_conflict::*;
25pub use ordered::*;
26pub use returning::*;
27pub use select::*;
28pub use traits::*;
29pub use update::*;
30pub use window::*;
31pub use with::*;
32
33/// Where a statement starts: `Query::select()`, `Query::insert()` and so on.
34#[derive(Debug, Clone)]
35pub struct Query;
36
37/// One of the four table statements.
38#[allow(clippy::large_enum_variant)]
39#[derive(Debug, Clone)]
40pub enum QueryStatement {
41    Select(SelectStatement),
42    Insert(InsertStatement),
43    Update(UpdateStatement),
44    Delete(DeleteStatement),
45}
46
47/// A statement nested in another: an expression's subquery or a derived table.
48#[allow(clippy::large_enum_variant)]
49#[derive(Debug, Clone, PartialEq)]
50pub enum SubQueryStatement {
51    SelectStatement(SelectStatement),
52    InsertStatement(InsertStatement),
53    UpdateStatement(UpdateStatement),
54    DeleteStatement(DeleteStatement),
55    WithStatement(WithQuery),
56}
57
58impl Query {
59    /// An empty [`SelectStatement`].
60    pub fn select() -> SelectStatement {
61        SelectStatement::new()
62    }
63
64    /// An empty [`InsertStatement`].
65    pub fn insert() -> InsertStatement {
66        InsertStatement::new()
67    }
68
69    /// An empty [`UpdateStatement`].
70    pub fn update() -> UpdateStatement {
71        UpdateStatement::new()
72    }
73
74    /// An empty [`DeleteStatement`].
75    pub fn delete() -> DeleteStatement {
76        DeleteStatement::new()
77    }
78
79    /// An empty [`WithClause`], for the common table expressions of a `WITH` query.
80    pub fn with() -> WithClause {
81        WithClause::new()
82    }
83
84    /// The builder of a `RETURNING` column list.
85    pub fn returning() -> Returning {
86        Returning::new()
87    }
88}