pub struct OwnedPreparedStatement {
pub inner: OwnedPreparedStatement<OwnedPostgresValue>,
}Expand description
Owned PostgreSQL prepared statement wrapper.
This is the owned counterpart to PreparedStatement that doesn’t have any lifetime
constraints. All data is owned by this struct, making it suitable for long-term storage,
caching, or passing across thread boundaries.
§Use Cases
- Caching: Store prepared statements in a cache for reuse
- Multi-threading: Pass prepared statements between threads (with tokio-postgres)
- Long-term storage: Keep prepared statements in application state
- Query reuse: Execute the same query with different parameters efficiently
§Examples
ⓘ
use drizzle_postgres::builder::{QueryBuilder, PreparedStatement, OwnedPreparedStatement};
use drizzle_macros::{PostgresTable, PostgresSchema};
use drizzle_core::{ToSQL, SQL};
#[PostgresTable(name = "users")]
struct User {
#[column(serial, primary)]
id: i32,
name: String,
}
#[derive(PostgresSchema)]
struct Schema {
user: User,
}
let builder = QueryBuilder::new::<Schema>();
let Schema { user } = Schema::new();
// Create a prepared statement and convert to owned
let prepared = builder
.select(user.name)
.from(user)
.prepare();
let owned: OwnedPreparedStatement = prepared.into_owned();
// Owned can be stored in a HashMap for reuse
// let mut cache: HashMap<String, OwnedPreparedStatement> = HashMap::new();
// cache.insert("select_user_name".to_string(), owned);§Conversion
You can convert between borrowed and owned forms:
PreparedStatement::into_owned()→OwnedPreparedStatementOwnedPreparedStatement→PreparedStatement(viaFromtrait)
Fields§
§inner: OwnedPreparedStatement<OwnedPostgresValue>Trait Implementations§
Source§impl Clone for OwnedPreparedStatement
impl Clone for OwnedPreparedStatement
Source§fn clone(&self) -> OwnedPreparedStatement
fn clone(&self) -> OwnedPreparedStatement
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OwnedPreparedStatement
impl Debug for OwnedPreparedStatement
Source§impl Display for OwnedPreparedStatement
impl Display for OwnedPreparedStatement
Source§impl From<OwnedPreparedStatement> for PreparedStatement<'_>
impl From<OwnedPreparedStatement> for PreparedStatement<'_>
Source§fn from(value: OwnedPreparedStatement) -> Self
fn from(value: OwnedPreparedStatement) -> Self
Converts to this type from the input type.
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
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for OwnedPreparedStatement
impl RefUnwindSafe for OwnedPreparedStatement
impl Send for OwnedPreparedStatement
impl Sync for OwnedPreparedStatement
impl Unpin for OwnedPreparedStatement
impl UnwindSafe for OwnedPreparedStatement
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
Mutably borrows from an owned value. Read more
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>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read more