sqlite-rwc 0.4.0

Reader Writer Concurrency Setup for Sqlite3
Documentation
use std::fmt::Debug;
use std::path::Path;

#[cfg(feature = "rusqlite")]
pub mod rusqlite;

#[cfg(feature = "diesel")]
pub mod diesel;

/// Implementation interface for any library which provides binding for sqlite.
pub trait Driver: 'static + Send + Sync + Debug {
    #[cfg(feature = "watcher")]
    type Connection: sqlite_watcher::connection::SqlExecutorMut<Error = Self::Error>;
    #[cfg(not(feature = "watcher"))]
    type Connection;
    type Error: std::error::Error;
    type ConnectionError: std::error::Error;

    /// Represents the reference to a connection type. Some drivers my specify this as
    /// immutable or mutable reference.
    type ConnectionRef<'c>;

    /// Create  new read-only connection with the given `path`.
    ///
    /// This method should not creat the db file if it does not exist.
    ///
    /// # Errors
    ///
    /// Should return error if the connection could not be created.
    fn new_read_connection(path: &Path) -> Result<Self::Connection, Self::ConnectionError>;

    /// Create a new writable connection with the given `path`.
    ///
    /// This method should create the database file if it does not exist.
    ///
    /// # Errors
    ///
    /// Should return error if the connection could not be created.
    fn new_write_connection(path: &Path) -> Result<Self::Connection, Self::ConnectionError>;

    /// Start a transaction with the given `sql` command.
    ///
    /// # Errors
    ///
    /// Return error if the transaction could not be started.
    fn begin_transaction(connection: &mut Self::Connection, sql: &str) -> Result<(), Self::Error>;

    /// Commit the transaction.
    ///
    /// # Errors
    ///
    /// Return error if the transaction could not be commited.
    fn commit_transaction(connection: &mut Self::Connection) -> Result<(), Self::Error>;

    /// Rollback the transaction.
    ///
    /// # Errors
    ///
    /// Return error if the transaction could not be rolled back.
    fn rollback_transaction(connection: &mut Self::Connection) -> Result<(), Self::Error>;
}

/// Marker trait to signal whether the driver allows mutable connection deref from
/// the [`Transaction`](crate::pool::Transaction) type.
pub trait DriverMutConnectionDeref: Driver {}