Skip to main content

SqlConn

Trait SqlConn 

Source
pub trait SqlConn:
    MaybeSend
    + MaybeSync
    + Clone
    + 'static {
    // Required methods
    fn exec(&self, sql: &str, params: &[SqlValue]) -> Result<u64, SqlError>;
    fn query(
        &self,
        sql: &str,
        params: &[SqlValue],
    ) -> Result<Vec<Row>, SqlError>;
    fn transaction<T: 'static>(&self, f: TxFn<Self, T>) -> Result<T, SqlError>;
    fn now_ms(&self) -> u64;
    fn size_bytes(&self) -> Result<u64, SqlError>;

    // Provided methods
    fn set_size_limit(&self, bytes: u64) -> Result<(), SqlError> { ... }
    fn backup_to(&self, dest: &str) -> Result<(), StoreError> { ... }
}
Expand description

A synchronous SQL connection: a cheaply cloneable handle (rusqlite: a shared, locked Connection; a Durable Object: its storage handle).

Synchronous on purpose: Durable Object sql.exec and transactionSync are synchronous, and so is rusqlite. A native host runs a store over it on a blocking thread.

Required Methods§

Source

fn exec(&self, sql: &str, params: &[SqlValue]) -> Result<u64, SqlError>

Run one statement that returns no rows; the number of rows changed.

Source

fn query(&self, sql: &str, params: &[SqlValue]) -> Result<Vec<Row>, SqlError>

Run one statement and collect its rows.

Source

fn transaction<T: 'static>(&self, f: TxFn<Self, T>) -> Result<T, SqlError>

Run f atomically and synchronously: commit if it returns Ok, roll back if it returns Err or panics. f receives a handle for its statements.

An implementation never issues transaction-control SQL itself: Durable Objects reject those statements and require storage.transactionSync; rusqlite uses its Transaction type. f never awaits, which is what makes apply cancellation-safe (normative rule 4).

f is owned and 'static (not a borrowed FnMut): the Durable Object bridge wraps it in a 'static wasm-bindgen closure, and this crate forbids unsafe.

Source

fn now_ms(&self) -> u64

The backend’s own clock, Unix ms, for Precondition::NotAfter (normative rule 8): the host’s system clock natively, Date.now() on a Durable Object. A reading before the epoch is u64::MAX, so every deadline fails closed.

Source

fn size_bytes(&self) -> Result<u64, SqlError>

Bytes the database uses, for the soft cap (Capacity): pages holding data (natively (page_count - freelist_count) * page_size; free pages are reused before the file grows), databaseSize on a Durable Object. Called inside a transaction.

Provided Methods§

Source

fn set_size_limit(&self, bytes: u64) -> Result<(), SqlError>

Enforce a hard size limit of about bytes at the engine (natively max_page_count). The default does nothing: a Durable Object has a fixed limit of its own, which the Capacity must not exceed.

Source

fn backup_to(&self, dest: &str) -> Result<(), StoreError>

Write a consistent backend-native backup of the whole database to dest (natively a file path, via VACUUM INTO). The default is StoreError::Unsupported: back such a backend up with the portable export (store::export_partition).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§