pub struct Connection { /* private fields */ }Expand description
A handle to call functions in background thread.
Implementations§
Source§impl Connection
impl Connection
Sourcepub async fn open<P: AsRef<Path>>(path: P) -> Result<Self, Error>
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.
Sourcepub async fn open_in_memory() -> Result<Self, Error>
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.
Sourcepub async fn open_with_flags<P: AsRef<Path>>(
path: P,
flags: OpenFlags,
) -> Result<Self, Error>
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.
Sourcepub async fn open_with_flags_and_vfs<P: AsRef<Path>>(
path: P,
flags: OpenFlags,
vfs: &str,
) -> Result<Self, Error>
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.
Sourcepub async fn open_in_memory_with_flags(flags: OpenFlags) -> Result<Self, Error>
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.
Sourcepub async fn open_in_memory_with_flags_and_vfs(
flags: OpenFlags,
vfs: &str,
) -> Result<Self, Error>
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.
Sourcepub async fn call<F, R, E>(&self, function: F) -> Result<R, Error<E>>
pub async fn call<F, R, E>(&self, function: F) -> Result<R, Error<E>>
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.
Sourcepub async fn call_raw<F, R>(&self, function: F) -> Result<R>
pub async fn call_raw<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.
Sourcepub async fn call_unwrap<F, R>(&self, function: F) -> R
pub async fn call_unwrap<F, R>(&self, function: F) -> R
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.
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