Skip to main content

Connection

Struct Connection 

Source
pub struct Connection<'p, P: Sqlite3Api> { /* private fields */ }
Expand description

Safe wrapper around a sqlite3* connection.

Implementations§

Source§

impl<'p, P: Sqlite3Api> Connection<'p, P>

Source

pub fn open( api: &'p P, filename: &str, options: OpenOptions<'_>, ) -> Result<Self>

Open a connection using the provider SPI.

Source

pub fn prepare(&self, sql: &str) -> Result<Statement<'_, 'p, P>>

Prepare a statement, using prepare_v3 when available.

Source

pub fn prepare_with_flags( &self, sql: &str, flags: u32, ) -> Result<Statement<'_, 'p, P>>

Prepare a statement with flags (requires prepare_v3 support).

Source

pub fn raw_handle(&self) -> NonNull<P::Db>

Expose the raw database handle.

Source§

impl<'p, P: Sqlite3Keying> Connection<'p, P>

Source

pub fn open_with_key( api: &'p P, filename: &str, options: OpenOptions<'_>, key: &[u8], ) -> Result<Self>

Open a connection and immediately apply a key (SQLCipher-style).

Source

pub fn rekey(&self, key: &[u8]) -> Result<()>

Rekey the database (SQLCipher-style).

Source§

impl<'p, P: Sqlite3Backup> Connection<'p, P>

Source

pub fn backup_to<'c>( &'c self, dest: &'c Connection<'p, P>, name: &str, ) -> Result<Backup<'c, 'p, P>>

Start a backup from this database to dest.

Source§

impl<'p, P: Sqlite3BlobIo> Connection<'p, P>

Source

pub fn open_blob<'c>( &'c self, db_name: &str, table: &str, column: &str, rowid: i64, flags: u32, ) -> Result<Blob<'c, 'p, P>>

Open an incremental blob handle.

Source§

impl<'p, P: Sqlite3Serialize> Connection<'p, P>

Source

pub fn serialize( &self, schema: Option<&str>, flags: u32, ) -> Result<SerializedDb<'p, P>>

Serialize the database into an owned buffer.

Source

pub fn deserialize( &self, schema: Option<&str>, data: &[u8], flags: u32, ) -> Result<()>

Deserialize bytes into the database.

Source§

impl<'p, P: Sqlite3Wal> Connection<'p, P>

Source

pub fn wal_checkpoint(&self, db_name: Option<&str>) -> Result<()>

Run a WAL checkpoint.

Source

pub fn wal_checkpoint_v2( &self, db_name: Option<&str>, mode: i32, ) -> Result<(i32, i32)>

Run a WAL checkpoint with a mode, returning (log, checkpointed) page counts.

Source

pub fn wal_frame_count(&self) -> Result<Option<u32>>

Return libsql WAL frame count if supported.

Source§

impl<'p, P: Sqlite3Metadata> Connection<'p, P>

Source

pub fn table_column_metadata( &self, db_name: Option<&str>, table: &str, column: &str, ) -> Result<ColumnMetadata>

Fetch column metadata for a table.

Source§

impl<'p, P: Sqlite3Hooks> Connection<'p, P>

Source

pub fn busy_timeout(&self, ms: i32) -> Result<()>

Set busy timeout.

Source

pub unsafe fn progress_handler_raw( &self, n: i32, cb: Option<extern "C" fn(*mut c_void) -> i32>, context: *mut c_void, ) -> Result<()>

Register or clear a raw progress callback.

§Safety

Callers must ensure the callback/context pair remains valid until it is explicitly cleared and that the callback never unwinds.

Source

pub fn register_progress_handler<'c, F>( &'c self, n: i32, f: F, ) -> Result<CallbackHandle<'c, 'p, P>>
where F: FnMut() -> i32 + Send + 'static,

Register a panic-contained progress callback.

The callback is invoked through a trampoline that catches panics and returns 1 on unwind so SQLite interrupts execution (fail-closed).

Source

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

Remove any previously registered progress callback.

Source

pub fn register_trace<'c, F>( &'c self, mask: TraceMask, f: F, ) -> Result<CallbackHandle<'c, 'p, P>>
where F: for<'a> FnMut(TraceEvent<'a, P>) + Send + 'static,

Register a typed trace callback.

Source

pub fn register_authorizer<'c, F>( &'c self, f: F, ) -> Result<CallbackHandle<'c, 'p, P>>
where F: FnMut(AuthorizerEvent<'_>) -> AuthorizerResult + Send + 'static,

Register a typed authorizer callback.

Source§

impl<'p, P: Sqlite3Api> Connection<'p, P>

Source

pub fn create_scalar_function<F>( &self, name: &str, n_args: i32, func: F, ) -> Result<()>
where F: for<'a> FnMut(&Context<'a, P>, &[ValueRef<'a>]) -> Result<Value> + Send + 'static,

Register a scalar function (xFunc).

Source

pub fn create_aggregate_function<T, Init, Step, Final>( &self, name: &str, n_args: i32, init: Init, step: Step, final_fn: Final, ) -> Result<()>
where T: Send + 'static, Init: Fn() -> T + Send + 'static, Step: for<'a> FnMut(&Context<'a, P>, &mut T, &[ValueRef<'a>]) -> Result<()> + Send + 'static, Final: for<'a> FnMut(&Context<'a, P>, T) -> Result<Value> + Send + 'static,

Register an aggregate function (xStep/xFinal).

State is stored out-of-line in a Rust Box<T> and the SQLite aggregate context keeps only a pointer-sized slot, so T alignment does not depend on backend aggregate-context allocation alignment.

Source

pub fn create_window_function<T, Init, Step, Inverse, ValueFn, Final>( &self, name: &str, n_args: i32, init: Init, step: Step, inverse: Inverse, value_fn: ValueFn, final_fn: Final, ) -> Result<()>
where T: Send + 'static, Init: Fn() -> T + Send + 'static, Step: for<'a> FnMut(&Context<'a, P>, &mut T, &[ValueRef<'a>]) -> Result<()> + Send + 'static, Inverse: for<'a> FnMut(&Context<'a, P>, &mut T, &[ValueRef<'a>]) -> Result<()> + Send + 'static, ValueFn: for<'a> FnMut(&Context<'a, P>, &mut T) -> Result<Value> + Send + 'static, Final: for<'a> FnMut(&Context<'a, P>, T) -> Result<Value> + Send + 'static,

Register a window function (xStep/xInverse/xValue/xFinal).

State is stored out-of-line in a Rust Box<T> and the SQLite aggregate context keeps only a pointer-sized slot, so T alignment does not depend on backend aggregate-context allocation alignment.

Source§

impl<'p, P: Sqlite3Api> Connection<'p, P>

Source

pub fn create_module<T>(&self, name: &str) -> Result<()>
where P: Sqlite3Api<VTab = VTab<P, T>, VTabCursor = Cursor<P, T::Cursor>>, T: VirtualTable<P>,

Register a virtual table module using the default glue.

Trait Implementations§

Source§

impl<'p, P: Sqlite3Api> Drop for Connection<'p, P>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'p, P> Freeze for Connection<'p, P>

§

impl<'p, P> RefUnwindSafe for Connection<'p, P>

§

impl<'p, P> !Send for Connection<'p, P>

§

impl<'p, P> !Sync for Connection<'p, P>

§

impl<'p, P> Unpin for Connection<'p, P>

§

impl<'p, P> UnsafeUnpin for Connection<'p, P>

§

impl<'p, P> UnwindSafe for Connection<'p, P>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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