pub struct InsertSeed<D, T> { /* private fields */ }Implementations§
Source§impl<D, T: Table> InsertSeed<D, T>
impl<D, T: Table> InsertSeed<D, T>
pub fn values<R: InsertRow<Table = T>>(self, row: R) -> Insert<D, R>
Sourcepub fn select<Scope, Sel, SelIdx, TgtIdx>(
self,
query: &Select<D, Scope, Sel>,
) -> InsertSelect<D, T>where
D: Dialect,
T: WrittenColumns,
T::Columns: ColumnList<WrittenTable<T>, TgtIdx>,
<<T as WrittenColumns>::Columns as ColumnList<WrittenTable<T>, TgtIdx>>::Fields<RowNil>: ColumnNames,
Sel: Selection<Scope, SelIdx>,
Sel::Output: SameShape<Row<<<T as WrittenColumns>::Columns as ColumnList<WrittenTable<T>, TgtIdx>>::Fields<RowNil>>>,
pub fn select<Scope, Sel, SelIdx, TgtIdx>(
self,
query: &Select<D, Scope, Sel>,
) -> InsertSelect<D, T>where
D: Dialect,
T: WrittenColumns,
T::Columns: ColumnList<WrittenTable<T>, TgtIdx>,
<<T as WrittenColumns>::Columns as ColumnList<WrittenTable<T>, TgtIdx>>::Fields<RowNil>: ColumnNames,
Sel: Selection<Scope, SelIdx>,
Sel::Output: SameShape<Row<<<T as WrittenColumns>::Columns as ColumnList<WrittenTable<T>, TgtIdx>>::Fields<RowNil>>>,
INSERT INTO t (..) SELECT ..: the rows a query produces, checked
against the target’s own row by row::SameShape, the same one
comparison a UNION branch and a CTE body go through.
The query fills every column the target lets a statement write: all
of them but the generated ones, which the database writes itself and
refuses a value for. That is the target’s order too, which is its
#[derive(Table)] field order with the generated fields left out.
SameShape walks the two lists together, so the source’s columns
must be spelled and typed as the target’s and come in that order.
Order because SQL fills an INSERT’s column list by position, and
the rendered header is read off the same list this is checked
against. SQL would widen an INTEGER into a BIGINT and take a NOT
NULL value for a nullable column, and neither is accepted here. A
source column under another name takes a label!{} one.
Known limitations: the source is a Select, so a SetOp
(UNION) or a DynSelect cannot be one; a one-column target still
needs a one-tuple (select((t::only,))), since a bare selection is
a value rather than a row.
Sourcepub fn values_all<R: InsertRow<Table = T> + Insertable>(
self,
rows: impl IntoIterator<Item = R>,
) -> Result<Insert<D, R>, NothingToInsert>
pub fn values_all<R: InsertRow<Table = T> + Insertable>( self, rows: impl IntoIterator<Item = R>, ) -> Result<Insert<D, R>, NothingToInsert>
Every row of a collection at once: the shape a bulk import has,
where the rows are already in a Vec and the first one isn’t
special. INSERT with no rows has no SQL form, so an empty
collection is refused here rather than rendered.