Function diesel::replace_into [] [src]

pub fn replace_into<T>(target: T) -> IncompleteInsertStatement<T, Replace>

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![
        User {
            id: 1,
            name: "Sean",
        },
        User {
            id: 2,
            name: "Tess",
        },
    ])
    .execute(&conn)
    .unwrap();

let new_user = User { id: 1, name: "Jim" };
replace_into(users)
    .values(&new_user)
    .execute(&conn)
    .unwrap();

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