1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Deserialize, Serialize)]
7pub struct TableColumn {
8 pub name: String,
10 #[serde(rename = "type")]
12 pub column_type: String,
13 #[serde(default)]
15 pub nullable: bool,
16}
17
18impl TableColumn {
19 pub fn new(name: &str, column_type: &str) -> Self {
21 Self {
22 name: name.to_string(),
23 column_type: column_type.to_string(),
24 nullable: true,
25 }
26 }
27
28 pub fn not_null(mut self) -> Self {
30 self.nullable = false;
31 self
32 }
33}
34
35#[derive(Debug, Clone, Deserialize, Serialize)]
37pub struct TableColumnInfo {
38 pub name: Option<String>,
40 #[serde(rename = "type")]
42 pub column_type: Option<String>,
43}
44
45#[derive(Debug, Clone, Deserialize, Serialize)]
47pub struct TableOwner {
48 pub handle: Option<String>,
50 #[serde(rename = "type")]
52 pub owner_type: Option<String>,
53}
54
55#[derive(Debug, Clone, Deserialize, Serialize)]
57pub struct Table {
58 pub full_name: Option<String>,
60 #[serde(default)]
62 pub columns: Vec<TableColumnInfo>,
63 pub is_private: Option<bool>,
65 pub owner: Option<TableOwner>,
67 pub table_size_bytes: Option<String>,
69 pub created_at: Option<String>,
71 pub updated_at: Option<String>,
73 pub purged_at: Option<String>,
75}
76
77#[derive(Debug, Clone, Serialize)]
79pub struct CreateTableRequest {
80 pub namespace: String,
82 pub table_name: String,
84 pub schema: Vec<TableColumn>,
86 #[serde(skip_serializing_if = "Option::is_none")]
88 pub description: Option<String>,
89 #[serde(skip_serializing_if = "Option::is_none")]
91 pub is_private: Option<bool>,
92}
93
94impl CreateTableRequest {
95 pub fn new(namespace: &str, table_name: &str, schema: Vec<TableColumn>) -> Self {
97 Self {
98 namespace: namespace.to_string(),
99 table_name: table_name.to_string(),
100 schema,
101 description: None,
102 is_private: None,
103 }
104 }
105
106 pub fn description(mut self, description: &str) -> Self {
108 self.description = Some(description.to_string());
109 self
110 }
111
112 pub fn private(mut self, is_private: bool) -> Self {
114 self.is_private = Some(is_private);
115 self
116 }
117}
118
119#[derive(Debug, Clone, Deserialize, Serialize)]
121pub struct CreateTableResponse {
122 pub full_name: Option<String>,
124 pub namespace: Option<String>,
126 pub table_name: Option<String>,
128 pub already_existed: Option<bool>,
130 pub example_query: Option<String>,
132 pub message: Option<String>,
134}
135
136#[derive(Debug, Clone, Serialize)]
138pub struct UploadCsvRequest {
139 pub table_name: String,
141 pub data: String,
143 #[serde(skip_serializing_if = "Option::is_none")]
145 pub description: Option<String>,
146 #[serde(skip_serializing_if = "Option::is_none")]
148 pub is_private: Option<bool>,
149}
150
151impl UploadCsvRequest {
152 pub fn new(table_name: &str, csv_data: &str) -> Self {
154 Self {
155 table_name: table_name.to_string(),
156 data: csv_data.to_string(),
157 description: None,
158 is_private: None,
159 }
160 }
161}
162
163#[derive(Debug, Clone, Deserialize, Serialize)]
165pub struct UploadCsvResponse {
166 pub success: Option<bool>,
168 pub table_name: Option<String>,
170}
171
172#[derive(Debug, Clone, Deserialize, Serialize)]
174pub struct InsertResponse {
175 pub name: Option<String>,
177 pub rows_written: Option<i64>,
179 pub bytes_written: Option<i64>,
181}
182
183#[derive(Debug, Clone, Deserialize, Serialize)]
185pub struct ClearTableResponse {
186 pub message: Option<String>,
188}
189
190#[derive(Debug, Clone, Deserialize, Serialize)]
192pub struct DeleteTableResponse {
193 pub message: Option<String>,
195}
196
197#[derive(Debug, Clone, Deserialize, Serialize)]
199pub struct ListTablesResponse {
200 #[serde(default)]
202 pub tables: Vec<Table>,
203 pub next_offset: Option<i64>,
205}
206
207#[derive(Debug, Clone, Default)]
209pub struct ListTablesOptions {
210 pub limit: Option<u32>,
212 pub offset: Option<i64>,
214}
215
216impl ListTablesOptions {
217 pub fn to_query_string(&self) -> String {
218 let mut params = Vec::new();
219 if let Some(limit) = self.limit {
220 params.push(format!("limit={}", limit));
221 }
222 if let Some(offset) = self.offset {
223 params.push(format!("offset={}", offset));
224 }
225 if params.is_empty() {
226 String::new()
227 } else {
228 format!("?{}", params.join("&"))
229 }
230 }
231}