toasty_core/driver/operation/raw_sql.rs
1use super::{Operation, TypedValue};
2
3use crate::stmt;
4
5/// Executes user-authored SQL against a SQL-capable driver.
6///
7/// Unlike [`QuerySql`](super::QuerySql), this operation carries backend SQL
8/// text directly. The driver does not serialize a Toasty statement AST before
9/// executing it.
10///
11/// The SQL text uses the placeholder syntax reported by
12/// [`Capability::sql_placeholder`](super::super::Capability::sql_placeholder).
13/// Parameters carry database storage types. The public raw SQL builders infer
14/// these from bound values and driver capabilities unless the caller supplies
15/// an explicit type.
16#[derive(Debug, Clone)]
17pub struct RawSql {
18 /// Backend SQL text to execute.
19 pub sql: String,
20
21 /// Typed bind parameters in placeholder order.
22 pub params: Vec<TypedValue>,
23
24 /// How the driver should execute and decode the SQL.
25 pub ret: RawSqlRet,
26}
27
28/// Return mode for a [`RawSql`] operation.
29#[derive(Debug, Clone)]
30pub enum RawSqlRet {
31 /// Execute as a statement and return an affected-row count.
32 None,
33
34 /// Execute as a query and infer result value types from driver metadata.
35 ///
36 /// Drivers should map backend-native result metadata to the closest
37 /// [`stmt::Value`](crate::stmt::Value) variant. Ambiguous backend values
38 /// may decode to their storage representation.
39 Infer,
40
41 /// Execute as a query using explicit result column type hints.
42 ///
43 /// Type hints affect decoding only; drivers must execute the SQL text
44 /// unchanged.
45 Types(Vec<stmt::Type>),
46}
47
48impl Operation {
49 /// Returns `true` if this is a [`RawSql`](Operation::RawSql) operation.
50 pub fn is_raw_sql(&self) -> bool {
51 matches!(self, Operation::RawSql(_))
52 }
53}
54
55impl From<RawSql> for Operation {
56 fn from(value: RawSql) -> Self {
57 Self::RawSql(value)
58 }
59}