Skip to main content

LibSqlConnection

Struct LibSqlConnection 

Source
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

Source

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.

Source

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.

Source

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'

Source

pub fn immediate_transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
where F: FnOnce(&mut Self) -> Result<T, E>, E: From<Error>,

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.

Source

pub fn exclusive_transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
where F: FnOnce(&mut Self) -> Result<T, E>, E: From<Error>,

Run a transaction with BEGIN EXCLUSIVE.

Acquires an exclusive lock immediately, preventing all other connections from reading or writing.

Source

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.

Source

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

Source§

type Backend = LibSql

The backend this type connects to
Source§

type TransactionManager = AnsiTransactionManager

The transaction manager implementation used by this connection
Source§

fn establish(database_url: &str) -> ConnectionResult<Self>

Establishes a new connection to the database Read more
Source§

fn execute_returning_count<T>(&mut self, source: &T) -> QueryResult<usize>
where T: QueryFragment<Self::Backend> + QueryId,

Execute a single SQL statements given by a query and return number of affected rows
Source§

fn transaction_state(&mut self) -> &mut AnsiTransactionManager
where Self: Sized,

Get access to the current transaction state of this connection Read more
Source§

fn instrumentation(&mut self) -> &mut dyn Instrumentation

Get the instrumentation instance stored in this connection
Source§

fn set_instrumentation(&mut self, instrumentation: impl Instrumentation)

Set a specific Instrumentation implementation for this connection
Source§

fn set_prepared_statement_cache_size(&mut self, _size: CacheSize)

Set the prepared statement cache size to CacheSize for this connection
Source§

fn transaction<T, E, F>(&mut self, f: F) -> Result<T, E>
where F: FnOnce(&mut Self) -> Result<T, E>, E: From<Error>,

Executes the given function inside of a database transaction Read more
Source§

fn begin_test_transaction(&mut self) -> Result<(), Error>

Creates a transaction that will never be committed. This is useful for tests. Panics if called while inside of a transaction or if called with a connection containing a broken transaction
Source§

fn test_transaction<T, E, F>(&mut self, f: F) -> T
where F: FnOnce(&mut Self) -> Result<T, E>, E: Debug,

Executes the given function inside a transaction, but does not commit it. Panics if the given function returns an error. Read more
Source§

impl LoadConnection for LibSqlConnection

Source§

type Cursor<'conn, 'query> = LibSqlCursor

The cursor type returned by LoadConnection::load Read more
Source§

type Row<'conn, 'query> = LibSqlRow

The row type used as Iterator::Item for the iterator implementation of LoadConnection::Cursor
Source§

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>,

Executes a given query and returns any requested values Read more
Source§

impl MigrationConnection for LibSqlConnection

Source§

fn setup(&mut self) -> QueryResult<usize>

Setup the following table: Read more
Source§

impl MultiConnectionHelper for LibSqlConnection

Source§

fn to_any<'a>( lookup: &mut <Self::Backend as TypeMetadata>::MetadataLookup, ) -> &mut (dyn Any + 'a)

Convert the lookup type to any
Source§

fn from_any( lookup: &mut dyn Any, ) -> Option<&mut <Self::Backend as TypeMetadata>::MetadataLookup>

Get the lookup type from any
Source§

impl SimpleConnection for LibSqlConnection

Source§

fn batch_execute(&mut self, query: &str) -> QueryResult<()>

Execute multiple SQL statements within the same string. Read more
Source§

impl WithMetadataLookup for LibSqlConnection

Source§

fn metadata_lookup(&mut self) -> &mut <LibSql as TypeMetadata>::MetadataLookup

Retrieves the underlying metadata lookup
Source§

impl ConnectionSealed for LibSqlConnection

Source§

impl Send for LibSqlConnection

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
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<C> BoxableConnection<<C as Connection>::Backend> for C
where C: Connection + Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Maps the current connection to std::any::Any
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more
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