Struct Connection

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

A handle to call functions in background thread.

Implementations§

Source§

impl Connection

Source

pub fn new<E>( builder: impl Fn() -> Result<Connection, E>, opt: Option<Options>, ) -> Result<Self, E>

Source

pub fn from_connection_test_only(conn: Connection) -> Self

Source

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.

Source

pub fn write_lock(&self) -> LockGuard<'_>

Source

pub fn try_write_lock_for(&self, duration: Duration) -> Option<LockGuard<'_>>

Source

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

Call a function in background thread and get the result asynchronously.

§Failure

Will return Err if the database connection has been closed.

Source

pub fn call_and_forget( &self, function: impl FnOnce(&Connection) + Send + 'static, )

Source

pub async fn read_query_rows( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, ) -> Result<Rows>

Query SQL statement.

Source

pub async fn write_query_rows( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, ) -> Result<Rows>

Source

pub async fn read_query_row( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, ) -> Result<Option<Row>>

Source

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>>
where T: Send + 'static, Error: From<E>,

Source

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>>
where T: Send + 'static, Error: From<E>,

Source

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>>

Source

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>>

Source

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>>

Source

pub async fn execute( &self, sql: impl AsRef<str> + Send + 'static, params: impl Params + Send + 'static, ) -> Result<usize>

Execute SQL statement.

Source

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.

Source

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.

Source

pub fn attach(&self, path: &str, name: &str) -> Result<()>

Source

pub async fn list_databases(&self) -> Result<Vec<Database>>

Source

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

Source§

fn clone(&self) -> Connection

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Connection

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.