pub struct Connection { /* private fields */ }
Expand description
A handle to call functions in background thread.
Implementations§
Source§impl Connection
impl Connection
pub fn new<E>( builder: impl Fn() -> Result<Connection, E>, opt: Option<Options>, ) -> Result<Self, E>
pub fn from_connection_test_only(conn: Connection) -> 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.
pub fn write_lock(&self) -> LockGuard<'_>
pub fn try_write_lock_for(&self, duration: Duration) -> Option<LockGuard<'_>>
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 read_query_rows(
&self,
sql: impl AsRef<str> + Send + 'static,
params: impl Params + Send + 'static,
) -> Result<Rows>
pub async fn read_query_rows( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, ) -> Result<Rows>
Query SQL statement.
pub async fn write_query_rows( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, ) -> Result<Rows>
pub async fn read_query_row( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, ) -> Result<Option<Row>>
pub async fn query_row_f<T, E>( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, f: impl FnOnce(&Row<'_>) -> Result<T, E> + Send + 'static, ) -> Result<Option<T>>
pub async fn read_query_row_f<T, E>( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, f: impl FnOnce(&Row<'_>) -> Result<T, E> + Send + 'static, ) -> Result<Option<T>>
pub async fn read_query_value<T: DeserializeOwned + Send + 'static>( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, ) -> Result<Option<T>>
pub async fn write_query_value<T: DeserializeOwned + Send + 'static>( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, ) -> Result<Option<T>>
pub async fn read_query_values<T: DeserializeOwned + Send + 'static>( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, ) -> Result<Vec<T>>
Sourcepub async fn execute(
&self,
sql: impl AsRef<str> + Send + 'static,
params: impl Params + Send + 'static,
) -> Result<usize>
pub async fn execute( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, ) -> Result<usize>
Execute SQL statement.
Sourcepub async fn execute_batch(
&self,
sql: impl AsRef<str> + Send + 'static,
) -> Result<Option<Rows>>
pub async fn execute_batch( &self, sql: impl AsRef<str> + Send + 'static, ) -> 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.
pub fn attach(&self, path: &str, name: &str) -> Result<()>
pub async fn list_databases(&self) -> Result<Vec<Database>>
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.
§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