xmtp_db/encrypted_store/
store.rs1use super::*;
2use derive_builder::Builder;
3
4#[derive(Clone, Debug, Builder)]
6#[builder(setter(into))]
7pub struct EncryptedMessageStore<Db> {
8 pub(super) db: Db,
9}
10
11impl<Db> EncryptedMessageStore<Db> {
12 pub fn builder() -> EncryptedMessageStoreBuilder<Db>
13 where
14 Db: Clone,
15 {
16 Default::default()
17 }
18}
19
20impl<Db: XmtpDb> EncryptedMessageStore<Db> {
21 pub fn new(db: Db) -> Result<Self, StorageError> {
22 db.init()?;
23 Ok(Self { db })
24 }
25
26 pub fn new_uninit(db: Db) -> Result<Self, StorageError> {
27 Ok(Self { db })
28 }
29
30 pub fn opts(&self) -> &StorageOption {
31 self.db.opts()
32 }
33}
34
35impl<Db> EncryptedMessageStore<Db>
36where
37 Db: XmtpDb,
38{
39 pub fn db(&self) -> <Db as XmtpDb>::DbQuery {
41 self.db.db()
42 }
43
44 pub fn conn(&self) -> Db::Connection {
46 self.db.conn()
47 }
48
49 pub fn release_connection(&self) -> Result<(), ConnectionError> {
51 self.db.disconnect()
52 }
53
54 pub fn reconnect(&self) -> Result<(), ConnectionError> {
56 self.db.reconnect()
57 }
58}
59
60impl<Db> XmtpDb for EncryptedMessageStore<Db>
61where
62 Db: XmtpDb,
63{
64 type Connection = Db::Connection;
65 type DbQuery = Db::DbQuery;
66
67 fn conn(&self) -> Self::Connection {
68 self.db.conn()
69 }
70
71 fn db(&self) -> Self::DbQuery {
72 self.db.db()
73 }
74
75 fn validate(&self, conn: &mut SqliteConnection) -> Result<(), ConnectionError> {
76 self.db.validate(conn)
77 }
78
79 fn opts(&self) -> &StorageOption {
80 self.db.opts()
81 }
82
83 fn reconnect(&self) -> Result<(), crate::ConnectionError> {
84 self.db.reconnect()
85 }
86
87 fn disconnect(&self) -> Result<(), crate::ConnectionError> {
88 self.db.disconnect()
89 }
90}