pub struct Connection { /* private fields */ }Expand description
A handle to call functions in background thread.
Implementations§
Source§impl Connection
impl Connection
pub fn from_conn(conn: Connection) -> Result<Self>
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Open a new connection to an in-memory SQLite database.
§Failure
Will return Err if the underlying SQLite open call fails.
Sourcepub async fn call<F, R>(&self, function: F) -> Result<R>
pub async fn call<F, R>(&self, function: F) -> Result<R>
Call a function in background thread and get the result asynchronously.
§Failure
Will return Err if the database connection has been closed.
pub fn call_and_forget( &self, function: impl FnOnce(&Connection) + Send + 'static, )
Sourcepub async fn query(
&self,
sql: &str,
params: impl Params + Send + 'static,
) -> Result<Rows>
pub async fn query( &self, sql: &str, params: impl Params + Send + 'static, ) -> Result<Rows>
Query SQL statement.
pub async fn query_row( &self, sql: &str, params: impl Params + Send + 'static, ) -> Result<Option<Row>>
pub async fn query_value<T: DeserializeOwned + Send + 'static>( &self, sql: &str, params: impl Params + Send + 'static, ) -> Result<Option<T>>
pub async fn query_values<T: DeserializeOwned + Send + 'static>( &self, sql: &str, params: impl Params + Send + 'static, ) -> Result<Vec<T>>
Sourcepub async fn execute(
&self,
sql: &str,
params: impl Params + Send + 'static,
) -> Result<usize>
pub async fn execute( &self, sql: &str, params: impl Params + Send + 'static, ) -> Result<usize>
Execute SQL statement.
Sourcepub async fn execute_batch(&self, sql: &str) -> Result<Option<Rows>>
pub async fn execute_batch(&self, sql: &str) -> Result<Option<Rows>>
Batch execute SQL statements and return rows of last statement.
Sourcepub async fn add_preupdate_hook(
&self,
hook: Option<impl Fn(Action, &str, &str, &PreUpdateCase) + Send + Sync + 'static>,
) -> Result<()>
pub async fn add_preupdate_hook( &self, hook: Option<impl Fn(Action, &str, &str, &PreUpdateCase) + Send + Sync + 'static>, ) -> Result<()>
Convenience API for (un)setting a new pre-update hook.
Sourcepub async fn close(self) -> Result<()>
pub async fn close(self) -> Result<()>
Close the database connection.
This is functionally equivalent to the Drop implementation for
Connection. It consumes the Connection, but on error returns it
to the caller for retry purposes.
If successful, any following close operations performed
on Connection copies will succeed immediately.
On the other hand, any calls to Connection::call will return a
Error::ConnectionClosed, and any calls to [Connection::call_unwrap] will cause a
panic.
§Failure
Will return Err if the underlying SQLite close call fails.
Trait Implementations§
Source§impl Clone for Connection
impl Clone for Connection
Source§fn clone(&self) -> Connection
fn clone(&self) -> Connection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more