Skip to main content

Connection

Struct Connection 

Source
pub struct Connection { /* private fields */ }
Expand description

A SQLite database connection.

Closed when dropped. Not Sync – all access must happen from a single thread (matches the WASM single-thread constraint and the native Mutex-guarded usage in CredentialStoreInner).

Implementations§

Source§

impl Connection

Source

pub fn open(path: &Path, read_only: bool) -> DbResult<Self>

Opens (or creates) a database at path.

§Errors

Returns Error if SQLite cannot open the file.

Source

pub fn execute_batch(&self, sql: &str) -> DbResult<()>

Executes one or more SQL statements separated by semicolons.

No result rows are returned. Suitable for DDL, PRAGMAs, and multi-statement scripts.

§Errors

Returns Error if any statement fails.

Source

pub fn execute_batch_zeroized(&self, sql: &str) -> DbResult<()>

Like execute_batch but zeroizes the internal C string buffer after execution. Use for SQL containing sensitive material (e.g. PRAGMA key).

§Errors

Returns Error if the statement fails.

Source

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

Prepares a single SQL statement.

§Errors

Returns Error if the SQL is invalid.

Source

pub fn execute(&self, sql: &str, params: &[Value]) -> DbResult<usize>

Prepares and executes a single SQL statement with the given parameters.

Returns the number of rows changed.

§Errors

Returns Error if preparation or execution fails.

Source

pub fn query_row<T>( &self, sql: &str, params: &[Value], mapper: impl FnOnce(&Row<'_, '_>) -> DbResult<T>, ) -> DbResult<T>

Prepares and executes a statement, mapping exactly one result row.

Returns an error if no row is returned.

§Errors

Returns Error if preparation, execution, or the mapper fails, or if the query returns no rows.

Source

pub fn query_row_optional<T>( &self, sql: &str, params: &[Value], mapper: impl FnOnce(&Row<'_, '_>) -> DbResult<T>, ) -> DbResult<Option<T>>

Like query_row but returns Ok(None) when no row is returned.

§Errors

Returns Error if preparation, execution, or the mapper fails.

Source

pub fn transaction(&self) -> DbResult<Transaction<'_>>

Begins a deferred transaction.

§Errors

Returns Error if BEGIN DEFERRED fails.

Source

pub fn transaction_immediate(&self) -> DbResult<Transaction<'_>>

Begins an immediate transaction (acquires a RESERVED lock right away).

§Errors

Returns Error if BEGIN IMMEDIATE fails.

Source

pub fn last_insert_rowid(&self) -> i64

Returns the rowid of the most recent successful INSERT.

Source

pub fn changes(&self) -> usize

Returns the number of rows changed by the most recent statement.

Trait Implementations§

Source§

impl Debug for Connection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.