autopush_common/db/
client.rs1use std::collections::HashSet;
2use std::fmt::Debug;
3
4use async_trait::async_trait;
5use mockall::automock;
6use uuid::Uuid;
7
8use crate::db::error::DbResult;
9use crate::db::User;
10use crate::notification::Notification;
11
12#[derive(Default, Debug)]
13pub struct FetchMessageResponse {
14 pub timestamp: Option<u64>,
15 pub messages: Vec<Notification>,
16}
17
18#[automock] #[async_trait]
24pub trait DbClient: Send + Sync {
25 async fn add_user(&self, user: &User) -> DbResult<()>;
28
29 async fn update_user(&self, user: &mut User) -> DbResult<bool>;
34
35 async fn get_user(&self, uaid: &Uuid) -> DbResult<Option<User>>;
37
38 async fn remove_user(&self, uaid: &Uuid) -> DbResult<()>;
40
41 async fn add_channel(&self, uaid: &Uuid, channel_id: &Uuid) -> DbResult<()>;
43
44 async fn add_channels(&self, uaid: &Uuid, channels: HashSet<Uuid>) -> DbResult<()>;
46
47 async fn get_channels(&self, uaid: &Uuid) -> DbResult<HashSet<Uuid>>;
49
50 async fn remove_channel(&self, uaid: &Uuid, channel_id: &Uuid) -> DbResult<bool>;
52
53 async fn remove_node_id(
57 &self,
58 uaid: &Uuid,
59 node_id: &str,
60 connected_at: u64,
61 version: &Option<Uuid>,
62 ) -> DbResult<bool>;
63
64 async fn save_message(&self, uaid: &Uuid, message: Notification) -> DbResult<()>;
66
67 async fn save_messages(&self, uaid: &Uuid, messages: Vec<Notification>) -> DbResult<()>;
69
70 async fn fetch_topic_messages(
72 &self,
73 uaid: &Uuid,
74 limit: usize,
75 ) -> DbResult<FetchMessageResponse>;
76
77 async fn fetch_timestamp_messages(
79 &self,
80 uaid: &Uuid,
81 timestamp: Option<u64>,
82 limit: usize,
83 ) -> DbResult<FetchMessageResponse>;
84
85 async fn increment_storage(&self, uaid: &Uuid, timestamp: u64) -> DbResult<()>;
87
88 async fn remove_message(&self, uaid: &Uuid, chidmessageid: &str) -> DbResult<()>;
90
91 async fn router_table_exists(&self) -> DbResult<bool>;
93
94 async fn message_table_exists(&self) -> DbResult<bool>;
96
97 async fn health_check(&self) -> DbResult<bool>;
99
100 fn name(&self) -> String;
104
105 fn pool_status(&self) -> Option<deadpool::Status> {
107 None
108 }
109
110 #[cfg(feature = "reliable_report")]
112 async fn log_report(
113 &self,
114 reliability_id: &str,
115 state: crate::reliability::ReliabilityState,
116 ) -> DbResult<()>;
117
118 fn box_clone(&self) -> Box<dyn DbClient>;
119}
120
121impl Clone for Box<dyn DbClient> {
122 fn clone(&self) -> Self {
123 self.box_clone()
124 }
125}