toasty_core/driver/operation/query_sql.rs
1use super::{Operation, TypedValue};
2
3use crate::stmt;
4
5/// Executes a SQL statement against the database.
6///
7/// Only sent to SQL-capable drivers (those with [`Capability::sql`](super::super::Capability)
8/// set to `true`). The statement is a fully lowered [`stmt::Statement`] that
9/// the SQL serialization layer converts into a backend-specific SQL string.
10///
11/// # Examples
12///
13/// ```ignore
14/// use toasty_core::driver::operation::{QuerySql, Operation};
15///
16/// let op = QuerySql {
17/// stmt: sql_statement,
18/// params: vec![],
19/// ret: Some(vec![stmt::Type::String, stmt::Type::I64]),
20/// };
21/// let operation: Operation = op.into();
22/// assert!(operation.is_query_sql());
23/// ```
24#[derive(Debug, Clone)]
25pub struct QuerySql {
26 /// The SQL statement to execute. Scalar values that should be sent as
27 /// bind parameters have been replaced with `Expr::Arg(n)` where `n` is
28 /// the index into [`params`](Self::params).
29 pub stmt: stmt::Statement,
30
31 /// Typed bind parameters extracted from the statement. Each entry
32 /// corresponds to an `Expr::Arg(n)` placeholder in the statement.
33 pub params: Vec<TypedValue>,
34
35 /// The types of columns in the result set. When `Some`, the driver uses
36 /// these types to decode returned rows. When `None`, the statement does
37 /// not return rows (e.g., `DELETE` without `RETURNING`).
38 pub ret: Option<Vec<stmt::Type>>,
39}
40
41impl Operation {
42 /// Returns `true` if this is a [`QuerySql`](Operation::QuerySql) operation.
43 pub fn is_query_sql(&self) -> bool {
44 matches!(self, Operation::QuerySql(_))
45 }
46}
47
48impl From<QuerySql> for Operation {
49 fn from(value: QuerySql) -> Self {
50 Self::QuerySql(value)
51 }
52}