Trait Driver

Source
pub trait Driver:
    'static
    + Send
    + Sync
    + Debug {
    type Connection;
    type Transaction<'t>;
    type Error: Debug;
    type ConnectionError: Debug;
    type ConnectionRef<'c>;

    // Required methods
    fn new_read_connection(
        path: &Path,
    ) -> Result<Self::Connection, Self::ConnectionError>;
    fn new_write_connection(
        path: &Path,
    ) -> Result<Self::Connection, Self::ConnectionError>;
    fn read<F, R, E>(
        connection: &mut Self::Connection,
        closure: F,
    ) -> Result<R, E>
       where F: FnOnce(Self::ConnectionRef<'_>) -> Result<R, E>,
             E: From<Self::Error>;
    fn write<F, R, E>(
        connection: &mut Self::Connection,
        closure: F,
    ) -> Result<R, E>
       where F: FnOnce(&mut Self::Transaction<'_>) -> Result<R, E>,
             E: From<Self::Error>;
}
Expand description

Implementation interface for any library which provides binding for sqlite.

Required Associated Types§

Source

type Connection

Source

type Transaction<'t>

Source

type Error: Debug

Source

type ConnectionError: Debug

Source

type ConnectionRef<'c>

Represents the reference to a connection type. Some drivers my specify this as immutable or mutable reference.

Required Methods§

Source

fn new_read_connection( path: &Path, ) -> Result<Self::Connection, Self::ConnectionError>

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.

Source

fn new_write_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.

Source

fn read<F, R, E>(connection: &mut Self::Connection, closure: F) -> Result<R, E>
where F: FnOnce(Self::ConnectionRef<'_>) -> Result<R, E>, E: From<Self::Error>,

Create a read transaction over the given closure.

A read transaction is created by executing the following SQL statements:

BEGIN
-- closure()
END
§Errors

Return error if the transaction could not be started or the closure failed.

Source

fn write<F, R, E>(connection: &mut Self::Connection, closure: F) -> Result<R, E>
where F: FnOnce(&mut Self::Transaction<'_>) -> Result<R, E>, E: From<Self::Error>,

Create new transaction an execute the given closure.

The transaction should be created with BEGIN IMMEDIATE to ensure the all file locks are acquired at the start of the transaction.

§Errors

Return error if the transaction could not be started, commited or the closure failed to execute.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§