Skip to main content

InsertSeed

Struct InsertSeed 

Source
pub struct InsertSeed<D, T> { /* private fields */ }

Implementations§

Source§

impl<D, T: Table> InsertSeed<D, T>

Source

pub fn values<R: InsertRow<Table = T>>(self, row: R) -> Insert<D, R>

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<D, T> Freeze for InsertSeed<D, T>
where PhantomData<fn() -> (D, T)>: Freeze,

§

impl<D, T> RefUnwindSafe for InsertSeed<D, T>

§

impl<D, T> Send for InsertSeed<D, T>
where PhantomData<fn() -> (D, T)>: Send,

§

impl<D, T> Sync for InsertSeed<D, T>
where PhantomData<fn() -> (D, T)>: Sync,

§

impl<D, T> Unpin for InsertSeed<D, T>
where PhantomData<fn() -> (D, T)>: Unpin,

§

impl<D, T> UnsafeUnpin for InsertSeed<D, T>

§

impl<D, T> UnwindSafe for InsertSeed<D, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<S> Superset<Nil, Nil> for S

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WrapNullable<NotNull> for T