use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryResponse<T> {
pub data: Vec<T>,
pub count: usize,
#[serde(skip_serializing_if = "Option::is_none")]
pub total: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateResponse {
pub id: Value,
#[serde(rename = "affected_rows")]
pub affected_rows: usize,
pub success: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateResponse {
#[serde(rename = "affected_rows")]
pub affected_rows: usize,
pub success: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteResponse {
#[serde(rename = "affected_rows")]
pub affected_rows: usize,
pub success: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TableSchema {
pub name: String,
pub columns: Vec<ColumnInfo>,
#[serde(rename = "primary_key")]
pub primary_key: Option<String>,
#[serde(rename = "row_count")]
pub row_count: Option<usize>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ColumnInfo {
pub name: String,
pub r#type: String,
pub nullable: bool,
pub default: Option<Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StorageQuota {
#[serde(rename = "storage_quota_gb")]
pub storage_quota_gb: f64,
#[serde(rename = "storage_used_gb")]
pub storage_used_gb: f64,
#[serde(rename = "storage_expansion_gb")]
pub storage_expansion_gb: f64,
#[serde(rename = "storage_available_gb")]
pub storage_available_gb: f64,
#[serde(rename = "usage_percentage")]
pub usage_percentage: f64,
#[serde(rename = "can_expand_storage")]
pub can_expand_storage: bool,
#[serde(rename = "is_enterprise")]
pub is_enterprise: bool,
#[serde(rename = "plan_name")]
pub plan_name: String,
}
impl StorageQuota {
pub fn storage_quota_bytes(&self) -> i64 {
(self.storage_quota_gb * 1024.0 * 1024.0 * 1024.0) as i64
}
pub fn storage_used_bytes(&self) -> i64 {
(self.storage_used_gb * 1024.0 * 1024.0 * 1024.0) as i64
}
pub fn storage_available_bytes(&self) -> i64 {
(self.storage_available_gb * 1024.0 * 1024.0 * 1024.0) as i64
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StorageFile {
pub key: String,
pub size: i64,
#[serde(rename = "last_modified")]
pub last_modified: String,
#[serde(rename = "content_type")]
pub content_type: Option<String>,
pub etag: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileUploadResult {
pub key: String,
pub size: i64,
pub url: String,
pub success: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FilterOperator {
Eq,
Neq,
Gt,
Gte,
Lt,
Lte,
Like,
#[serde(rename = "is")]
IsNull,
}
impl std::fmt::Display for FilterOperator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FilterOperator::Eq => write!(f, "eq"),
FilterOperator::Neq => write!(f, "neq"),
FilterOperator::Gt => write!(f, "gt"),
FilterOperator::Gte => write!(f, "gte"),
FilterOperator::Lt => write!(f, "lt"),
FilterOperator::Lte => write!(f, "lte"),
FilterOperator::Like => write!(f, "like"),
FilterOperator::IsNull => write!(f, "is"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SortDirection {
Asc,
Desc,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilterExpression {
pub column: String,
pub operator: FilterOperator,
pub value: Option<Value>,
}