Skip to main content

ormdantic_schema/
index.rs

1#[derive(Debug, Clone, PartialEq, Eq)]
2pub struct IndexDef {
3    name: String,
4    columns: Vec<String>,
5    expressions: Vec<String>,
6    unique: bool,
7    where_expr: Option<String>,
8    include_columns: Vec<String>,
9    method: Option<String>,
10    postgres_with: Vec<(String, String)>,
11}
12
13impl IndexDef {
14    pub fn new(name: impl Into<String>, columns: Vec<String>) -> Self {
15        Self {
16            name: name.into(),
17            columns,
18            expressions: Vec::new(),
19            unique: false,
20            where_expr: None,
21            include_columns: Vec::new(),
22            method: None,
23            postgres_with: Vec::new(),
24        }
25    }
26
27    pub fn unique(mut self, unique: bool) -> Self {
28        self.unique = unique;
29        self
30    }
31
32    pub fn where_expr(mut self, where_expr: impl Into<String>) -> Self {
33        self.where_expr = Some(where_expr.into());
34        self
35    }
36
37    pub fn expressions(mut self, expressions: Vec<String>) -> Self {
38        self.expressions = expressions;
39        self
40    }
41
42    pub fn include_columns(mut self, include_columns: Vec<String>) -> Self {
43        self.include_columns = include_columns;
44        self
45    }
46
47    pub fn method(mut self, method: impl Into<String>) -> Self {
48        self.method = Some(method.into());
49        self
50    }
51
52    pub fn postgres_with(mut self, parameters: Vec<(String, String)>) -> Self {
53        self.postgres_with = parameters;
54        self
55    }
56
57    pub fn name(&self) -> &str {
58        &self.name
59    }
60
61    pub fn columns(&self) -> &[String] {
62        &self.columns
63    }
64
65    pub fn expressions_ref(&self) -> &[String] {
66        &self.expressions
67    }
68
69    pub fn is_unique(&self) -> bool {
70        self.unique
71    }
72
73    pub fn predicate(&self) -> Option<&str> {
74        self.where_expr.as_deref()
75    }
76
77    pub fn include_columns_ref(&self) -> &[String] {
78        &self.include_columns
79    }
80
81    pub fn method_name(&self) -> Option<&str> {
82        self.method.as_deref()
83    }
84
85    pub fn postgres_with_ref(&self) -> &[(String, String)] {
86        &self.postgres_with
87    }
88}