xmtp_db/encrypted_store/
pragmas.rs1use crate::{ConnectionExt, DbConnection};
4use diesel::prelude::*;
5
6#[derive(QueryableByName, Debug)]
7struct BusyTimeout {
8 #[diesel(sql_type = diesel::sql_types::Integer)]
9 timeout: i32,
10}
11
12pub trait Pragmas {
13 fn busy_timeout(&self) -> Result<i32, crate::ConnectionError>;
15 fn set_sqlcipher_log<S: AsRef<str>>(&self, level: S) -> Result<(), crate::ConnectionError>;
16}
17
18impl<T> Pragmas for &T
19where
20 T: Pragmas,
21{
22 fn busy_timeout(&self) -> Result<i32, crate::ConnectionError> {
24 (**self).busy_timeout()
25 }
26
27 fn set_sqlcipher_log<S: AsRef<str>>(&self, level: S) -> Result<(), crate::ConnectionError> {
28 (**self).set_sqlcipher_log(level)
29 }
30}
31
32impl<C: ConnectionExt> Pragmas for DbConnection<C> {
33 fn busy_timeout(&self) -> Result<i32, crate::ConnectionError> {
34 self.raw_query_read(|conn| {
35 let BusyTimeout { timeout } =
36 diesel::sql_query("PRAGMA busy_timeout").get_result::<BusyTimeout>(conn)?;
37 Ok(timeout)
38 })
39 }
40
41 fn set_sqlcipher_log<S: AsRef<str>>(&self, level: S) -> Result<(), crate::ConnectionError> {
42 let level = level.as_ref();
43 self.raw_query_read(|conn| {
44 diesel::sql_query(format!("PRAGMA cipher_log_level = {level}")).execute(conn)?;
45 Ok(())
46 })
47 }
48}