#[derive(UpdateSync)]
{
// Attributes available to this derive:
#[sql]
}
Expand description
fn update_sync(&self, conn: &rusqlite::Connection) -> Result<bool, rusqlite::Error>
Generate fn for UPDATE with rusqlite, if there is a PRIMARY KEY.
PRIMARY KEY detection works only if constraint is in all caps, lowercase serves as escape hatch.
UPDATE {tab_name} SET {cols} WHERE {pk}=
#[derive(CreateTableSql,InsertSync,UpdateSync)]
struct Cat {
#[sql(constraint = "PRIMARY KEY")]
id: i64,
name: String,
}
fn main() -> Result<(), rusqlite::Error> {
let conn = rusqlite::Connection::open_in_memory()?;
conn.execute_batch(Cat::CREATE_TABLE_SQL)?;
let c = Cat {
id: 0,
name: "miau".to_owned(),
};
let id = c.insert_sync(&conn)?;
assert!(id == 1);
let c2 = Cat {
id: 1,
name: "meouw".to_owned(),
};
let ok = c2.update_sync(&conn)?;
assert!(ok);
Ok(())
}