sea_query/extension/postgres/func/json_table/
exists_column.rs1use std::borrow::Cow;
2
3use crate::{TypeRef, extension::postgres::json_table::ExistsOnErrorClause};
4
5use super::types::JsonTableColumn;
6
7#[derive(Debug, Clone)]
9pub struct ExistsColumn {
10 name: Cow<'static, str>,
11 column_type: TypeRef,
12 path: Option<Cow<'static, str>>,
13 on_error: Option<ExistsOnErrorClause>,
14}
15
16impl ExistsColumn {
17 pub fn new(name: impl Into<Cow<'static, str>>, column_type: impl Into<TypeRef>) -> Self {
18 Self {
19 name: name.into(),
20 column_type: column_type.into(),
21 path: None,
22 on_error: None,
23 }
24 }
25
26 pub fn path(mut self, path: impl Into<Cow<'static, str>>) -> Self {
27 self.path = Some(path.into());
28 self
29 }
30
31 pub fn error_on_error(mut self) -> Self {
32 self.on_error = Some(ExistsOnErrorClause::Error);
33 self
34 }
35
36 pub fn true_on_error(mut self) -> Self {
37 self.on_error = Some(ExistsOnErrorClause::True);
38 self
39 }
40
41 pub fn false_on_error(mut self) -> Self {
42 self.on_error = Some(ExistsOnErrorClause::False);
43 self
44 }
45
46 pub fn unknown_on_error(mut self) -> Self {
47 self.on_error = Some(ExistsOnErrorClause::Unknown);
48 self
49 }
50
51 pub(super) fn into_column(self) -> JsonTableColumn {
52 JsonTableColumn::Exists {
53 name: self.name,
54 column_type: self.column_type,
55 path: self.path,
56 on_error: self.on_error,
57 }
58 }
59}