pub struct LibSqlConnection { /* private fields */ }Expand description
A Diesel connection backed by libsql.
Supports local SQLite databases (:memory: and file-based) as well as
remote Turso databases and embedded replicas.
Implementations§
Source§impl LibSqlConnection
impl LibSqlConnection
Sourcepub fn establish_replica(
local_path: &str,
remote_url: &str,
auth_token: &str,
) -> ConnectionResult<Self>
pub fn establish_replica( local_path: &str, remote_url: &str, auth_token: &str, ) -> ConnectionResult<Self>
Establish an embedded replica connection.
The replica maintains a local SQLite file at local_path that syncs
from remote_url using the provided auth_token. Reads are served
locally; writes are delegated to the remote primary.
Call sync to pull the latest state from the remote.
Sourcepub fn sync(&mut self) -> QueryResult<()>
pub fn sync(&mut self) -> QueryResult<()>
Sync the embedded replica with the remote primary.
Returns Ok(()) on success. If this connection is not a replica
(i.e., it is a local or pure-remote connection), this is a no-op.
Sourcepub fn alter_column(
&mut self,
table: &str,
column: &str,
new_definition: &str,
) -> QueryResult<()>
pub fn alter_column( &mut self, table: &str, column: &str, new_definition: &str, ) -> QueryResult<()>
Execute a libSQL-specific ALTER TABLE ... ALTER COLUMN ... TO ... statement.
The new_definition should include the column name, type, and any constraints.
For example:
conn.alter_column("users", "name", "name TEXT NOT NULL DEFAULT 'unknown'")?;This generates: ALTER TABLE users ALTER COLUMN name TO name TEXT NOT NULL DEFAULT 'unknown'
Sourcepub fn immediate_transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
pub fn immediate_transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
Run a transaction with BEGIN IMMEDIATE.
Acquires a reserved lock immediately, preventing other writers.
Useful when you know you will write and want to avoid SQLITE_BUSY.
Sourcepub fn exclusive_transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
pub fn exclusive_transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
Run a transaction with BEGIN EXCLUSIVE.
Acquires an exclusive lock immediately, preventing all other connections from reading or writing.
Sourcepub fn last_insert_rowid(&self) -> i64
pub fn last_insert_rowid(&self) -> i64
Returns the row ID of the last successful INSERT.
Returns 0 if no INSERT has been performed on this connection.
Sourcepub fn replica_builder(
local_path: impl Into<String>,
remote_url: impl Into<String>,
auth_token: impl Into<String>,
) -> ReplicaBuilder
pub fn replica_builder( local_path: impl Into<String>, remote_url: impl Into<String>, auth_token: impl Into<String>, ) -> ReplicaBuilder
Create a ReplicaBuilder for configuring an embedded replica connection.
Trait Implementations§
Source§impl Connection for LibSqlConnection
impl Connection for LibSqlConnection
Source§type TransactionManager = AnsiTransactionManager
type TransactionManager = AnsiTransactionManager
Source§fn establish(database_url: &str) -> ConnectionResult<Self>
fn establish(database_url: &str) -> ConnectionResult<Self>
Source§fn execute_returning_count<T>(&mut self, source: &T) -> QueryResult<usize>
fn execute_returning_count<T>(&mut self, source: &T) -> QueryResult<usize>
Source§fn transaction_state(&mut self) -> &mut AnsiTransactionManagerwhere
Self: Sized,
fn transaction_state(&mut self) -> &mut AnsiTransactionManagerwhere
Self: Sized,
Source§fn instrumentation(&mut self) -> &mut dyn Instrumentation
fn instrumentation(&mut self) -> &mut dyn Instrumentation
Source§fn set_instrumentation(&mut self, instrumentation: impl Instrumentation)
fn set_instrumentation(&mut self, instrumentation: impl Instrumentation)
Instrumentation implementation for this connectionSource§fn set_prepared_statement_cache_size(&mut self, _size: CacheSize)
fn set_prepared_statement_cache_size(&mut self, _size: CacheSize)
CacheSize for this connectionSource§fn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
fn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
Source§impl LoadConnection for LibSqlConnection
impl LoadConnection for LibSqlConnection
Source§type Cursor<'conn, 'query> = LibSqlCursor
type Cursor<'conn, 'query> = LibSqlCursor
LoadConnection::load Read moreSource§type Row<'conn, 'query> = LibSqlRow
type Row<'conn, 'query> = LibSqlRow
Iterator::Item for the iterator implementation
of LoadConnection::CursorSource§fn load<'conn, 'query, T>(
&'conn mut self,
source: T,
) -> QueryResult<Self::Cursor<'conn, 'query>>where
T: Query + QueryFragment<Self::Backend> + QueryId + 'query,
Self::Backend: QueryMetadata<T::SqlType>,
fn load<'conn, 'query, T>(
&'conn mut self,
source: T,
) -> QueryResult<Self::Cursor<'conn, 'query>>where
T: Query + QueryFragment<Self::Backend> + QueryId + 'query,
Self::Backend: QueryMetadata<T::SqlType>,
Source§impl MultiConnectionHelper for LibSqlConnection
impl MultiConnectionHelper for LibSqlConnection
Source§fn to_any<'a>(
lookup: &mut <Self::Backend as TypeMetadata>::MetadataLookup,
) -> &mut (dyn Any + 'a)
fn to_any<'a>( lookup: &mut <Self::Backend as TypeMetadata>::MetadataLookup, ) -> &mut (dyn Any + 'a)
Source§fn from_any(
lookup: &mut dyn Any,
) -> Option<&mut <Self::Backend as TypeMetadata>::MetadataLookup>
fn from_any( lookup: &mut dyn Any, ) -> Option<&mut <Self::Backend as TypeMetadata>::MetadataLookup>
Source§impl SimpleConnection for LibSqlConnection
impl SimpleConnection for LibSqlConnection
Source§fn batch_execute(&mut self, query: &str) -> QueryResult<()>
fn batch_execute(&mut self, query: &str) -> QueryResult<()>
Source§impl WithMetadataLookup for LibSqlConnection
impl WithMetadataLookup for LibSqlConnection
Source§fn metadata_lookup(&mut self) -> &mut <LibSql as TypeMetadata>::MetadataLookup
fn metadata_lookup(&mut self) -> &mut <LibSql as TypeMetadata>::MetadataLookup
impl ConnectionSealed for LibSqlConnection
impl Send for LibSqlConnection
Auto Trait Implementations§
impl !Freeze for LibSqlConnection
impl !RefUnwindSafe for LibSqlConnection
impl !Sync for LibSqlConnection
impl Unpin for LibSqlConnection
impl UnsafeUnpin for LibSqlConnection
impl !UnwindSafe for LibSqlConnection
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
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<C> BoxableConnection<<C as Connection>::Backend> for Cwhere
C: Connection + Any,
impl<C> BoxableConnection<<C as Connection>::Backend> for Cwhere
C: Connection + Any,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
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::RequestSource§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read more