Rindle docs and package mapSkip to main content

StatementCache

Struct StatementCache 

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

The prepared-statement cache for a SQLite source (05 §4.3). Owns the connection (Rc<Connection>, mirroring the spec’s Rc<Db> so the cache can live alongside the per-snapshot write statements and be rebound on a Snapshotter leapfrog, 05 §5.7) and lends out PooledStmt RAII guards.

The actual statement storage is rusqlite’s per-connection cache, reached via [Connection::prepare_cached]; this type adds (1) the PooledStmt checkout handle — the single place to hang the scanStatus capture-on-drop hook (05 §13 Q8, deferred) — and (2) open-cursor accounting (README Primitive #2), so a test can prove the statement was released even on an early break.

Implementations§

Source§

impl StatementCache

Source

pub fn new(conn: Rc<Connection>) -> StatementCache

Wrap conn with the default LRU capacity (DEFAULT_CAPACITY).

Source

pub fn with_capacity(conn: Rc<Connection>, capacity: usize) -> StatementCache

Wrap conn and set the LRU capacity (number of distinct cached SQL statements retained). 0 disables caching (every get prepares fresh).

Source

pub fn set_capacity(&self, capacity: usize)

Re-bound the LRU capacity. Resolves 05 §13 Q7 (the server-side memory-footprint bound) without the JS external drop(n).

Source

pub fn flush(&self)

Finalize every cached statement (drops the LRU contents). The bounded analogue of the JS drop(size); e.g. on schema change before a re-prepare.

Source

pub fn conn(&self) -> &Rc<Connection>

The wrapped connection — needed by the source to prepare the write statements (insert/delete/update/checkExists/getExisting, 05 §4.3) that are held for a snapshot’s lifetime rather than cache-checked-out per fetch.

Source

pub fn open_cursors(&self) -> i64

Cursors currently checked out (Primitive #2 accounting). 0 when every PooledStmt has been dropped — i.e. no statement is mid-iteration and the connection is free for a write.

Source

pub fn get(&self, sql: &str) -> Result<PooledStmt<'_>>

Check out a prepared statement for sql, removed from the cache while in use (a SQLite statement is not reentrant — 05 §3.10). Returns a PooledStmt RAII guard that returns the statement to the cache on Drop.

A concurrent get for the same sql while this one is checked out finds the slot empty and prepares a fresh statement (rusqlite cache.rs:147), so the two iterate independently — the self-join / reentrant-fetch case.

Fails only if sql is not valid SQL on this connection — a builder bug in practice, since fetch SQL is emitted by build_select_query (05 §4.4). Surfaced as a Result rather than hidden (foundations §10).

Source

pub fn with<T>( &self, sql: &str, f: impl FnOnce(&mut PooledStmt<'_>) -> T, ) -> Result<T>

Check out a statement, run f against it, and return it to the cache — the port of the JS StatementCache.use (statement-cache.ts:103-110) and the StatementRunner one-liners (zero-cache/db/statements.ts). The statement is released when f returns (or unwinds), automatically.

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

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

§

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

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,