Skip to main content

Statement

Trait Statement 

Source
pub trait Statement: Sealed {
    type Dialect: Dialect;
    type Table: Table;

    // Provided methods
    fn to_sql(&self, _dialect: Self::Dialect) -> (String, Vec<Value>) { ... }
    fn returning<Sel, Idx>(self, sel: Sel) -> Returning<Self, Sel>
       where Self: Sized,
             Self::Dialect: SupportsReturning,
             Sel: Selection<WrittenTable<Self::Table>, Idx> { ... }
}
Expand description

A statement that writes to a single table. Sealed: the three writing statements are the whole set, and Returning is defined against this rather than against each of them.

Required Associated Types§

Provided Methods§

Source

fn to_sql(&self, _dialect: Self::Dialect) -> (String, Vec<Value>)

The dialect is an argument for the reason Select::to_sql’s is.

Source

fn returning<Sel, Idx>(self, sel: Sel) -> Returning<Self, Sel>
where Self: Sized, Self::Dialect: SupportsReturning, Sel: Selection<WrittenTable<Self::Table>, Idx>,

RETURNING, on whichever of the three this is. The clause is the same clause. A distinct type rather than Self with a flag set: the execution layer needs Sel’s concrete type to know what to decode a returned row into, and an optional field would erase it.

The selection is checked against WrittenTable, which is this statement’s own row.

Known limitation: SQL’s RETURNING reaches further. A scalar subquery there is the deferral Select::contains states, and the joined columns an UPDATE .. FROM / DELETE .. USING lets it name need those clauses, which aren’t built either. Bind this statement as a CTE body (cte::with) and join from the outer query instead: that is checked, and the write and the read it feeds stay one statement.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<D: Dialect, R: InsertRow> Statement for Insert<D, R>

Source§

impl<D: Dialect, T: Table> Statement for Delete<D, T>

Source§

impl<D: Dialect, T: Table> Statement for InsertSelect<D, T>

Source§

impl<D: Dialect, T: Table> Statement for Update<D, T>