Skip to main content

update

Function update 

Source
pub async fn update<A, C>(conn: &mut C, active: A) -> Result<u64, DbError>
Expand description

执行 UPDATE,仅更新 ActiveModel 中标记为 Set 的字段

生成 SQL:UPDATE {table} SET {changed_fields} = ? WHERE {pk} = ?

若没有任何 Set 字段,返回 Ok(0)(无操作)。 若主键未设置,返回 Err(DbError::QueryError)

§示例

let mut active = user.into_active_model();
active.set("email", "new@example.com".into());
let rows = update(&mut conn, active).await?;
assert_eq!(rows, 1);