1use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
7pub struct TableInfo {
8 pub name: String,
10 pub columns: Vec<ColumnInfo>,
12 pub row_count: u64,
14 pub primary_key: Vec<String>,
16 pub create_sql: Option<String>,
18}
19
20#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
22pub struct ViewInfo {
23 pub name: String,
25 pub create_sql: Option<String>,
27}
28
29#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
31pub struct SchemaObjectInfo {
32 pub name: String,
34 pub table_name: String,
36 pub create_sql: Option<String>,
38}
39
40#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
42pub struct ColumnInfo {
43 pub name: String,
45 pub col_type: String,
47 pub nullable: bool,
49 pub default_value: Option<String>,
51 pub is_primary_key: bool,
53}
54
55#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
57pub enum SqlValue {
58 Null,
60 Integer(i64),
62 Real(f64),
64 Text(String),
66 Blob(Vec<u8>),
68}
69
70#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
72pub struct DatabaseSummary {
73 pub path: String,
75 pub tables: Vec<TableInfo>,
77 pub views: Vec<ViewInfo>,
79 pub indexes: Vec<SchemaObjectInfo>,
81 pub triggers: Vec<SchemaObjectInfo>,
83}
84
85#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
87pub struct TablePage {
88 pub table_name: String,
90 pub columns: Vec<ColumnInfo>,
92 pub rows: Vec<Vec<SqlValue>>,
94 pub page: usize,
96 pub page_size: usize,
98 pub total_rows: u64,
100 pub sort: Option<TableSort>,
102}
103
104#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
106pub struct TableSort {
107 pub column: String,
109 pub direction: SortDirection,
111}
112
113#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
115pub enum SortDirection {
116 Asc,
118 Desc,
120}
121
122#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
124pub struct TableQuery {
125 pub page: usize,
127 pub page_size: usize,
129 pub sort: Option<TableSort>,
131}
132
133impl Default for TableQuery {
134 fn default() -> Self {
135 Self {
136 page: 0,
137 page_size: 100,
138 sort: None,
139 }
140 }
141}
142
143#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
145pub struct SchemaDiff {
146 pub added_tables: Vec<TableInfo>,
148 pub removed_tables: Vec<TableInfo>,
150 pub modified_tables: Vec<TableSchemaDiff>,
152 pub unchanged_tables: Vec<String>,
154 pub added_indexes: Vec<SchemaObjectInfo>,
156 pub removed_indexes: Vec<SchemaObjectInfo>,
158 pub modified_indexes: Vec<(SchemaObjectInfo, SchemaObjectInfo)>,
160 pub added_triggers: Vec<SchemaObjectInfo>,
162 pub removed_triggers: Vec<SchemaObjectInfo>,
164 pub modified_triggers: Vec<(SchemaObjectInfo, SchemaObjectInfo)>,
166}
167
168#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
170pub struct TableSchemaDiff {
171 pub table_name: String,
173 pub added_columns: Vec<ColumnInfo>,
175 pub removed_columns: Vec<ColumnInfo>,
177 pub modified_columns: Vec<(ColumnInfo, ColumnInfo)>,
179}
180
181#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
183pub struct TableDataDiff {
184 pub table_name: String,
186 pub columns: Vec<String>,
188 pub added_rows: Vec<Vec<SqlValue>>,
190 pub removed_rows: Vec<Vec<SqlValue>>,
192 pub removed_row_keys: Vec<Vec<SqlValue>>,
194 pub modified_rows: Vec<RowModification>,
196 pub stats: DiffStats,
198 pub warnings: Vec<String>,
200}
201
202#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
204pub struct RowModification {
205 pub primary_key: Vec<SqlValue>,
207 pub changes: Vec<CellChange>,
209}
210
211#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
213pub struct CellChange {
214 pub column: String,
216 pub old_value: SqlValue,
218 pub new_value: SqlValue,
220}
221
222#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
224pub struct DiffStats {
225 pub total_rows_left: u64,
227 pub total_rows_right: u64,
229 pub added: u64,
231 pub removed: u64,
233 pub modified: u64,
235 pub unchanged: u64,
237}
238
239#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
241pub struct Snapshot {
242 pub id: String,
244 pub name: String,
246 pub source_path: String,
248 pub created_at: String,
250 pub table_count: u32,
252 pub total_rows: u64,
254}
255
256impl SqlValue {
257 pub fn display(&self) -> String {
259 match self {
260 Self::Null => "NULL".to_owned(),
261 Self::Integer(value) => value.to_string(),
262 Self::Real(value) => value.to_string(),
263 Self::Text(value) => value.clone(),
264 Self::Blob(bytes) => format!("[BLOB: {} bytes]", bytes.len()),
265 }
266 }
267}