tank_core/query/prepared.rs
1use crate::{AsValue, QueryMetadata, Result};
2use std::{
3 any::Any,
4 fmt::{Debug, Display},
5};
6
7/// A parameterized, backend-prepared query handle.
8///
9/// `Prepared` enables drivers to pre-parse / optimize SQL statements and later
10/// bind positional parameters. Values are converted via the `AsValue` trait.
11///
12/// # Binding Semantics
13/// * `bind` appends a value (driver chooses actual placeholder numbering).
14/// * `bind_index` sets the parameter at `index` (zero-based).
15///
16/// Methods return `&mut Self` for fluent chaining:
17/// ```ignore
18/// prepared.bind(42)?.bind("hello")?;
19/// ```
20pub trait Prepared: Any + Send + Sync + Display + Debug {
21 fn as_any(self: Box<Self>) -> Box<dyn Any>;
22 /// Clear all bound values.
23 fn clear_bindings(&mut self) -> Result<&mut Self>
24 where
25 Self: Sized;
26 /// Append a bound value.
27 fn bind(&mut self, value: impl AsValue) -> Result<&mut Self>
28 where
29 Self: Sized;
30 /// Bind a value at a specific index.
31 fn bind_index(&mut self, value: impl AsValue, index: u64) -> Result<&mut Self>
32 where
33 Self: Sized;
34 /// Get QueryMetadata
35 fn metadata(&self) -> &QueryMetadata;
36 /// Get mutable QueryMetadata
37 fn metadata_mut(&mut self) -> &mut QueryMetadata;
38}