notion_sdk/database/
mod.rs

1//!
2//! # Notion DataBase
3//!
4//! ## Examples
5//! ```rust,no_run
6//! use notion_sdk::common::parent::Parent;
7//! use notion_sdk::database::CreateDatabase;
8//! use notion_sdk::database::properties::Properties;
9//! let database = CreateDatabase{
10//!     parent: Parent::Workspace,
11//!     title: vec![],
12//!     properties: Properties { properties: Default::default()},
13//! };
14//! ```
15pub mod properties;
16
17use crate::common::file::FileOrEmojiObject;
18use crate::common::parent::Parent;
19use crate::common::rich_text::RichText;
20use crate::database::id::DatabaseId;
21use crate::database::properties::{Properties, PropertyConfiguration};
22use crate::user::UserCommon;
23use chrono::{DateTime, Utc};
24use serde::{Deserialize, Serialize};
25use std::collections::HashMap;
26
27mod aka;
28mod api;
29pub mod date;
30pub mod files;
31pub mod formula;
32pub mod id;
33pub mod number;
34pub mod relation;
35pub mod rollup;
36pub mod select;
37pub mod status;
38
39#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
40#[serde(rename_all = "lowercase")]
41pub enum Color {
42    Default,
43    Gray,
44    Brown,
45    Orange,
46    Yellow,
47    Green,
48    Blue,
49    Purple,
50    Pink,
51    Red,
52}
53
54/// Represents a Notion Database
55/// See <https://developers.notion.com/reference/database>
56#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
57pub struct Database {
58    /// Unique identifier for the database.
59    pub id: DatabaseId,
60    pub icon: Option<FileOrEmojiObject>,
61    /// Date and time when this database was created.
62    pub created_time: DateTime<Utc>,
63    /// Date and time when this database was updated.
64    pub last_edited_time: DateTime<Utc>,
65    pub created_by: UserCommon,
66    pub last_edited_by: UserCommon,
67    /// Name of the database as it appears in Notion.
68    pub title: Vec<RichText>,
69    /// Schema of properties for the database as they appear in Notion.
70    //
71    // key string
72    // The name of the property as it appears in Notion.
73    //
74    // value object
75    // A Property object.
76    pub properties: HashMap<String, PropertyConfiguration>,
77    /// The archived status of the database.
78    pub archived: bool,
79    pub is_inline: bool,
80    pub description: Vec<RichText>,
81    pub url: String,
82    pub parent: Parent,
83}
84
85#[derive(Serialize, Debug, Eq, PartialEq)]
86pub struct CreateDatabase {
87    pub parent: Parent,
88    pub title: Vec<RichText>,
89    pub properties: Properties,
90}
91
92#[derive(Serialize, Debug, Eq, PartialEq)]
93pub struct UpdateDatabase {
94    pub title: Vec<RichText>,
95    pub properties: Properties,
96}