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 ’aOwnedPreparedStatement- 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>
impl<'a> PreparedStatement<'a>
Sourcepub fn into_owned(&self) -> OwnedPreparedStatement
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 constraintsTrait Implementations§
Source§impl<'a> Clone for PreparedStatement<'a>
impl<'a> Clone for PreparedStatement<'a>
Source§fn clone(&self) -> PreparedStatement<'a>
fn clone(&self) -> PreparedStatement<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for PreparedStatement<'a>
impl<'a> Debug for PreparedStatement<'a>
Source§impl<'a> Display for PreparedStatement<'a>
impl<'a> Display for PreparedStatement<'a>
Source§impl From<OwnedPreparedStatement> for PreparedStatement<'_>
impl From<OwnedPreparedStatement> for PreparedStatement<'_>
Source§fn from(value: OwnedPreparedStatement) -> Self
fn from(value: OwnedPreparedStatement) -> Self
Source§impl<'a> From<PreparedStatement<'a>> for OwnedPreparedStatement
impl<'a> From<PreparedStatement<'a>> for OwnedPreparedStatement
Source§fn from(value: PreparedStatement<'a>) -> Self
fn from(value: PreparedStatement<'a>) -> Self
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more