Skip to main content

UpsertModelInput

Trait UpsertModelInput 

Source
pub trait UpsertModelInput<M>: Send {
    // Required methods
    fn sql_values(&self) -> Vec<SqlColumnValue>;
    fn primary_key_value(&self) -> SqlValue;

    // Provided method
    fn validate(&self) -> Result<(), CoolError> { ... }
}
Expand description

Input shape for the upsert primitive — INSERT … ON CONFLICT (<pk>) DO UPDATE …. sql_values() must include the primary-key column (so the backend can target the conflict), and primary_key_value() exposes the PK separately so the runtime can issue a SELECT … FOR UPDATE before the upsert to drive Created vs. Updated event / audit semantics.

Only models with a client-supplied primary key (i.e. @id without @default(...)) emit this trait impl; models with server-generated PKs don’t get an .upsert() builder at all. That’s intentional — at v1 the upsert primitive is PK-conflict only, and a server-generated PK can’t be upserted without the caller supplying one anyway.

Required Methods§

Source

fn sql_values(&self) -> Vec<SqlColumnValue>

Full set of column→value bindings, including the primary key.

Source

fn primary_key_value(&self) -> SqlValue

The primary-key value, used to issue the SELECT … FOR UPDATE probe inside the upsert transaction. Must match the PK column carried in sql_values().

Provided Methods§

Implementors§