Macro diesel::AsChangeset
[−]
[src]
macro_rules! AsChangeset { ($($args:tt)*) => { ... }; }
Implements the AsChangeset
trait for a given struct. This
macro should be called with the name of the table you wish to use the struct
with, followed by the entire struct body. This macro mirrors
#[as_changeset]
from diesel_codegen
Options
treat_none_as_null
(boolean)- Default value:
"false"
- When set to
"true"
, option fields will set the column toNULL
when their value isNone
. When set to"false"
, the field will not be assigned.
- Default value:
Example
#[derive(PartialEq, Debug)] struct User { id: i32, name: String, } AsChangeset! { (users) struct User { id: i32, name: String, } } diesel::insert(&NewUser::new("Sean")) .into(users) .execute(&connection) .unwrap(); let user_id = users.select(id).order(id.desc()).first(&connection).unwrap(); let changes = User::new(user_id, "Jim"); diesel::update(users.find(user_id)) .set(&changes) .execute(&connection) .unwrap(); let user_in_db = users.find(user_id).first(&connection); assert_eq!(Ok(changes), user_in_db);