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>
impl<M: Table> ModelInsert<M>
Sourcepub fn with(self, mods: impl Mod<M::Insert> + Send + 'static) -> Self
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.
Sourcepub async fn one(self, db: &dyn Executor) -> Result<M::Row, ExecError>
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.
Sourcepub async fn exec(self, db: &dyn Executor) -> Result<ExecResult, ExecError>
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.