pub struct Connection { /* private fields */ }Implementations§
Source§impl Connection
impl Connection
pub fn create( conn: Arc<TursoConnection>, extra_io: Option<Arc<dyn Fn(Waker) -> Result<()> + Send + Sync>>, ) -> Self
Sourcepub async fn query(
&self,
sql: impl AsRef<str>,
params: impl IntoParams,
) -> Result<Rows>
pub async fn query( &self, sql: impl AsRef<str>, params: impl IntoParams, ) -> Result<Rows>
Query the database with SQL.
Sourcepub async fn execute(
&self,
sql: impl AsRef<str>,
params: impl IntoParams,
) -> Result<u64>
pub async fn execute( &self, sql: impl AsRef<str>, params: impl IntoParams, ) -> Result<u64>
Execute SQL statement on the database.
Sourcepub async fn execute_batch(&self, sql: impl AsRef<str>) -> Result<()>
pub async fn execute_batch(&self, sql: impl AsRef<str>) -> Result<()>
Execute a batch of SQL statements on the database.
Sourcepub async fn prepare(&self, sql: impl AsRef<str>) -> Result<Statement>
pub async fn prepare(&self, sql: impl AsRef<str>) -> Result<Statement>
Prepare a SQL statement for later execution.
Sourcepub async fn prepare_cached(&self, sql: impl AsRef<str>) -> Result<Statement>
pub async fn prepare_cached(&self, sql: impl AsRef<str>) -> Result<Statement>
Prepare a SQL statement for later execution, caching it in the connection.
Sourcepub async fn pragma_query<F>(&self, pragma_name: &str, f: F) -> Result<()>
pub async fn pragma_query<F>(&self, pragma_name: &str, f: F) -> Result<()>
Query a pragma.
Sourcepub async fn pragma_update<V: Display>(
&self,
pragma_name: &str,
pragma_value: V,
) -> Result<Vec<Row>>
pub async fn pragma_update<V: Display>( &self, pragma_name: &str, pragma_value: V, ) -> Result<Vec<Row>>
Set a pragma value.
Sourcepub fn last_insert_rowid(&self) -> i64
pub fn last_insert_rowid(&self) -> i64
Returns the rowid of the last row inserted.
Sourcepub fn cacheflush(&self) -> Result<()>
pub fn cacheflush(&self) -> Result<()>
Flush dirty pages to disk. This will write the dirty pages to the WAL.
pub fn is_autocommit(&self) -> Result<bool>
Sourcepub fn busy_timeout(&self, duration: Duration) -> Result<()>
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:
- Set duration to 5ms
- Step through query -> returns Busy -> sleep/yield for 1 ms
- Step through query -> returns Busy -> sleep/yield for 2 ms
- Step through query -> returns Busy -> sleep/yield for 2 ms (totaling 5 ms of sleep)
- Step through query -> returns Busy -> return Busy to user
Source§impl Connection
impl Connection
Sourcepub async fn transaction(&mut self) -> Result<Transaction<'_>>
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.
Sourcepub async fn transaction_with_behavior(
&mut self,
behavior: TransactionBehavior,
) -> Result<Transaction<'_>>
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.
Sourcepub async fn unchecked_transaction(&self) -> Result<Transaction<'_>>
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.
Sourcepub fn set_transaction_behavior(&mut self, behavior: TransactionBehavior)
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
impl Clone for Connection
Auto Trait Implementations§
impl !Freeze for Connection
impl !RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnsafeUnpin for Connection
impl !UnwindSafe for Connection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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