notion_client/objects/
database.rs

1use std::collections::HashMap;
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use serde_with::skip_serializing_none;
6
7use super::{emoji::Emoji, file::File, parent::Parent, rich_text::RichText, user::User};
8
9#[skip_serializing_none]
10#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
11pub struct Database {
12    pub id: Option<String>,
13    pub created_time: DateTime<Utc>,
14    pub created_by: Option<User>,
15    pub last_edited_time: DateTime<Utc>,
16    pub last_edited_by: Option<User>,
17    pub title: Vec<RichText>,
18    pub description: Vec<RichText>,
19    pub icon: Option<Icon>,
20    pub cover: Option<File>,
21    pub properties: HashMap<String, DatabaseProperty>,
22    pub parent: Parent,
23    pub url: String,
24    pub archived: bool,
25    pub is_inline: bool,
26    pub public_url: Option<bool>,
27}
28
29#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
30#[serde(tag = "type", rename_all = "snake_case")]
31pub enum Icon {
32    #[default]
33    None,
34    File(File),
35    Emoji(Emoji),
36}
37
38#[skip_serializing_none]
39#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
40#[serde(tag = "type", rename_all = "snake_case")]
41pub enum DatabaseProperty {
42    Checkbox {
43        id: Option<String>,
44        name: Option<String>,
45        checkbox: HashMap<(), ()>,
46    },
47    CreatedBy {
48        id: Option<String>,
49        name: Option<String>,
50        created_by: HashMap<(), ()>,
51    },
52    CreatedTime {
53        id: Option<String>,
54        name: Option<String>,
55        created_time: HashMap<(), ()>,
56    },
57    Date {
58        id: Option<String>,
59        name: Option<String>,
60        date: HashMap<(), ()>,
61    },
62    Email {
63        id: Option<String>,
64        name: Option<String>,
65        email: HashMap<(), ()>,
66    },
67    Files {
68        id: Option<String>,
69        name: Option<String>,
70        files: HashMap<(), ()>,
71    },
72    Formula {
73        id: Option<String>,
74        name: Option<String>,
75        formula: FormulaPropertyValue,
76    },
77    LastEditedBy {
78        id: Option<String>,
79        name: Option<String>,
80        last_edited_by: HashMap<(), ()>,
81    },
82    LastEditedTime {
83        id: Option<String>,
84        name: Option<String>,
85        last_edited_time: HashMap<(), ()>,
86    },
87    MultiSelect {
88        id: Option<String>,
89        name: Option<String>,
90        multi_select: SelectPropertyValue,
91    },
92    Number {
93        id: Option<String>,
94        name: Option<String>,
95        number: NumberPropertyValue,
96    },
97    People {
98        id: Option<String>,
99        name: Option<String>,
100        people: HashMap<(), ()>,
101    },
102    PhoneNumber {
103        id: Option<String>,
104        name: Option<String>,
105        phone_number: HashMap<(), ()>,
106    },
107    Relation {
108        id: Option<String>,
109        name: Option<String>,
110        relation: RelationPropertyValue,
111    },
112    RichText {
113        id: Option<String>,
114        name: Option<String>,
115        rich_text: HashMap<(), ()>,
116    },
117    Rollup {
118        id: Option<String>,
119        name: Option<String>,
120        rollup: RollupPropertyValue,
121    },
122    Select {
123        id: Option<String>,
124        name: Option<String>,
125        select: SelectPropertyValue,
126    },
127    Status {
128        id: Option<String>,
129        name: Option<String>,
130        status: StatusPropertyValue,
131    },
132    Title {
133        id: Option<String>,
134        name: Option<String>,
135        title: HashMap<(), ()>,
136    },
137    Url {
138        id: Option<String>,
139        name: Option<String>,
140        url: HashMap<(), ()>,
141    },
142}
143
144#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
145#[serde(rename_all = "snake_case")]
146pub enum Color {
147    #[default]
148    Blue,
149    Brown,
150    Default,
151    Gray,
152    Green,
153    Orange,
154    Pink,
155    Purple,
156    Red,
157    Yellow,
158}
159
160#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
161pub struct FormulaPropertyValue {
162    pub expression: String,
163}
164
165#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
166pub struct NumberPropertyValue {
167    pub format: NumberFormat,
168}
169
170#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
171#[serde(rename_all = "snake_case")]
172pub enum NumberFormat {
173    ArgentinePeso,
174    Baht,
175    AustralianDollar,
176    CanadianDollar,
177    ChileanPeso,
178    ColombianPeso,
179    DanishKrone,
180    Dirham,
181    Dollar,
182    Euro,
183    Forint,
184    Franc,
185    HongKongDollar,
186    Koruna,
187    Krona,
188    Leu,
189    Lira,
190    MexicanPeso,
191    NewTaiwanDollar,
192    NewZealandDollar,
193    NorwegianKrone,
194    Number,
195    NumberWithCommas,
196    Percent,
197    PhilippinePeso,
198    Pound,
199    PeruvianSol,
200    Rand,
201    Real,
202    Ringgit,
203    Riyal,
204    Ruble,
205    Rupee,
206    Rupiah,
207    Shekel,
208    SingaporeDollar,
209    UruguayanPeso,
210    Yen,
211    Yuan,
212    Won,
213    Zloty,
214}
215
216#[skip_serializing_none]
217#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
218pub struct RelationPropertyValue {
219    pub database_id: Option<String>,
220    pub synced_property_id: Option<String>,
221    pub synced_property_name: Option<String>,
222}
223
224#[skip_serializing_none]
225#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
226pub struct RollupPropertyValue {
227    pub rollup_property_name: String,
228    pub relation_property_name: String,
229    pub function: RollupFunction,
230    pub relation_property_id: Option<String>,
231    pub rollup_property_id: Option<String>,
232}
233
234#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
235#[serde(rename_all = "snake_case")]
236pub enum RollupFunction {
237    #[default]
238    Average,
239    Checked,
240    CountPerGroup,
241    Count,
242    CountValues,
243    DateRange,
244    EarliestDate,
245    Empty,
246    LatestDate,
247    Max,
248    Median,
249    Min,
250    NotEmpty,
251    PercentChecked,
252    PercentEmpty,
253    PercentNotEmpty,
254    PercentPerGroup,
255    PercentUnchecked,
256    Range,
257    Unchecked,
258    Unique,
259    ShowOriginal,
260    ShowUnique,
261    Sum,
262}
263
264#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
265pub struct StatusPropertyValue {
266    pub options: Vec<SelectPropertyValue>,
267    pub groups: Vec<Group>,
268}
269
270#[skip_serializing_none]
271#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
272pub struct Group {
273    pub color: Color,
274    pub id: Option<String>,
275    pub name: String,
276    pub option_ids: Vec<String>,
277}
278
279#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
280pub struct SelectPropertyValue {
281    pub options: Vec<OptionValue>,
282}
283
284#[skip_serializing_none]
285#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
286pub struct OptionValue {
287    pub name: String,
288    pub color: Option<Color>,
289    pub id: Option<String>,
290}