1use super::dml::Select;
2use super::expr::Expr;
3use super::span::{Span, Spanned};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
12#[serde(deny_unknown_fields)]
13pub struct CreateContinuousAggregate {
14 pub name: String,
15 pub name_span: Span,
16 #[serde(with = "crate::nim_bridge::continuous_aggregate_select_wire")]
17 pub query: Select,
18 pub options: Vec<ContinuousAggregateOption>,
19 pub span: Span,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
24#[serde(deny_unknown_fields)]
25pub struct ContinuousAggregateOption {
26 pub key: String,
27 pub key_span: Span,
28 pub value: String,
29 pub value_span: Span,
30 pub span: Span,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct CreateTable {
35 pub if_not_exists: bool,
36 pub name: String,
37 pub columns: Vec<ColumnDef>,
38 pub constraints: Vec<TableConstraint>,
39 pub with_options: Vec<IndexOption>,
40 pub span: Span,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct ColumnDef {
45 pub name: String,
46 pub data_type: DataType,
47 pub constraints: Vec<ColumnConstraint>,
48 pub span: Span,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(tag = "variant")]
53pub enum DataType {
54 Integer,
55 Int,
56 BigInt,
57 Float,
58 Double,
59 Text,
60 Blob,
61 Boolean,
62 Bool,
63 Timestamp,
64 Vector {
65 dimension: u32,
66 metric: Option<VectorMetric>,
67 },
68}
69
70#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
71pub enum VectorMetric {
72 Cosine,
73 L2,
74 Inner,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(tag = "variant")]
79pub enum ColumnConstraint {
80 NotNull { span: Span },
81 PrimaryKey { span: Span },
82 Unique { span: Span },
83 Default { value: Expr, span: Span },
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(tag = "variant")]
88pub enum TableConstraint {
89 PrimaryKey { columns: Vec<String>, span: Span },
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct DropTable {
94 pub if_exists: bool,
95 pub name: String,
96 pub span: Span,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct CreateIndex {
101 pub if_not_exists: bool,
102 pub name: String,
103 pub table: String,
104 pub column: String,
105 pub method: Option<IndexMethod>,
106 pub options: Vec<IndexOption>,
107 pub span: Span,
108}
109
110#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
111pub enum IndexMethod {
112 BTree,
113 Hnsw,
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize)]
117pub struct IndexOption {
118 pub key: String,
119 pub value: String,
120 pub span: Span,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct DropIndex {
125 pub if_exists: bool,
126 pub name: String,
127 pub span: Span,
128}
129
130impl Spanned for CreateTable {
131 fn span(&self) -> Span {
132 self.span
133 }
134}
135
136impl Spanned for CreateContinuousAggregate {
137 fn span(&self) -> Span {
138 self.span
139 }
140}
141
142impl Spanned for ContinuousAggregateOption {
143 fn span(&self) -> Span {
144 self.span
145 }
146}
147
148impl Spanned for ColumnDef {
149 fn span(&self) -> Span {
150 self.span
151 }
152}
153
154impl Spanned for ColumnConstraint {
155 fn span(&self) -> Span {
156 match self {
157 ColumnConstraint::NotNull { span }
158 | ColumnConstraint::PrimaryKey { span }
159 | ColumnConstraint::Unique { span }
160 | ColumnConstraint::Default { span, .. } => *span,
161 }
162 }
163}
164
165impl Spanned for TableConstraint {
166 fn span(&self) -> Span {
167 match self {
168 TableConstraint::PrimaryKey { span, .. } => *span,
169 }
170 }
171}
172
173impl Spanned for DropTable {
174 fn span(&self) -> Span {
175 self.span
176 }
177}
178
179impl Spanned for CreateIndex {
180 fn span(&self) -> Span {
181 self.span
182 }
183}
184
185impl Spanned for IndexOption {
186 fn span(&self) -> Span {
187 self.span
188 }
189}
190
191impl Spanned for DropIndex {
192 fn span(&self) -> Span {
193 self.span
194 }
195}