pub struct SqliteConnection { /* private fields */ }Expand description
Connection wrapper backed by a bb8 pooled SQLite connection.
Implementations§
Source§impl SqliteConnection
impl SqliteConnection
Sourcepub 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,
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
impl SqliteConnection
Sourcepub async fn execute_batch(
&mut self,
query: &str,
) -> Result<(), SqlMiddlewareDbError>
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.
Sourcepub async fn execute_dml(
&mut self,
query: &str,
params: &[Value],
) -> Result<usize, SqlMiddlewareDbError>
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.
Sourcepub async fn execute_dml_in_tx(
&mut self,
query: &str,
params: &[Value],
) -> Result<usize, SqlMiddlewareDbError>
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.
Sourcepub async fn execute_batch_in_tx(
&mut self,
sql: &str,
) -> Result<(), SqlMiddlewareDbError>
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
impl SqliteConnection
Sourcepub async fn prepare_statement(
&mut self,
query: &str,
) -> Result<SqlitePreparedStatement<'_>, SqlMiddlewareDbError>
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
impl SqliteConnection
Sourcepub async fn execute_select<F>(
&mut self,
query: &str,
params: &[Value],
builder: F,
) -> Result<ResultSet, SqlMiddlewareDbError>
pub async fn execute_select<F>( &mut self, query: &str, params: &[Value], builder: F, ) -> Result<ResultSet, SqlMiddlewareDbError>
Execute a SELECT and materialize into a ResultSet.
§Errors
Returns SqlMiddlewareDbError if preparing or executing the query fails.
Sourcepub async fn execute_select_in_tx<F>(
&mut self,
query: &str,
params: &[Value],
builder: F,
) -> Result<ResultSet, SqlMiddlewareDbError>
pub async fn execute_select_in_tx<F>( &mut self, query: &str, params: &[Value], builder: F, ) -> Result<ResultSet, SqlMiddlewareDbError>
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.
Sourcepub fn query<'a>(&'a mut self, sql: &'a str) -> QueryBuilder<'a, 'a>
pub fn query<'a>(&'a mut self, sql: &'a str) -> QueryBuilder<'a, 'a>
Start a query builder (auto-commit per operation).
Source§impl SqliteConnection
impl SqliteConnection
Sourcepub async fn begin(&mut self) -> Result<(), SqlMiddlewareDbError>
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.