Skip to main content

CachedStatement

Struct CachedStatement 

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

A prepared statement suitable for caching and re-execution. A prepared statement that can be reset and re-executed with different bindings.

Unlike Statement, CachedStatement is not tied to a connection’s lifetime. It remains valid as long as the underlying database is open.

This type is used by Diesel statement cache (StatementCache<DuckDb, CachedStatement>).

Implementations§

Source§

impl CachedStatement

Source

pub fn prepare(conn: &RawConnection, sql: impl AsRef<str>) -> Result<Self>

Prepares sql against the given connection.

§Errors

Returns Error::DuckDBFailure if DuckDB cannot parse or plan the query, or Error::NulError if sql contains an interior nul byte.

Source

pub fn reset_bindings(&mut self) -> Result<()>

Resets all parameter bindings so the statement can be re-executed.

§Errors

Returns Error::DuckDBFailure if the DuckDB clear-bindings call fails.

Source

pub fn bind<T: AppendAble + ?Sized>( &mut self, idx: u64, value: &mut T, ) -> Result<()>

Binds value at the given 1-based parameter index.

§Errors

Returns an error if the underlying DuckDB bind call fails or idx is out of range.

Source

pub fn execute(&mut self) -> Result<DuckResult>

Executes the prepared statement and returns the result.

Works for all statement types:

  • SELECT — iterate rows via the Iterator impl on DuckResult.
  • INSERT / UPDATE / DELETE — check DuckResult::changes() for affected rows.
  • DDL (CREATE TABLE etc.) — .changes() returns 0, no rows to iterate.
  • INSERT … RETURNING — iterate rows and/or call .changes().
§Errors

Returns Error::DuckDBFailure if execution fails.

Trait Implementations§

Source§

impl Drop for CachedStatement

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for CachedStatement

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.