Skip to main content

ModelInsert

Struct ModelInsert 

Source
pub struct ModelInsert<M: Table> { /* private fields */ }
Expand description

A pending model INSERT: the three-state setter, held unbuilt so Table::before_insert can still rewrite it once an executor is in hand.

That deferral is why this wrapper, unlike the others, stores extra mods as closures (with) instead of applying them eagerly: there is no statement to apply them to until the verb runs.

Implementations§

Source§

impl<M: Table> ModelInsert<M>

Source

pub fn with(self, mods: impl Mod<M::Insert> + Send + 'static) -> Self

Defer Layer 1 mods onto the eventual INSERT statement — .with(insert::on_conflict(…).do_nothing()) is how an upsert or any other dialect feature mixes into a typed insert.

Source

pub async fn one(self, db: &dyn Executor) -> Result<M::Row, ExecError>

Insert and hand back the one inserted row, via the statement’s RETURNING. Zero returned rows is ExecError::RowNotFound — on a dialect without RETURNING (MySQL) the generated model supplies its own read-back instead of this verb; see the crate docs.

Source

pub async fn exec(self, db: &dyn Executor) -> Result<ExecResult, ExecError>

Insert for the side effect. Table::after_insert still runs, with an empty row slice.

Trait Implementations§

Source§

impl<M: Table> Debug for ModelInsert<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for ModelInsert<M>

§

impl<M> !Sync for ModelInsert<M>

§

impl<M> !UnwindSafe for ModelInsert<M>

§

impl<M> Freeze for ModelInsert<M>
where <M as Table>::Setter: Freeze,

§

impl<M> Send for ModelInsert<M>

§

impl<M> Unpin for ModelInsert<M>
where <M as Table>::Setter: Unpin,

§

impl<M> UnsafeUnpin for ModelInsert<M>
where <M as Table>::Setter: UnsafeUnpin,

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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.