notion_sdk/database/
rollup.rs

1use crate::common::rich_text::RichText;
2use crate::database::date::{DateValue, FormulaResultValue};
3use crate::database::files::FileReference;
4use crate::database::id::PropertyId;
5use crate::database::relation::RelationValue;
6use crate::database::select::SelectedValue;
7use crate::user::User;
8use chrono::{DateTime, Utc};
9use serde::{Deserialize, Serialize};
10use serde_json::Number;
11
12#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
13#[serde(tag = "type", rename_all = "snake_case")]
14pub enum RollupValue {
15    Number { number: Option<Number> },
16    Date { date: Option<DateTime<Utc>> },
17    Array { array: Vec<RollupPropertyValue> },
18}
19/// <https://developers.notion.com/reference/page#rollup-property-value-element>
20#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
21#[serde(tag = "type")]
22#[serde(rename_all = "snake_case")]
23pub enum RollupPropertyValue {
24    /// <https://developers.notion.com/reference/page#rich-text-property-values>
25    #[serde(rename = "rich_text")]
26    Text {
27        rich_text: Vec<RichText>,
28    },
29    /// <https://developers.notion.com/reference/page#number-property-values>
30    Number {
31        number: Option<Number>,
32    },
33    /// <https://developers.notion.com/reference/page#select-property-values>
34    Select {
35        select: Option<SelectedValue>,
36    },
37    Status {
38        status: Option<SelectedValue>,
39    },
40    MultiSelect {
41        multi_select: Option<Vec<SelectedValue>>,
42    },
43    Date {
44        date: Option<DateValue>,
45    },
46    /// <https://developers.notion.com/reference/page#formula-property-values>
47    Formula {
48        formula: FormulaResultValue,
49    },
50    /// <https://developers.notion.com/reference/page#relation-property-values>
51    /// It is actually an array of relations
52    Relation {
53        relation: Option<Vec<RelationValue>>,
54    },
55    /// <https://developers.notion.com/reference/page#rollup-property-values>
56    Rollup {
57        rollup: Option<RollupValue>,
58    },
59    People {
60        people: Vec<User>,
61    },
62    Files {
63        files: Option<Vec<FileReference>>,
64    },
65    Checkbox {
66        checkbox: bool,
67    },
68    Url {
69        url: Option<String>,
70    },
71    Email {
72        email: Option<String>,
73    },
74    PhoneNumber {
75        phone_number: String,
76    },
77    CreatedTime {
78        created_time: DateTime<Utc>,
79    },
80    CreatedBy {
81        created_by: User,
82    },
83    LastEditedTime {
84        last_edited_time: DateTime<Utc>,
85    },
86    LastEditedBy {
87        last_edited_by: User,
88    },
89}
90
91#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
92pub struct Rollup {
93    /// The name of the relation property this property is responsible for rolling up.
94    pub relation_property_name: String,
95    /// The id of the relation property this property is responsible for rolling up.
96    pub relation_property_id: PropertyId,
97    /// The name of the property of the pages in the related database
98    /// that is used as an input to `function`.
99    pub rollup_property_name: String,
100    /// The id of the property of the pages in the related database
101    /// that is used as an input to `function`.
102    pub rollup_property_id: String,
103    /// The function that is evaluated for every page in the relation of the rollup.
104    pub function: RollupFunction,
105}
106
107/// The function used to roll up the values of the relation property.
108/// <https://developers.notion.com/reference/page-property-values#rollup>
109#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
110#[serde(rename_all = "snake_case")]
111pub enum RollupFunction {
112    Average,
113    Checked,
114    Count,
115    CountPerGroup,
116    CountValues,
117    DateRange,
118    EarliestDate,
119    Empty,
120    LatestDate,
121    Max,
122    Median,
123    Min,
124    NotEmpty,
125    PercentChecked,
126    PercentEmpty,
127    PercentNotEmpty,
128    PercentPerGroup,
129    PercentUnchecked,
130    Range,
131    ShowOriginal,
132    ShowUnique,
133    Sum,
134    Unchecked,
135    Unique,
136}