sqlite_rwc/
sync_adapter.rs1use crate::drivers::Driver;
2use crate::pool::{ConnectionAdapter, ConnectionPool, PooledConnection};
3use std::ops::Deref;
4
5pub type SyncConnectionPool<T> = ConnectionPool<T, SyncConnectionAdapter<T>>;
6
7pub struct SyncConnectionAdapter<T: Driver>(T::Connection);
9
10impl<T: Driver> SyncConnectionAdapter<T> {
11 fn read<F, R, E>(&mut self, closure: F) -> Result<R, E>
12 where
13 F: FnOnce(T::ConnectionRef<'_>) -> Result<R, E>,
14 E: From<T::Error>,
15 {
16 T::read(&mut self.0, closure)
17 }
18}
19
20impl<T: Driver> ConnectionAdapter<T> for SyncConnectionAdapter<T> {
21 fn from_driver_connection(connection: T::Connection) -> Self {
22 Self(connection)
23 }
24}
25
26impl<T: Driver> PooledConnection<T, SyncConnectionAdapter<T>> {
27 pub fn scoped_read<F, R, E>(&mut self, closure: F) -> Result<R, E>
40 where
41 F: FnOnce(T::ConnectionRef<'_>) -> Result<R, E>,
42 E: From<T::Error>,
43 {
44 let conn = self.connection_mut();
45 conn.read(closure)
46 }
47
48 pub fn read<F, R, E>(&mut self, closure: F) -> Result<R, E>
57 where
58 F: FnOnce(&T::Connection) -> Result<R, E>,
59 E: From<T::Error>,
60 {
61 let conn = self.connection_mut();
62 closure(&conn.0)
63 }
64
65 pub fn transaction<F, R, E>(&mut self, closure: F) -> Result<R, E>
73 where
74 F: FnOnce(&mut T::Transaction<'_>) -> Result<R, E>,
75 E: From<T::Error>,
76 {
77 self.pool.transaction(closure)
78 }
79}
80
81impl<T: Driver> Deref for PooledConnection<T, SyncConnectionAdapter<T>> {
82 type Target = T::Connection;
83
84 fn deref(&self) -> &Self::Target {
85 &self.connection().0
86 }
87}