sqlite_rwc/
drivers.rs

1use std::fmt::Debug;
2use std::path::Path;
3
4#[cfg(feature = "rusqlite")]
5pub mod rusqlite;
6
7#[cfg(feature = "diesel")]
8pub mod diesel;
9
10/// Implementation interface for any library which provides binding for sqlite.
11pub trait Driver: 'static + Send + Sync + Debug {
12    #[cfg(feature = "watcher")]
13    type Connection: sqlite_watcher::connection::SqlExecutorMut<Error = Self::Error>;
14    #[cfg(not(feature = "watcher"))]
15    type Connection;
16    type Error: std::error::Error;
17    type ConnectionError: std::error::Error;
18
19    /// Represents the reference to a connection type. Some drivers my specify this as
20    /// immutable or mutable reference.
21    type ConnectionRef<'c>;
22
23    /// Create  new read-only connection with the given `path`.
24    ///
25    /// This method should not creat the db file if it does not exist.
26    ///
27    /// # Errors
28    ///
29    /// Should return error if the connection could not be created.
30    fn new_read_connection(path: &Path) -> Result<Self::Connection, Self::ConnectionError>;
31
32    /// Create a new writable connection with the given `path`.
33    ///
34    /// This method should create the database file if it does not exist.
35    ///
36    /// # Errors
37    ///
38    /// Should return error if the connection could not be created.
39    fn new_write_connection(path: &Path) -> Result<Self::Connection, Self::ConnectionError>;
40
41    /// Start a transaction with the given `sql` command.
42    ///
43    /// # Errors
44    ///
45    /// Return error if the transaction could not be started.
46    fn begin_transaction(connection: &mut Self::Connection, sql: &str) -> Result<(), Self::Error>;
47
48    /// Commit the transaction.
49    ///
50    /// # Errors
51    ///
52    /// Return error if the transaction could not be commited.
53    fn commit_transaction(connection: &mut Self::Connection) -> Result<(), Self::Error>;
54
55    /// Rollback the transaction.
56    ///
57    /// # Errors
58    ///
59    /// Return error if the transaction could not be rolled back.
60    fn rollback_transaction(connection: &mut Self::Connection) -> Result<(), Self::Error>;
61}
62
63/// Marker trait to signal whether the driver allows mutable connection deref from
64/// the [`Transaction`](crate::pool::Transaction) type.
65pub trait DriverMutConnectionDeref: Driver {}