Skip to main content

toasty_core/driver/operation/
insert.rs

1use super::{Operation, TypedValue};
2
3use crate::stmt;
4
5/// Inserts one or more records into a table.
6///
7/// Contains a lowered [`stmt::Statement`] (always an insert statement) and an
8/// optional return type describing the columns the driver should return after
9/// the insert (e.g., auto-generated keys).
10///
11/// # Examples
12///
13/// ```ignore
14/// use toasty_core::driver::operation::{Insert, Operation};
15///
16/// let op = Insert {
17///     stmt: insert_statement,
18///     params: vec![],
19///     ret: Some(vec![stmt::Type::I64]),
20/// };
21/// let operation: Operation = op.into();
22/// ```
23#[derive(Debug, Clone)]
24pub struct Insert {
25    /// The insert statement to execute. Scalar values that should be sent as
26    /// bind parameters have been replaced with `Expr::Arg(n)` where `n` is
27    /// the index into [`params`](Self::params).
28    pub stmt: stmt::Statement,
29
30    /// Typed bind parameters extracted from the statement.
31    pub params: Vec<TypedValue>,
32
33    /// The types of values the insert must return. SQL backends with native
34    /// mutation `RETURNING` decode its projected rows. A backend may also
35    /// provide an exact operation-specific result, such as MySQL's generated
36    /// ID for a single-row insert. When `None`, no rows are returned.
37    pub ret: Option<Vec<stmt::Type>>,
38}
39
40impl From<Insert> for Operation {
41    fn from(value: Insert) -> Self {
42        Self::Insert(value)
43    }
44}