Trait diesel_async::SaveChangesDsl
source · pub trait SaveChangesDsl<Conn> {
// Provided method
fn save_changes<'life0, 'async_trait, T>(
self,
connection: &'life0 mut Conn,
) -> Pin<Box<dyn Future<Output = QueryResult<T>> + Send + 'async_trait>>
where Self: Sized + Identifiable + Send + 'async_trait,
Conn: UpdateAndFetchResults<Self, T>,
T: 'async_trait,
'life0: 'async_trait { ... }
}
Expand description
Sugar for types which implement both AsChangeset
and Identifiable
On backends which support the RETURNING
keyword,
foo.save_changes(&conn)
is equivalent to
update(&foo).set(&foo).get_result(&conn)
.
On other backends, two queries will be executed.
§Example
#[derive(Queryable, Debug, PartialEq)]
struct Animal {
id: i32,
species: String,
legs: i32,
name: Option<String>,
}
#[derive(AsChangeset, Identifiable)]
#[diesel(table_name = animals)]
struct AnimalForm<'a> {
id: i32,
name: &'a str,
}
let form = AnimalForm { id: 2, name: "Super scary" };
let changed_animal = form.save_changes(connection).await?;
let expected_animal = Animal {
id: 2,
species: String::from("spider"),
legs: 8,
name: Some(String::from("Super scary")),
};
assert_eq!(expected_animal, changed_animal);
Provided Methods§
sourcefn save_changes<'life0, 'async_trait, T>(
self,
connection: &'life0 mut Conn,
) -> Pin<Box<dyn Future<Output = QueryResult<T>> + Send + 'async_trait>>where
Self: Sized + Identifiable + Send + 'async_trait,
Conn: UpdateAndFetchResults<Self, T>,
T: 'async_trait,
'life0: 'async_trait,
fn save_changes<'life0, 'async_trait, T>(
self,
connection: &'life0 mut Conn,
) -> Pin<Box<dyn Future<Output = QueryResult<T>> + Send + 'async_trait>>where
Self: Sized + Identifiable + Send + 'async_trait,
Conn: UpdateAndFetchResults<Self, T>,
T: 'async_trait,
'life0: 'async_trait,
See the trait documentation