notion_tools/structs/
database.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
//! Database struct and its dependencies.
//!
//! This module defines the `Database` struct and its associated sub-structs used for representing
//! and manipulating database objects in the application. The primary struct, `Database`, contains
//! various fields that describe the properties and metadata of a database, such as its ID, creation
//! time, last edited time, URL, and more. Additionally, it includes nested structs to represent
//! specific property types within the database, such as `FormulaExpression`, `MultiSelectObject`,
//! `NumberFormat`, `RelationObject`, `RollupObject`, `SelectObject`, and `StatusObject`.
//!
//! Each sub-struct is equipped with serialization and deserialization capabilities using Serde,
//! and provides methods to check if the struct is empty. The `DatabaseProperty` struct is used to
//! define the properties of a database, with various fields representing different property types
//! and their corresponding data.
//!
use crate::structs::common::*;
use fxhash::FxHashMap;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct FormulaExpression {
    #[serde(default = "String::new")]
    pub expression: String,
}

impl FormulaExpression {
    pub fn is_empty(&self) -> bool {
        self.expression.is_empty()
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct MultiSelectObject {
    #[serde(default = "Vec::default")]
    pub options: Vec<SelectOption>,
}

impl MultiSelectObject {
    pub fn is_empty(&self) -> bool {
        self.options.is_empty()
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct NumberFormat {
    #[serde(default = "String::new")]
    pub format: String,
}

impl NumberFormat {
    pub fn is_empty(&self) -> bool {
        self.format.is_empty()
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct RelationObject {
    #[serde(default = "String::new")]
    pub database_id: String,
    #[serde(default = "String::new")]
    pub synced_property_id: String,
    #[serde(default = "String::new")]
    pub synced_property_name: String,
}

impl RelationObject {
    pub fn is_empty(&self) -> bool {
        self.database_id.is_empty()
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct RollupObject {
    #[serde(default = "String::new")]
    pub rollup_property_id: String,
    #[serde(default = "String::new")]
    pub rollup_property_name: String,
    #[serde(default = "String::new")]
    pub relation_property_id: String,
    #[serde(default = "String::new")]
    pub relation_property_name: String,
    #[serde(default = "String::new")]
    pub function: String,
}

impl RollupObject {
    pub fn is_empty(&self) -> bool {
        self.rollup_property_id.is_empty()
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SelectObject {
    #[serde(default = "Vec::default")]
    pub options: Vec<SelectOption>,
}

impl SelectObject {
    pub fn is_empty(&self) -> bool {
        self.options.is_empty()
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct StatusObject {
    #[serde(default = "Vec::default")]
    pub options: Vec<SelectOption>,
}

impl StatusObject {
    pub fn is_empty(&self) -> bool {
        self.options.is_empty()
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DatabaseProperty {
    #[serde(default = "String::new")]
    pub id: String,
    #[serde(default = "String::new")]
    pub name: String,
    #[serde(rename = "type", default = "String::new")]
    pub type_name: String,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub checkbox: FxHashMap<String, String>,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub created_by: FxHashMap<String, String>,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub created_time: FxHashMap<String, String>,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub date: FxHashMap<String, String>,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub email: FxHashMap<String, String>,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub files: FxHashMap<String, String>,
    #[serde(
        default = "FormulaExpression::default",
        skip_serializing_if = "FormulaExpression::is_empty"
    )]
    pub formula: FormulaExpression,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub last_edited_by: FxHashMap<String, String>,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub last_edited_time: FxHashMap<String, String>,
    #[serde(
        default = "MultiSelectObject::default",
        skip_serializing_if = "MultiSelectObject::is_empty"
    )]
    pub multi_select: MultiSelectObject,
    #[serde(
        default = "NumberFormat::default",
        skip_serializing_if = "NumberFormat::is_empty"
    )]
    pub number: NumberFormat,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub people: FxHashMap<String, String>,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub phone_number: FxHashMap<String, String>,
    #[serde(
        default = "RelationObject::default",
        skip_serializing_if = "RelationObject::is_empty"
    )]
    pub relation: RelationObject,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub rich_text: FxHashMap<String, String>,
    #[serde(
        default = "RollupObject::default",
        skip_serializing_if = "RollupObject::is_empty"
    )]
    pub rollup: RollupObject,
    #[serde(
        default = "SelectObject::default",
        skip_serializing_if = "SelectObject::is_empty"
    )]
    pub select: SelectObject,
    #[serde(
        default = "StatusObject::default",
        skip_serializing_if = "StatusObject::is_empty"
    )]
    pub status: StatusObject,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub title: FxHashMap<String, String>,
    #[serde(
        default = "FxHashMap::default",
        skip_serializing_if = "FxHashMap::is_empty"
    )]
    pub url: FxHashMap<String, String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Database {
    #[serde(default = "String::new")]
    pub object: String,
    #[serde(default = "u32::default", skip_serializing)]
    pub status: u32,
    #[serde(default = "String::new", skip_serializing)]
    pub code: String,
    #[serde(default = "String::new", skip_serializing)]
    pub message: String,
    #[serde(default = "String::new", skip_serializing)]
    pub request_id: String,
    #[serde(default = "String::new")]
    pub id: String,
    #[serde(default = "String::new")]
    pub created_time: String,
    #[serde(default = "String::new")]
    pub last_edited_time: String,
    #[serde(default = "User::default")]
    pub created_by: User,
    #[serde(default = "User::default")]
    pub last_edited_by: User,
    #[serde(default = "String::new")]
    pub url: String,
    #[serde(default = "bool::default")]
    pub archived: bool,
    #[serde(default = "bool::default")]
    pub is_inline: bool,
    #[serde(default = "Option::default")]
    pub public_url: Option<String>,
    #[serde(default = "Vec::default")]
    pub title: Vec<RichText>,
    #[serde(default = "Vec::default")]
    pub description: Vec<RichText>,
    #[serde(default = "FxHashMap::default")]
    pub properties: FxHashMap<String, DatabaseProperty>,
}