toasty_core/driver/operation/
query_sql.rs

1use super::Operation;
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///     ret: Some(vec![stmt::Type::String, stmt::Type::I64]),
19///     last_insert_id_hack: None,
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.
27    pub stmt: stmt::Statement,
28
29    /// The types of columns in the result set. When `Some`, the driver uses
30    /// these types to decode returned rows. When `None`, the statement does
31    /// not return rows (e.g., `DELETE` without `RETURNING`).
32    pub ret: Option<Vec<stmt::Type>>,
33
34    /// **Temporary MySQL workaround** for `RETURNING` from `INSERT`.
35    ///
36    /// When set, the driver should fetch `LAST_INSERT_ID()` to simulate
37    /// `RETURNING` behavior for the specified number of inserted rows.
38    /// Non-MySQL drivers should assert this is `None`.
39    pub last_insert_id_hack: Option<u64>,
40}
41
42impl Operation {
43    /// Returns `true` if this is a [`QuerySql`](Operation::QuerySql) operation.
44    pub fn is_query_sql(&self) -> bool {
45        matches!(self, Operation::QuerySql(_))
46    }
47}
48
49impl From<QuerySql> for Operation {
50    fn from(value: QuerySql) -> Self {
51        Self::QuerySql(value)
52    }
53}