sea_query/extension/postgres/func/json_table/
exists_column.rs

1use std::borrow::Cow;
2
3use crate::{
4    TypeRef,
5    extension::postgres::json_table::{ExistsOnErrorClause, JsonTableColumn},
6};
7
8/// Builder for EXISTS columns in JSON_TABLE
9#[derive(Debug, Clone)]
10pub struct ExistsColumnBuilder<T> {
11    pub(super) builder: T,
12    pub(super) name: Cow<'static, str>,
13    pub(super) column_type: TypeRef,
14    pub(super) path: Option<Cow<'static, str>>,
15    pub(super) on_error: Option<ExistsOnErrorClause>,
16}
17
18impl<T> ExistsColumnBuilder<T> {
19    /// Set PATH clause
20    pub fn path<P>(mut self, path: P) -> Self
21    where
22        P: Into<Cow<'static, str>>,
23    {
24        self.path = Some(path.into());
25        self
26    }
27
28    /// Convenience method for `ERROR ON ERROR`
29    pub fn error_on_error(mut self) -> Self {
30        self.on_error = Some(ExistsOnErrorClause::Error);
31        self
32    }
33
34    /// Convenience method for `TRUE ON ERROR`
35    pub fn true_on_error(mut self) -> Self {
36        self.on_error = Some(ExistsOnErrorClause::True);
37        self
38    }
39
40    /// Convenience method for `FALSE ON ERROR`
41    pub fn false_on_error(mut self) -> Self {
42        self.on_error = Some(ExistsOnErrorClause::False);
43        self
44    }
45
46    /// Convenience method for `UNKNOWN ON ERROR`
47    pub fn unknown_on_error(mut self) -> Self {
48        self.on_error = Some(ExistsOnErrorClause::Unknown);
49        self
50    }
51}
52
53impl ExistsColumnBuilder<super::Builder> {
54    /// Finish building this column and return to the main builder
55    pub fn build_column(mut self) -> super::Builder {
56        self.builder.columns.push(JsonTableColumn::Exists {
57            name: self.name,
58            column_type: self.column_type,
59            path: self.path,
60            on_error: self.on_error,
61        });
62        self.builder
63    }
64}