chain_builder/query/join/
mod.rs

1//! JOIN functionality for query building
2
3mod join_methods;
4
5use serde_json::Value;
6
7// Re-export join methods
8pub use join_methods::*;
9
10/// JOIN statement types
11#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
12pub(crate) enum JoinStatement {
13    /// Simple ON condition: left_column, operator, right_column
14    On(String, String, String),
15    /// OR chain for complex JOIN conditions
16    OrChain(Box<JoinBuilder>),
17    /// ON condition with value: column, operator, value
18    OnVal(String, String, Value),
19    /// Raw ON condition with optional bind parameters
20    OnRaw(String, Option<Vec<Value>>),
21}
22
23impl JoinStatement {
24    /// Convert statement to a mutable join builder reference
25    pub fn as_mut_join_builder(&mut self) -> &mut JoinBuilder {
26        match self {
27            JoinStatement::OrChain(query) => query,
28            _ => panic!("JoinStatement::as_mut_join_builder() called on non-chain statement"),
29        }
30    }
31}
32
33/// JOIN builder for constructing JOIN clauses
34#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
35pub struct JoinBuilder {
36    /// Table name to join
37    pub(crate) table: String,
38    /// JOIN type (JOIN, LEFT JOIN, RIGHT JOIN, etc.)
39    pub(crate) join_type: String,
40    /// JOIN conditions
41    pub(crate) statement: Vec<JoinStatement>,
42    /// Raw JOIN SQL with optional bind parameters
43    pub(crate) raw: Option<(String, Option<Vec<Value>>)>,
44    /// Table alias
45    pub(crate) as_name: Option<String>,
46}