Your one-stop-cake-shop for everything Freshly Baked has to offer

fix: db

+2 -2
sprinkles/migrations/20250701052622_initial.up.sql
··· 12 CREATE TABLE notifications ( 13 id INTEGER PRIMARY KEY AUTOINCREMENT, 14 dbus_notification_id STRING REFERENCES dbus_notifications (id), 15 - closed BOOLEAN NOT NULL DEFAULT FALSE 16 ); 17 18 CREATE TABLE notification_actions ( 19 id STRING PRIMARY KEY, 20 - dbus_notification_id INTEGER REFERENCES notifications (id), 21 action TEXT NOT NULL 22 ); 23
··· 12 CREATE TABLE notifications ( 13 id INTEGER PRIMARY KEY AUTOINCREMENT, 14 dbus_notification_id STRING REFERENCES dbus_notifications (id), 15 + read BOOLEAN NOT NULL DEFAULT FALSE 16 ); 17 18 CREATE TABLE notification_actions ( 19 id STRING PRIMARY KEY, 20 + dbus_notification_id INTEGER REFERENCES dbus_notifications (id), 21 action TEXT NOT NULL 22 ); 23
+69
sprinkles/src/db/get_parsed_notification.sql
···
··· 1 + WITH nid AS ( 2 + SELECT id, dbus_notification_id, closed 3 + FROM notifications 4 + WHERE id = ? 5 + ), 6 + current AS ( 7 + SELECT c.*, c.id AS raw_id 8 + FROM dbus_notifications c 9 + JOIN nid ON c.id = nid.dbus_notification_id 10 + ), 11 + actions AS ( 12 + SELECT action 13 + FROM notification_actions 14 + WHERE dbus_notification_id = (SELECT dbus_notification_id FROM nid) 15 + ORDER BY action 16 + ), 17 + hints AS ( 18 + SELECT k, value 19 + FROM notification_hints 20 + WHERE dbus_notification_id = (SELECT dbus_notification_id FROM nid) 21 + ), 22 + history AS ( 23 + SELECT 24 + h.*, 25 + p.idx, 26 + ( 27 + SELECT json_group_array(action ORDER BY action) 28 + FROM notification_actions na 29 + WHERE na.dbus_notification_id = h.id 30 + ) AS actions, 31 + ( 32 + SELECT json_group_object(k, value) 33 + FROM notification_hints nh 34 + WHERE nh.dbus_notification_id = h.id 35 + ) AS hints 36 + FROM previous_dbus_notifications p 37 + JOIN dbus_notifications h ON h.id = p.dbus_notification_id 38 + WHERE p.notification_id = (SELECT id FROM nid) 39 + ORDER BY p.idx ASC 40 + ) 41 + SELECT 42 + (SELECT id FROM nid) AS id, 43 + (SELECT closed FROM nid) AS closed, 44 + (SELECT CAST(json_object( 45 + 'id', lower(substr(hex(current.id),1,8)||'-'||substr(hex(current.id),9,4)||'-'||substr(hex(current.id),13,4)||'-'||substr(hex(current.id),17,4)||'-'||substr(hex(current.id),21)), 46 + 'app_name', current.app_name, 47 + 'replaces_id', COALESCE(current.replaces_id, 0), 48 + 'app_icon', current.app_icon, 49 + 'summary', current.summary, 50 + 'body', current.body, 51 + 'expire_timeout',current.expire_timeout, 52 + 'actions', (SELECT json_group_array(action) FROM actions), 53 + 'hints', (SELECT json_group_object(k,value) FROM hints) 54 + ) AS TEXT) FROM current) AS dbus_notification, 55 + (SELECT CAST(json_group_array( 56 + json_object( 57 + 'id', lower(substr(hex(history.id),1,8)||'-'||substr(hex(history.id),9,4)||'-'||substr(hex(history.id),13,4)||'-'||substr(hex(history.id),17,4)||'-'||substr(hex(history.id),21)), 58 + 'app_name', history.app_name, 59 + 'replaces_id', COALESCE(history.replaces_id, 0), 60 + 'app_icon', history.app_icon, 61 + 'summary', history.summary, 62 + 'body', history.body, 63 + 'expire_timeout',history.expire_timeout, 64 + 'actions', history.actions, 65 + 'hints', history.hints 66 + ) 67 + ORDER BY idx 68 + ) AS TEXT) FROM history) AS history 69 + ;
+1 -1
sprinkles/src/db/intermediates.rs
··· 47 pub struct ParsedNotification { 48 pub id: u32, 49 pub dbus_notification: ParsedDBusNotification, 50 - pub closed: bool, 51 pub history: Vec<ParsedDBusNotification>, 52 }
··· 47 pub struct ParsedNotification { 48 pub id: u32, 49 pub dbus_notification: ParsedDBusNotification, 50 + pub read: bool, 51 pub history: Vec<ParsedDBusNotification>, 52 }
+7 -79
sprinkles/src/db/mod.rs
··· 44 &mut self, 45 notification_id: u32, 46 ) -> Result<ParsedNotification, sqlx::Error> { 47 - let row = sqlx::query( 48 - r#" 49 - WITH nid AS ( 50 - SELECT id, dbus_notification_id, closed 51 - FROM notifications 52 - WHERE id = ? 53 - ), 54 - current AS ( 55 - SELECT c.*, c.id AS raw_id 56 - FROM dbus_notifications c 57 - JOIN nid ON c.id = nid.dbus_notification_id 58 - ), 59 - actions AS ( 60 - SELECT action 61 - FROM notification_actions 62 - WHERE dbus_notification_id = (SELECT dbus_notification_id FROM nid) 63 - ORDER BY action 64 - ), 65 - hints AS ( 66 - SELECT k, value 67 - FROM notification_hints 68 - WHERE dbus_notification_id = (SELECT dbus_notification_id FROM nid) 69 - ), 70 - history AS ( 71 - SELECT 72 - h.*, 73 - p.idx, 74 - ( 75 - SELECT json_group_array(action ORDER BY action) 76 - FROM notification_actions na 77 - WHERE na.dbus_notification_id = h.id 78 - ) AS actions, 79 - ( 80 - SELECT json_group_object(k, value) 81 - FROM notification_hints nh 82 - WHERE nh.dbus_notification_id = h.id 83 - ) AS hints 84 - FROM previous_dbus_notifications p 85 - JOIN dbus_notifications h ON h.id = p.dbus_notification_id 86 - WHERE p.notification_id = (SELECT id FROM nid) 87 - ORDER BY p.idx ASC 88 - ) 89 - SELECT 90 - (SELECT id FROM nid) AS id, 91 - (SELECT closed FROM nid) AS closed, 92 - (SELECT CAST(json_object( 93 - 'id', lower(substr(hex(current.id),1,8)||'-'||substr(hex(current.id),9,4)||'-'||substr(hex(current.id),13,4)||'-'||substr(hex(current.id),17,4)||'-'||substr(hex(current.id),21)), 94 - 'app_name', current.app_name, 95 - 'replaces_id', COALESCE(current.replaces_id, 0), 96 - 'app_icon', current.app_icon, 97 - 'summary', current.summary, 98 - 'body', current.body, 99 - 'expire_timeout',current.expire_timeout, 100 - 'actions', (SELECT json_group_array(action) FROM actions), 101 - 'hints', (SELECT json_group_object(k,value) FROM hints) 102 - ) AS TEXT) FROM current) AS dbus_notification, 103 - (SELECT CAST(json_group_array( 104 - json_object( 105 - 'id', lower(substr(hex(history.id),1,8)||'-'||substr(hex(history.id),9,4)||'-'||substr(hex(history.id),13,4)||'-'||substr(hex(history.id),17,4)||'-'||substr(hex(history.id),21)), 106 - 'app_name', history.app_name, 107 - 'replaces_id', COALESCE(history.replaces_id, 0), 108 - 'app_icon', history.app_icon, 109 - 'summary', history.summary, 110 - 'body', history.body, 111 - 'expire_timeout',history.expire_timeout, 112 - 'actions', history.actions, 113 - 'hints', history.hints 114 - ) 115 - ORDER BY idx 116 - ) AS TEXT) FROM history) AS history 117 - ; 118 - "#, 119 - ) 120 - .bind(notification_id) 121 - .fetch_one(&mut self.connection) 122 - .await?; 123 124 let id = row.get("id"); 125 - let closed = row.get("closed"); 126 let dbus_json_bytes: Vec<u8> = row.get("dbus_notification"); 127 let history_json_bytes: Vec<u8> = row.get("history"); 128 ··· 133 134 Ok(ParsedNotification { 135 id, 136 - closed, 137 dbus_notification: serde_json::from_str(&dbus_json) 138 .map_err(|e| sqlx::Error::Decode(Box::new(e)))?, 139 history: serde_json::from_str(&history_json) ··· 299 } 300 301 pub async fn close_notification(&mut self, notification_id: u32) { 302 - sqlx::query("UPDATE notifications SET closed = true WHERE id = ?") 303 .bind(notification_id) 304 .execute(&mut self.connection) 305 .await
··· 44 &mut self, 45 notification_id: u32, 46 ) -> Result<ParsedNotification, sqlx::Error> { 47 + let row = sqlx::query(include_str!("get_parsed_notification.sql")) 48 + .bind(notification_id) 49 + .fetch_one(&mut self.connection) 50 + .await?; 51 52 let id = row.get("id"); 53 + let read = row.get("read"); 54 let dbus_json_bytes: Vec<u8> = row.get("dbus_notification"); 55 let history_json_bytes: Vec<u8> = row.get("history"); 56 ··· 61 62 Ok(ParsedNotification { 63 id, 64 + read, 65 dbus_notification: serde_json::from_str(&dbus_json) 66 .map_err(|e| sqlx::Error::Decode(Box::new(e)))?, 67 history: serde_json::from_str(&history_json) ··· 227 } 228 229 pub async fn close_notification(&mut self, notification_id: u32) { 230 + sqlx::query("UPDATE notifications SET read = true WHERE id = ?") 231 .bind(notification_id) 232 .execute(&mut self.connection) 233 .await
+1 -1
sprinkles/src/db/parser.rs
··· 325 #[test] 326 fn basic_and() { 327 let (sql, params) = parse_query("{urgent = 1} & unread()").unwrap(); 328 - assert_eq!(sql, "(urgent = ? AND closed = 0)"); 329 assert_eq!(params, vec!["1"]); 330 } 331
··· 325 #[test] 326 fn basic_and() { 327 let (sql, params) = parse_query("{urgent = 1} & unread()").unwrap(); 328 + assert_eq!(sql, "(EXISTS ( SELECT 1 FROM dbus_notifications d WHERE d.id = dbus_notification_id AND d.urgent = ? ) AND closed = 0)"); 329 assert_eq!(params, vec!["1"]); 330 } 331
+1 -1
sprinkles/src/db/tables.rs
··· 17 pub struct Notification { 18 pub id: u32, 19 pub dbus_notification_id: Uuid, 20 - pub closed: bool, 21 } 22 23 #[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
··· 17 pub struct Notification { 18 pub id: u32, 19 pub dbus_notification_id: Uuid, 20 + pub read: bool, 21 } 22 23 #[derive(Debug, Clone, Serialize, Deserialize, FromRow)]