pub struct Statement { /* private fields */ }
Expand description
named prepared postgres statement without information of which Client
it belongs to and lifetime
cycle management
this type is used as entry point for other statement types like StatementGuarded
and StatementUnnamed
.
itself is rarely directly used and main direct usage is for statement caching where owner of it is tasked
with manual management of it’s association and lifetime
Implementations§
Source§impl Statement
impl Statement
Sourcepub const fn named<'a>(stmt: &'a str, types: &'a [Type]) -> StatementNamed<'a>
pub const fn named<'a>(stmt: &'a str, types: &'a [Type]) -> StatementNamed<'a>
construct a new named statement.
must be called with Execute::execute
method for making a prepared statement.
Sourcepub const fn unnamed<'a>(
stmt: &'a str,
types: &'a [Type],
) -> StatementUnnamed<'a>
pub const fn unnamed<'a>( stmt: &'a str, types: &'a [Type], ) -> StatementUnnamed<'a>
construct a new unnamed statement. unnamed statement can bind to it’s parameter values without being prepared by database.
Sourcepub fn bind<P>(&self, params: P) -> StatementQuery<'_, P>where
P: AsParams,
pub fn bind<P>(&self, params: P) -> StatementQuery<'_, P>where
P: AsParams,
bind self to typed value parameters where they are encoded into a valid sql query in binary format
§Examples
// prepare a statement with typed parameters.
let stmt = Statement::named("SELECT * FROM users WHERE id = $1 AND age = $2", &[Type::INT4, Type::INT4])
.execute(&cli).await?;
// bind statement to typed value parameters and start query
let row_stream = stmt.bind([9527_i32, 18]).query(&cli).await?;
Sourcepub fn bind_dyn<'p, 't>(
&self,
params: &'p [&'t (dyn ToSql + Sync)],
) -> StatementQuery<'_, impl ExactSizeIterator<Item = &'t (dyn ToSql + Sync)> + 'p>
pub fn bind_dyn<'p, 't>( &self, params: &'p [&'t (dyn ToSql + Sync)], ) -> StatementQuery<'_, impl ExactSizeIterator<Item = &'t (dyn ToSql + Sync)> + 'p>
Statement::bind for dynamic typed parameters
§Examples
// bind to a dynamic typed slice where items have it's own concrete type.
let bind = statement.bind_dyn(&[&9527i32, &"nobody"]);
Sourcepub fn columns(&self) -> &[Column]
pub fn columns(&self) -> &[Column]
Returns information about the columns returned when the statement is queried.
Sourcepub fn into_guarded<C>(self, cli: &C) -> StatementGuarded<'_, C>where
C: Query,
pub fn into_guarded<C>(self, cli: &C) -> StatementGuarded<'_, C>where
C: Query,
Convert self to a drop guarded statement which would cancel on drop.