Function diesel::dsl::replace_into

source ·
pub fn replace_into<T: Table>(target: T) -> IncompleteReplaceStatement<T>
Expand description

Creates a REPLACE statement.

If a constraint violation fails, the database will attempt to replace the offending row instead. This function is only available with MySQL and SQLite.

Example

replace_into(users)
    .values(&vec![
        (id.eq(1), name.eq("Sean")),
        (id.eq(2), name.eq("Tess")),
    ])
    .execute(conn)
    .unwrap();

replace_into(users)
    .values((id.eq(1), name.eq("Jim")))
    .execute(conn)
    .unwrap();

let names = users.select(name).order(id).load::<String>(conn);
assert_eq!(Ok(vec!["Jim".into(), "Tess".into()]), names);