SqliteConnection

Struct SqliteConnection 

Source
pub struct SqliteConnection { /* private fields */ }
Expand description

Connection wrapper backed by a bb8 pooled SQLite connection.

Implementations§

Source§

impl SqliteConnection

Source

pub async fn with_connection<F, R>( &self, func: F, ) -> Result<R, SqlMiddlewareDbError>
where F: FnOnce(&mut Connection) -> Result<R, SqlMiddlewareDbError> + Send + 'static, R: Send + 'static,

Run func on the pooled rusqlite connection while no other transaction is in flight.

§Errors

Returns SqlMiddlewareDbError::ExecutionError if the connection is in a transaction or the closure returns an error.

Source§

impl SqliteConnection

Source

pub async fn execute_batch( &mut self, query: &str, ) -> Result<(), SqlMiddlewareDbError>

Execute a batch of statements; wraps in a transaction when not already inside one.

§Errors

Returns SqlMiddlewareDbError if acquiring the SQLite guard or executing the batch fails.

Source

pub async fn execute_dml( &mut self, query: &str, params: &[Value], ) -> Result<usize, SqlMiddlewareDbError>

Execute a DML statement and return rows affected.

§Errors

Returns SqlMiddlewareDbError if preparing or executing the statement fails.

Source

pub async fn execute_dml_in_tx( &mut self, query: &str, params: &[Value], ) -> Result<usize, SqlMiddlewareDbError>

Execute a DML statement inside an open transaction.

§Errors

Returns SqlMiddlewareDbError if the guard fails or the transaction is not active.

Source

pub async fn execute_batch_in_tx( &mut self, sql: &str, ) -> Result<(), SqlMiddlewareDbError>

Execute a batch inside an open transaction without implicit commit.

§Errors

Returns SqlMiddlewareDbError if the guard fails or the transaction is not active.

Source§

impl SqliteConnection

Source

pub async fn prepare_statement( &mut self, query: &str, ) -> Result<SqlitePreparedStatement<'_>, SqlMiddlewareDbError>

Prepare a statement for repeated execution (auto-commit mode only).

§Errors

Returns SqlMiddlewareDbError if preparing the statement fails or a transaction is active.

Source§

impl SqliteConnection

Source

pub async fn execute_select<F>( &mut self, query: &str, params: &[Value], builder: F, ) -> Result<ResultSet, SqlMiddlewareDbError>
where F: FnOnce(&mut Statement<'_>, &[Value]) -> Result<ResultSet, SqlMiddlewareDbError> + Send + 'static,

Execute a SELECT and materialize into a ResultSet.

§Errors

Returns SqlMiddlewareDbError if preparing or executing the query fails.

Source

pub async fn execute_select_in_tx<F>( &mut self, query: &str, params: &[Value], builder: F, ) -> Result<ResultSet, SqlMiddlewareDbError>
where F: FnOnce(&mut Statement<'_>, &[Value]) -> Result<ResultSet, SqlMiddlewareDbError> + Send + 'static,

Execute a query inside an open transaction and build a ResultSet.

§Errors

Returns SqlMiddlewareDbError if preparing/executing the query fails or the transaction is not active.

Source

pub fn query<'a>(&'a mut self, sql: &'a str) -> QueryBuilder<'a, 'a>

Start a query builder (auto-commit per operation).

Source§

impl SqliteConnection

Source

pub async fn begin(&mut self) -> Result<(), SqlMiddlewareDbError>

Begin a transaction, transitioning this connection into transactional mode.

§Errors

Returns SqlMiddlewareDbError if the transaction cannot be started or is already active.

Source

pub async fn commit(&mut self) -> Result<(), SqlMiddlewareDbError>

Commit an open transaction.

§Errors

Returns SqlMiddlewareDbError if committing fails or no transaction is active.

Source

pub async fn rollback(&mut self) -> Result<(), SqlMiddlewareDbError>

Roll back an open transaction.

§Errors

Returns SqlMiddlewareDbError if rolling back fails or no transaction is active.

Trait Implementations§

Source§

impl Debug for SqliteConnection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V