Skip to main content

Connection

Struct Connection 

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

Implementations§

Source§

impl Connection

Source

pub fn create( conn: Arc<TursoConnection>, extra_io: Option<Arc<dyn Fn(Waker) -> Result<()> + Send + Sync>>, ) -> Self

Source

pub async fn query( &self, sql: impl AsRef<str>, params: impl IntoParams, ) -> Result<Rows>

Query the database with SQL.

Source

pub async fn execute( &self, sql: impl AsRef<str>, params: impl IntoParams, ) -> Result<u64>

Execute SQL statement on the database.

Source

pub async fn execute_batch(&self, sql: impl AsRef<str>) -> Result<()>

Execute a batch of SQL statements on the database.

Source

pub async fn prepare(&self, sql: impl AsRef<str>) -> Result<Statement>

Prepare a SQL statement for later execution.

Source

pub async fn prepare_cached(&self, sql: impl AsRef<str>) -> Result<Statement>

Prepare a SQL statement for later execution, caching it in the connection.

Source

pub async fn pragma_query<F>(&self, pragma_name: &str, f: F) -> Result<()>
where F: FnMut(&Row) -> Result<(), TursoError>,

Query a pragma.

Source

pub async fn pragma_update<V: Display>( &self, pragma_name: &str, pragma_value: V, ) -> Result<Vec<Row>>

Set a pragma value.

Source

pub fn last_insert_rowid(&self) -> i64

Returns the rowid of the last row inserted.

Source

pub fn cacheflush(&self) -> Result<()>

Flush dirty pages to disk. This will write the dirty pages to the WAL.

Source

pub fn is_autocommit(&self) -> Result<bool>

Source

pub fn busy_timeout(&self, duration: Duration) -> Result<()>

Sets maximum total accumuated timeout. If the duration is None or Zero, we unset the busy handler for this Connection

This api defers slighty from: https://www.sqlite.org/c3ref/busy_timeout.html

Instead of sleeping for linear amount of time specified by the user, we will sleep in phases, until the the total amount of time is reached. This means we first sleep of 1ms, then if we still return busy, we sleep for 2 ms, and repeat until a maximum of 100 ms per phase.

Example:

  1. Set duration to 5ms
  2. Step through query -> returns Busy -> sleep/yield for 1 ms
  3. Step through query -> returns Busy -> sleep/yield for 2 ms
  4. Step through query -> returns Busy -> sleep/yield for 2 ms (totaling 5 ms of sleep)
  5. Step through query -> returns Busy -> return Busy to user
Source§

impl Connection

Source

pub async fn transaction(&mut self) -> Result<Transaction<'_>>

Begin a new transaction with the default behavior (DEFERRED).

The transaction defaults to rolling back on the next access to the connection if it is not finished when the transaction is dropped. If you want the transaction to commit, you must call commit or set_drop_behavior(DropBehavior::Commit).

§Example
async fn perform_queries(conn: &mut Connection) -> Result<()> {
    let tx = conn.transaction().await?;

    do_queries_part_1(&tx)?; // tx causes rollback if this fails
    do_queries_part_2(&tx)?; // tx causes rollback if this fails

    tx.commit().await
}
§Failure

Will return Err if the call fails.

Source

pub async fn transaction_with_behavior( &mut self, behavior: TransactionBehavior, ) -> Result<Transaction<'_>>

Begin a new transaction with a specified behavior.

See transaction.

§Failure

Will return Err if the call fails.

Source

pub async fn unchecked_transaction(&self) -> Result<Transaction<'_>>

Begin a new transaction with the default behavior (DEFERRED).

Attempt to open a nested transaction will result in a SQLite error. Connection::transaction prevents this at compile time by taking &mut self, but Connection::unchecked_transaction() may be used to defer the checking until runtime.

See Connection::transaction and Transaction::new_unchecked (which can be used if the default transaction behavior is undesirable).

§Example
async fn perform_queries(conn: Rc<Connection>) -> Result<()> {
    let tx = conn.unchecked_transaction().await?;

    do_queries_part_1(&tx)?; // tx causes rollback if this fails
    do_queries_part_2(&tx)?; // tx causes rollback if this fails

    tx.commit().await
}
§Failure

Will return Err if the underlying SQLite call fails. The specific error returned if transactions are nested is currently unspecified.

Source

pub fn set_transaction_behavior(&mut self, behavior: TransactionBehavior)

Set the default transaction behavior for the connection.

§Note

This will only apply to transactions initiated by transaction or unchecked_transaction.

§Example
async fn perform_queries(conn: &mut Connection) -> Result<()> {
    conn.set_transaction_behavior(TransactionBehavior::Immediate);

    let tx = conn.transaction().await?;

    do_queries_part_1(&tx)?; // tx causes rollback if this fails
    do_queries_part_2(&tx)?; // tx causes rollback if this fails

    tx.commit().await
}

Trait Implementations§

Source§

impl Clone for Connection

Source§

fn clone(&self) -> Self

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more