Connection

Struct Connection 

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

A handle to call functions in background thread.

Implementations§

Source§

impl Connection

Source

pub async fn open<P: AsRef<Path>>(path: P) -> Result<Self, Error>

Open a new connection to a SQLite database.

Connection::open(path) is equivalent to Connection::open_with_flags(path, OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE).

§Failure

Will return Err if path cannot be converted to a C-compatible string or if the underlying SQLite open call fails.

Source

pub async fn open_in_memory() -> Result<Self, Error>

Open a new connection to an in-memory SQLite database.

§Failure

Will return Err if the underlying SQLite open call fails.

Source

pub async fn open_with_flags<P: AsRef<Path>>( path: P, flags: OpenFlags, ) -> Result<Self, Error>

Open a new connection to a SQLite database.

Database Connection for a description of valid flag combinations.

§Failure

Will return Err if path cannot be converted to a C-compatible string or if the underlying SQLite open call fails.

Source

pub async fn open_with_flags_and_vfs<P: AsRef<Path>>( path: P, flags: OpenFlags, vfs: &str, ) -> Result<Self, Error>

Open a new connection to a SQLite database using the specific flags and vfs name.

Database Connection for a description of valid flag combinations.

§Failure

Will return Err if either path or vfs cannot be converted to a C-compatible string or if the underlying SQLite open call fails.

Source

pub async fn open_in_memory_with_flags(flags: OpenFlags) -> Result<Self, Error>

Open a new connection to an in-memory SQLite database.

Database Connection for a description of valid flag combinations.

§Failure

Will return Err if the underlying SQLite open call fails.

Source

pub async fn open_in_memory_with_flags_and_vfs( flags: OpenFlags, vfs: &str, ) -> Result<Self, Error>

Open a new connection to an in-memory SQLite database using the specific flags and vfs name.

Database Connection for a description of valid flag combinations.

§Failure

Will return Err if vfs cannot be converted to a C-compatible string or if the underlying SQLite open call fails.

Source

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

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

§Failure

Will return Err if the database connection has been closed. Will return Error::Error wrapping the inner error if function failed.

Source

pub async fn call_raw<F, R>(&self, function: F) -> Result<R>
where F: FnOnce(&mut Connection) -> R + 'static + Send, 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 async fn call_unwrap<F, R>(&self, function: F) -> R
where F: FnOnce(&mut Connection) -> R + Send + 'static, R: Send + 'static,

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

This method can cause a panic if the underlying database connection is closed. it is a more user-friendly alternative to the Connection::call method. It should be safe if the connection is never explicitly closed (using the Connection::close call).

Calling this on a closed connection will cause a panic.

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.

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

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

impl From<Connection> for Connection

Source§

fn from(conn: Connection) -> Self

Converts to this type from the input type.

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.