use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TableSchema {
pub name: String,
pub columns: Vec<ColumnInfo>,
pub primary_key: Option<Vec<String>>,
pub foreign_keys: Vec<ForeignKey>,
pub indexes: Vec<IndexInfo>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ColumnInfo {
pub name: String,
pub data_type: String,
pub nullable: bool,
pub default_value: Option<String>,
pub is_primary_key: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ForeignKey {
pub column: String,
pub references_table: String,
pub references_column: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IndexInfo {
pub name: String,
pub columns: Vec<String>,
pub unique: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TableInfo {
pub name: String,
pub row_count: Option<u64>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RowQuery {
#[serde(default)]
pub offset: u64,
#[serde(default = "default_limit")]
pub limit: u64,
pub sort_by: Option<String>,
pub sort_order: Option<SortOrder>,
#[serde(default)]
pub filters: std::collections::HashMap<String, String>,
}
fn default_limit() -> u64 {
100
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum SortOrder {
Ascending,
Descending,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RowsResponse {
pub rows: Vec<serde_json::Value>,
pub columns: Vec<String>,
pub total: u64,
pub offset: u64,
pub limit: u64,
pub has_more: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TablesResponse {
pub tables: Vec<TableInfo>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QueryRequest {
pub sql: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QueryResult {
pub columns: Vec<String>,
pub rows: Vec<serde_json::Value>,
pub affected_rows: u64,
pub execution_time_milliseconds: u64,
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CountResponse {
pub count: u64,
}