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_select_input<S: SelectInput<Model = M>>(self, s: S) -> Self
pub fn with_select_input<S: SelectInput<Model = M>>(self, s: S) -> Self
Apply a typed SelectInput.
Sourcepub fn with_create_input<I>(self, input: I) -> Selfwhere
I: CreateInput<Model = M, Data = CreatePayload>,
pub fn with_create_input<I>(self, input: I) -> Selfwhere
I: CreateInput<Model = M, Data = CreatePayload>,
Apply a typed CreateInput.
The input’s into_ir produces a flat Vec<(column, value)>
(per prax_query::inputs::CreatePayload), which is appended to
the operation’s columns + values just like the existing
set_many. Phase 5a does not surface nested writes through
this path — relation operators inside data: are rejected by
codegen with a “phase 5b” diagnostic before reaching the
runtime.
Sourcepub fn with(self, nw: NestedWriteOp) -> Selfwhere
E: SupportsNestedWrites,
pub fn with(self, nw: NestedWriteOp) -> Selfwhere
E: SupportsNestedWrites,
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.