pub struct PreparedStatement { /* private fields */ }Expand description
A prepared statement for efficient repeated query execution.
Prepared statements allow you to define a query once and execute it multiple times with different parameters. This can improve performance by allowing query plan caching on the server.
§Example
ⓘ
let stmt = conn.prepare("MATCH (p:Person {id: $id}) RETURN p").await?;
for id in 1..=100 {
let mut params = HashMap::new();
params.insert("id".to_string(), Value::int(id));
let (page, _) = stmt.execute(&mut conn, ¶ms).await?;
// Process results...
}Implementations§
Source§impl PreparedStatement
impl PreparedStatement
Sourcepub fn new(query: impl Into<String>) -> Self
pub fn new(query: impl Into<String>) -> Self
Create a new prepared statement.
Extracts parameter names from the query (tokens starting with $).
Sourcepub fn param_names(&self) -> &[String]
pub fn param_names(&self) -> &[String]
Get the parameter names expected by this statement.
Sourcepub async fn execute(
&self,
conn: &mut Connection,
params: &HashMap<String, Value>,
) -> Result<(Page, Option<String>)>
pub async fn execute( &self, conn: &mut Connection, params: &HashMap<String, Value>, ) -> Result<(Page, Option<String>)>
Execute the prepared statement with the given parameters.
§Arguments
conn- The connection to execute onparams- Parameter values (must include all parameters in the query)
§Returns
A tuple of (Page, Option<String>) with results and optional warnings.
§Errors
Returns an error if required parameters are missing or if the query fails.
Trait Implementations§
Source§impl Clone for PreparedStatement
impl Clone for PreparedStatement
Source§fn clone(&self) -> PreparedStatement
fn clone(&self) -> PreparedStatement
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 moreAuto Trait Implementations§
impl Freeze for PreparedStatement
impl RefUnwindSafe for PreparedStatement
impl Send for PreparedStatement
impl Sync for PreparedStatement
impl Unpin for PreparedStatement
impl UnwindSafe for PreparedStatement
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request