pub struct Query { /* private fields */ }Expand description
A raw SQL query that returns dynamic rows.
Create one with query.
Implementations§
Source§impl Query
impl Query
Sourcepub fn bind(self, value: impl Into<Value>) -> Query
pub fn bind(self, value: impl Into<Value>) -> Query
Bind a value using the executor driver’s default database type for that value.
Values are bound in the order this method is called. Use
bind_typed for NULL, empty lists, or values
whose database type cannot be inferred from the value alone.
Sourcepub fn bind_typed(self, value: impl Into<Value>, ty: Type) -> Query
pub fn bind_typed(self, value: impl Into<Value>, ty: Type) -> Query
Bind a value with an explicit database type.
This is useful for NULL, empty lists, or backend-specific column
types.
Sourcepub fn column_types(self, types: impl IntoIterator<Item = Type>) -> Query
pub fn column_types(self, types: impl IntoIterator<Item = Type>) -> Query
Provide result column type hints for ambiguous backend values.
Hints affect result decoding only. They do not change the SQL sent to the database. Use this when backend metadata is not enough to choose the desired Toasty value type.
use toasty::stmt;
let rows = toasty::sql::query(
"SELECT id, enabled FROM users WHERE id = ?1",
)
.bind(1_i64)
.column_types([stmt::Type::I64, stmt::Type::Bool])
.exec(&mut db)
.await?;Sourcepub async fn exec(
self,
executor: &mut dyn Executor,
) -> Result<Vec<Value>, Error>
pub async fn exec( self, executor: &mut dyn Executor, ) -> Result<Vec<Value>, Error>
Execute the query and return dynamic rows.
Each row is a Value::Record with fields in selected-column order.
The executor may be a Db, Connection,
or Transaction.