PreparedStatement

Struct PreparedStatement 

Source
pub struct PreparedStatement<'a> {
    pub inner: PreparedStatement<'a, SQLiteValue<'a>>,
}
Expand description

SQLite-specific prepared statement wrapper.

A prepared statement represents a compiled SQL query with placeholder parameters that can be executed multiple times with different parameter values. This wrapper provides SQLite-specific functionality while maintaining compatibility with the core Drizzle prepared statement infrastructure.

§Features

  • Parameter Binding: Safely bind values to SQL placeholders
  • Reusable Execution: Execute the same query multiple times efficiently
  • Memory Management: Automatic handling of borrowed/owned lifetimes
  • Type Safety: Compile-time verification of parameter types

§Basic Usage

use drizzle_sqlite::builder::QueryBuilder;
use drizzle_macros::{SQLiteTable, SQLiteSchema};
use drizzle_core::{ToSQL, expressions::eq};

#[SQLiteTable(name = "users")]
struct User {
    #[integer(primary)]
    id: i32,
    #[text]
    name: String,
}

#[derive(SQLiteSchema)]
struct Schema {
    user: User,
}

let builder = QueryBuilder::new::<Schema>();
let Schema { user } = Schema::new();

// Build query that will become a prepared statement
let query = builder
    .select(user.name)
    .from(user)
    .r#where(eq(user.id, drizzle_core::Placeholder::question()));

// Convert to prepared statement (this would typically be done by the driver)
let sql = query.to_sql();
println!("SQL: {}", sql.sql());  // "SELECT "users"."name" FROM "users" WHERE "users"."id" = ?"

§Lifetime Management

The prepared statement can be converted between borrowed and owned forms:

  • PreparedStatement<'a> - Borrows data with lifetime ’a
  • OwnedPreparedStatement - Owns all data, no lifetime constraints

This allows for flexible usage patterns depending on whether you need to store the prepared statement long-term or use it immediately.

Fields§

§inner: PreparedStatement<'a, SQLiteValue<'a>>

Implementations§

Source§

impl<'a> PreparedStatement<'a>

Source

pub fn into_owned(&self) -> OwnedPreparedStatement

Converts this borrowed prepared statement into an owned one.

This method clones all the internal data to create an OwnedPreparedStatement that doesn’t have any lifetime constraints. This is useful when you need to store the prepared statement beyond the lifetime of the original query builder.

§Examples
// Convert borrowed to owned for long-term storage
let owned = prepared_statement.into_owned();

// Now `owned` can be stored without lifetime constraints

Trait Implementations§

Source§

impl<'a> Clone for PreparedStatement<'a>

Source§

fn clone(&self) -> PreparedStatement<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for PreparedStatement<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Display for PreparedStatement<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<OwnedPreparedStatement> for PreparedStatement<'_>

Source§

fn from(value: OwnedPreparedStatement) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<PreparedStatement<'a>> for OwnedPreparedStatement

Source§

fn from(value: PreparedStatement<'a>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for PreparedStatement<'a>

§

impl<'a> RefUnwindSafe for PreparedStatement<'a>

§

impl<'a> Send for PreparedStatement<'a>

§

impl<'a> Sync for PreparedStatement<'a>

§

impl<'a> Unpin for PreparedStatement<'a>

§

impl<'a> UnwindSafe for PreparedStatement<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToCompactString for T
where T: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.