1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct Note {
6 pub id: String,
8 #[serde(skip)]
10 pub pk: i64,
11 pub title: String,
13 pub text: String,
15 pub tags: Vec<String>,
17 pub created: i64,
19 pub modified: i64,
21 pub trashed: bool,
22 pub archived: bool,
23 pub pinned: bool,
24 pub locked: bool,
25 pub encrypted: bool,
26 pub has_images: bool,
27 pub has_files: bool,
28 pub has_source_code: bool,
29 pub todo_completed: i64,
30 pub todo_incompleted: i64,
31 pub attachments: Vec<Attachment>,
33 pub pinned_in_tags: Vec<String>,
36}
37
38impl Note {
39 pub fn hash(&self) -> String {
41 use sha2::{Digest, Sha256};
42 let digest = Sha256::digest(self.text.as_bytes());
43 format!("{digest:x}")
44 }
45
46 pub fn length(&self) -> i64 {
48 self.text.len() as i64
49 }
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct Tag {
55 pub name: String,
57 #[serde(skip)]
59 pub pk: i64,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct Attachment {
65 pub filename: String,
67 pub size: i64,
69 pub uuid: String,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct PinRecord {
76 pub note_id: String,
78 pub pin: String,
80}
81
82#[derive(Debug, Clone, Copy, PartialEq, Eq)]
84pub enum InsertPosition {
85 Beginning,
86 End,
87}
88
89#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
91pub enum TagPosition {
92 Top,
93 #[default]
94 Bottom,
95}
96
97#[derive(Debug, Clone, Copy, PartialEq, Eq)]
99pub enum SortField {
100 Pinned,
101 Modified,
102 Created,
103 Title,
104}
105
106impl SortField {
107 pub fn sql_column(&self) -> &'static str {
108 match self {
109 SortField::Pinned => "n.ZPINNED",
110 SortField::Modified => "n.ZMODIFICATIONDATE",
111 SortField::Created => "n.ZCREATIONDATE",
112 SortField::Title => "n.ZTITLE",
113 }
114 }
115}
116
117#[derive(Debug, Clone, Copy, PartialEq, Eq)]
119pub enum SortDir {
120 Asc,
121 Desc,
122}