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///     ret: Some(vec![stmt::Type::I64]),
19/// };
20/// let operation: Operation = op.into();
21/// ```
22#[derive(Debug, Clone)]
23pub struct Insert {
24    /// The insert statement to execute. Scalar values that should be sent as
25    /// bind parameters have been replaced with `Expr::Arg(n)` where `n` is
26    /// the index into [`params`](Self::params).
27    pub stmt: stmt::Statement,
28
29    /// Typed bind parameters extracted from the statement.
30    pub params: Vec<TypedValue>,
31
32    /// The types of columns to return from the insert. When `Some`, the driver
33    /// should return the inserted row(s) projected to these types (e.g.,
34    /// auto-increment IDs). When `None`, no rows are returned.
35    pub ret: Option<Vec<stmt::Type>>,
36}
37
38impl From<Insert> for Operation {
39    fn from(value: Insert) -> Self {
40        Self::Insert(value)
41    }
42}