use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Matview {
pub id: Option<String>,
pub query_id: Option<i64>,
pub sql_id: Option<String>,
pub is_private: Option<bool>,
pub table_size_bytes: Option<i64>,
}
#[derive(Debug, Clone, Serialize)]
pub struct UpsertMatviewRequest {
pub name: String,
pub query_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub cron_expression: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expires_at: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_private: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub performance: Option<String>,
}
impl UpsertMatviewRequest {
pub fn new(name: &str, query_id: i64) -> Self {
Self {
name: name.to_string(),
query_id,
cron_expression: None,
expires_at: None,
is_private: None,
performance: None,
}
}
pub fn cron(mut self, cron_expression: &str) -> Self {
self.cron_expression = Some(cron_expression.to_string());
self
}
pub fn private(mut self, is_private: bool) -> Self {
self.is_private = Some(is_private);
self
}
pub fn large(mut self) -> Self {
self.performance = Some("large".to_string());
self
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct UpsertMatviewResponse {
pub name: Option<String>,
pub execution_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct RefreshMatviewRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub performance: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct RefreshMatviewResponse {
pub execution_id: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DeleteMatviewResponse {
pub message: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListMatviewsResponse {
#[serde(default)]
pub materialized_views: Vec<Matview>,
pub next_offset: Option<i64>,
}
#[derive(Debug, Clone, Default)]
pub struct ListMatviewsOptions {
pub limit: Option<u32>,
pub offset: Option<i64>,
}
impl ListMatviewsOptions {
pub fn to_query_string(&self) -> String {
let mut params = Vec::new();
if let Some(limit) = self.limit {
params.push(format!("limit={}", limit));
}
if let Some(offset) = self.offset {
params.push(format!("offset={}", offset));
}
if params.is_empty() {
String::new()
} else {
format!("?{}", params.join("&"))
}
}
}