pub struct Connection { /* private fields */ }
Expand description
A connection to some libsql database, this can be a remote one or a local one.
Implementations§
Source§impl Connection
impl Connection
Sourcepub async fn execute(&self, sql: &str, params: impl IntoParams) -> Result<u64>
pub async fn execute(&self, sql: &str, params: impl IntoParams) -> Result<u64>
Execute sql query provided some type that implements IntoParams
returning
on success the number of rows that were changed.
§Example
conn.execute("INSERT INTO foo (id) VALUES (?1)", [42]).await.unwrap();
conn.execute("INSERT INTO foo (id, name) VALUES (?1, ?2)", params![42, "baz"]).await.unwrap();
For more info on how to pass params check IntoParams
’s docs.
Sourcepub async fn execute_batch(&self, sql: &str) -> Result<BatchRows>
pub async fn execute_batch(&self, sql: &str) -> Result<BatchRows>
Execute a batch set of statements.
§Return
This returns a BatchRows
currently only the remote
and local
connection supports this feature and
all other connection types will return an empty set always.
Sourcepub async fn execute_transactional_batch(&self, sql: &str) -> Result<BatchRows>
pub async fn execute_transactional_batch(&self, sql: &str) -> Result<BatchRows>
Execute a batch set of statements atomically in a transaction.
§Return
This returns a BatchRows
currently only the remote
and local
connection supports this feature and
all other connection types will return an empty set always.
Sourcepub async fn query(&self, sql: &str, params: impl IntoParams) -> Result<Rows>
pub async fn query(&self, sql: &str, params: impl IntoParams) -> Result<Rows>
Execute sql query provided some type that implements IntoParams
returning
on success the Rows
.
§Example
conn.query("SELECT foo FROM bar WHERE id = ?1", [42]).await.unwrap();
conn.query("SELECT foo FROM bar WHERE id = ?1 AND name = ?2", params![42, "baz"]).await.unwrap();
For more info on how to pass params check IntoParams
’s docs and on how to
extract values out of the rows check the Rows
docs.
Sourcepub async fn transaction(&self) -> Result<Transaction>
pub async fn transaction(&self) -> Result<Transaction>
Begin a new transaction in DEFERRED
mode, which is the default.
Sourcepub async fn transaction_with_behavior(
&self,
tx_behavior: TransactionBehavior,
) -> Result<Transaction>
pub async fn transaction_with_behavior( &self, tx_behavior: TransactionBehavior, ) -> Result<Transaction>
Begin a new transaction in the given TransactionBehavior
.
Sourcepub fn interrupt(&self) -> Result<()>
pub fn interrupt(&self) -> Result<()>
Cancel ongoing operations and return at earliest opportunity.
pub fn busy_timeout(&self, timeout: Duration) -> Result<()>
Sourcepub fn is_autocommit(&self) -> bool
pub fn is_autocommit(&self) -> bool
Check whether libsql is in autocommit
or not.
Sourcepub fn total_changes(&self) -> u64
pub fn total_changes(&self) -> u64
Check the total amount of changes the connection has done.
Sourcepub fn last_insert_rowid(&self) -> i64
pub fn last_insert_rowid(&self) -> i64
Check the last inserted row id.
pub async fn reset(&self)
Sourcepub fn load_extension_enable(&self) -> Result<()>
pub fn load_extension_enable(&self) -> Result<()>
Enable loading SQLite extensions from SQL queries and Rust API.
See load_extension
documentation for more details.
Sourcepub fn load_extension_disable(&self) -> Result<()>
pub fn load_extension_disable(&self) -> Result<()>
Disable loading SQLite extensions from SQL queries and Rust API.
See load_extension
documentation for more details.
Sourcepub fn load_extension<P: AsRef<Path>>(
&self,
dylib_path: P,
entry_point: Option<&str>,
) -> Result<()>
pub fn load_extension<P: AsRef<Path>>( &self, dylib_path: P, entry_point: Option<&str>, ) -> Result<()>
Load a SQLite extension from a dynamic library at dylib_path
, specifying optional
entry point entry_point
.
§Security
Loading extensions from dynamic libraries is a potential security risk, as it allows arbitrary code execution. Only load extensions that you trust.
Extension loading is disabled by default. Please use the load_extension_enable
method to enable it. It’s recommended to disable extension loading after you’re done
loading extensions to avoid SQL injection attacks from loading extensions.
See SQLite’s documentation on sqlite3_load_extension
for more information:
https://sqlite.org/c3ref/load_extension.html
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 moreAuto Trait Implementations§
impl Freeze for Connection
impl !RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin 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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request