pub struct CreateOperation<E: QueryEngine, M: Model> { /* private fields */ }Expand description
Implementations§
Source§impl<E: QueryEngine, M: Model + FromRow> CreateOperation<E, M>
impl<E: QueryEngine, M: Model + FromRow> CreateOperation<E, M>
Sourcepub fn set(
self,
column: impl Into<String>,
value: impl Into<FilterValue>,
) -> Self
pub fn set( self, column: impl Into<String>, value: impl Into<FilterValue>, ) -> Self
Set a column value.
Sourcepub fn set_many(
self,
values: impl IntoIterator<Item = (impl Into<String>, impl Into<FilterValue>)>,
) -> Self
pub fn set_many( self, values: impl IntoIterator<Item = (impl Into<String>, impl Into<FilterValue>)>, ) -> Self
Set multiple column values from an iterator.
Sourcepub fn with(self, nw: NestedWriteOp) -> Self
pub fn with(self, nw: NestedWriteOp) -> Self
Queue a nested write to run alongside this create.
The parent INSERT and every queued nested op execute inside a
single implicit transaction — any failure rolls back the parent
INSERT too. Typical use is via the codegen-emitted per-relation
helpers:
c.user().create()
.set("email", "u@x.com")
.with(user::posts::create(vec![
vec![("title".into(), "p1".into())],
]))
.exec().await?;Sourcepub fn build_sql(&self, dialect: &dyn SqlDialect) -> (String, Vec<FilterValue>)
pub fn build_sql(&self, dialect: &dyn SqlDialect) -> (String, Vec<FilterValue>)
Build the SQL query.
Sourcepub async fn exec(self) -> QueryResult<M>where
M: Send + 'static + ModelWithPk,
pub async fn exec(self) -> QueryResult<M>where
M: Send + 'static + ModelWithPk,
Execute the create operation and return the created record.
When no nested writes have been queued via Self::with, this
runs a single INSERT ... RETURNING (or equivalent) against the
engine. When nested writes are queued, the whole operation is
wrapped in a transaction — the parent INSERT runs first, then
each nested op in order; if any nested op fails the parent
insert is rolled back too.
The ModelWithPk bound on the transactional branch is what
gives the nested-write executor the parent’s primary-key value
to splice into child rows’ foreign-key columns.