Struct SqliteConnection

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

A connection to an open [Sqlite] database.

Because SQLite is an in-process database accessed by blocking API calls, rbdc uses a background thread and communicates with it via channels to allow non-blocking access to the database.

Dropping this struct will signal the worker thread to quit and close the database, though if an error occurs there is no way to pass it back to the user this way.

You can explicitly call [.close()][Self::close] to ensure the database is closed successfully or get an error otherwise.

Implementations§

Source§

impl SqliteConnection

Source

pub fn fetch_many( &mut self, query: SqliteQuery, ) -> BoxStream<'_, Result<Either<SqliteQueryResult, SqliteRow>, Error>>

Source

pub fn fetch_optional( &mut self, query: SqliteQuery, ) -> BoxFuture<'_, Result<Option<SqliteRow>, Error>>

Source

pub fn prepare_with<'a>( &'a mut self, sql: &'a str, _parameters: &[SqliteTypeInfo], ) -> BoxFuture<'a, Result<SqliteStatement, Error>>

Source§

impl SqliteConnection

Source

pub unsafe fn as_raw_handle(&mut self) -> *mut sqlite3

👎Deprecated: Unsynchronized access is unsafe. See documentation for details.

Returns the underlying sqlite3* connection handle.

§Note

There is no synchronization using this method, beware that the background thread could be making SQLite API calls concurrent to use of this method.

You probably want to use .lock_handle() to ensure that the worker thread is not using the database concurrently.

Source

pub fn create_collation( &mut self, name: &str, compare: impl Fn(&str, &str) -> Ordering + Send + Sync + 'static, ) -> Result<(), Error>

👎Deprecated: Completes asynchronously. See documentation for details.

Apply a collation to the open database.

See SqliteConnectOptions::collation() for details.

§Deprecated

Due to the rearchitecting of the SQLite driver, this method cannot actually function synchronously and return the result directly from sqlite3_create_collation_v2(), so it instead sends a message to the worker create the collation asynchronously. If an error occurs it will simply be logged.

Instead, you should specify the collation during the initial configuration with SqliteConnectOptions::collation(). Then, if the collation fails to apply it will return an error during the connection creation. When used with a [Pool][crate::pool::Pool], this also ensures that the collation is applied to all connections automatically.

Or if necessary, you can call .lock_handle() and create the collation directly with LockedSqliteHandle::create_collation().

[Error::from("WorkerCrashed")] may still be returned if we could not communicate with the worker.

Note that this may also block if the worker command channel is currently applying backpressure.

Source

pub async fn lock_handle(&mut self) -> Result<LockedSqliteHandle<'_>, Error>

Lock the SQLite database handle out from the worker thread so direct SQLite API calls can be made safely.

Returns an error if the worker thread crashed.

Source§

impl SqliteConnection

Source

pub async fn do_close(&mut self) -> Result<(), Error>

Source

pub fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>>

Ensure the background worker thread is alive and accepting commands.

Source

pub fn cached_statements_size(&self) -> usize

Source

pub fn clear_cached_statements(&mut self) -> BoxFuture<'_, Result<(), Error>>

Trait Implementations§

Source§

impl Connection for SqliteConnection

Source§

fn get_rows( &mut self, sql: &str, params: Vec<Value>, ) -> BoxFuture<'_, Result<Vec<Box<dyn Row>>, Error>>

Execute a query that is expected to return a result set, such as a SELECT statement
Source§

fn exec( &mut self, sql: &str, params: Vec<Value>, ) -> BoxFuture<'_, Result<ExecResult, Error>>

Execute a query that is expected to update some rows.
Source§

fn close(&mut self) -> BoxFuture<'_, Result<(), Error>>

close connection Normally conn is dropped when the link is dropped, but it is recommended to actively close this function so that the database does not report errors. If &mut self is not satisfied close, when you need mut self, It is recommended to use Option and then call take to take ownership and then if let Some(v) = self.inner.take() {v.lose ().await; }
Source§

fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>>

ping
Source§

fn get_values( &mut self, sql: &str, params: Vec<Value>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Value>, Error>> + Send + '_>>

Execute a query that is expected to return a result set, such as a SELECT statement
Source§

fn begin( &mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

an translation impl begin
Source§

fn commit( &mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

an translation impl commit
Source§

fn rollback( &mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

an translation impl rollback
Source§

impl Debug for SqliteConnection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Sync for SqliteConnection

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,