dune_api/matviews/
types.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Deserialize, Serialize)]
7pub struct Matview {
8 pub id: Option<String>,
10 pub query_id: Option<i64>,
12 pub sql_id: Option<String>,
14 pub is_private: Option<bool>,
16 pub table_size_bytes: Option<i64>,
18}
19
20#[derive(Debug, Clone, Serialize)]
22pub struct UpsertMatviewRequest {
23 pub name: String,
25 pub query_id: i64,
27 #[serde(skip_serializing_if = "Option::is_none")]
29 pub cron_expression: Option<String>,
30 #[serde(skip_serializing_if = "Option::is_none")]
32 pub expires_at: Option<String>,
33 #[serde(skip_serializing_if = "Option::is_none")]
35 pub is_private: Option<bool>,
36 #[serde(skip_serializing_if = "Option::is_none")]
38 pub performance: Option<String>,
39}
40
41impl UpsertMatviewRequest {
42 pub fn new(name: &str, query_id: i64) -> Self {
44 Self {
45 name: name.to_string(),
46 query_id,
47 cron_expression: None,
48 expires_at: None,
49 is_private: None,
50 performance: None,
51 }
52 }
53
54 pub fn cron(mut self, cron_expression: &str) -> Self {
56 self.cron_expression = Some(cron_expression.to_string());
57 self
58 }
59
60 pub fn private(mut self, is_private: bool) -> Self {
62 self.is_private = Some(is_private);
63 self
64 }
65
66 pub fn large(mut self) -> Self {
68 self.performance = Some("large".to_string());
69 self
70 }
71}
72
73#[derive(Debug, Clone, Deserialize, Serialize)]
75pub struct UpsertMatviewResponse {
76 pub name: Option<String>,
78 pub execution_id: Option<String>,
80}
81
82#[derive(Debug, Clone, Serialize, Default)]
84pub struct RefreshMatviewRequest {
85 #[serde(skip_serializing_if = "Option::is_none")]
87 pub performance: Option<String>,
88}
89
90#[derive(Debug, Clone, Deserialize, Serialize)]
92pub struct RefreshMatviewResponse {
93 pub execution_id: Option<String>,
95}
96
97#[derive(Debug, Clone, Deserialize, Serialize)]
99pub struct DeleteMatviewResponse {
100 pub message: Option<String>,
102}
103
104#[derive(Debug, Clone, Deserialize, Serialize)]
106pub struct ListMatviewsResponse {
107 #[serde(default)]
109 pub materialized_views: Vec<Matview>,
110 pub next_offset: Option<i64>,
112}
113
114#[derive(Debug, Clone, Default)]
116pub struct ListMatviewsOptions {
117 pub limit: Option<u32>,
119 pub offset: Option<i64>,
121}
122
123impl ListMatviewsOptions {
124 pub fn to_query_string(&self) -> String {
125 let mut params = Vec::new();
126 if let Some(limit) = self.limit {
127 params.push(format!("limit={}", limit));
128 }
129 if let Some(offset) = self.offset {
130 params.push(format!("offset={}", offset));
131 }
132 if params.is_empty() {
133 String::new()
134 } else {
135 format!("?{}", params.join("&"))
136 }
137 }
138}