toasty_core/driver/operation/insert.rs
1use super::Operation;
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.
25 pub stmt: stmt::Statement,
26
27 /// The types of columns to return from the insert. When `Some`, the driver
28 /// should return the inserted row(s) projected to these types (e.g.,
29 /// auto-increment IDs). When `None`, no rows are returned.
30 pub ret: Option<Vec<stmt::Type>>,
31}
32
33impl From<Insert> for Operation {
34 fn from(value: Insert) -> Self {
35 Self::Insert(value)
36 }
37}