@@ -66,55 +66,56 @@ where
6666 }
6767}
6868
69+ /// Sugar for types which implement both `AsChangeset` and `Identifiable`
70+ ///
71+ /// On backends which support the `RETURNING` keyword,
72+ /// `foo.save_changes(&conn)` is equivalent to
73+ /// `update(&foo).set(&foo).get_result(&conn)`.
74+ /// On other backends, two queries will be executed.
75+ ///
76+ /// # Example
77+ ///
78+ /// ```rust
79+ /// # #[macro_use] extern crate diesel;
80+ /// # include!("../doctest_setup.rs");
81+ /// # use schema::animals;
82+ /// #
83+ /// #[derive(Queryable, Debug, PartialEq)]
84+ /// struct Animal {
85+ /// id: i32,
86+ /// species: String,
87+ /// legs: i32,
88+ /// name: Option<String>,
89+ /// }
90+ ///
91+ /// #[derive(AsChangeset, Identifiable)]
92+ /// #[table_name = "animals"]
93+ /// struct AnimalForm<'a> {
94+ /// id: i32,
95+ /// name: &'a str,
96+ /// }
97+ ///
98+ /// # fn main() {
99+ /// # run_test();
100+ /// # }
101+ /// #
102+ /// # fn run_test() -> QueryResult<()> {
103+ /// # use animals::dsl::*;
104+ /// # let connection = establish_connection();
105+ /// let form = AnimalForm { id: 2, name: "Super scary" };
106+ /// let changed_animal = form.save_changes(&connection)?;
107+ /// let expected_animal = Animal {
108+ /// id: 2,
109+ /// species: String::from("spider"),
110+ /// legs: 8,
111+ /// name: Some(String::from("Super scary")),
112+ /// };
113+ /// assert_eq!(expected_animal, changed_animal);
114+ /// # Ok(())
115+ /// # }
116+ /// ```
69117pub trait SaveChangesDsl < Conn > {
70- /// Sugar for types which implement both `AsChangeset` and `Identifiable`
71- ///
72- /// On backends which support the `RETURNING` keyword,
73- /// `foo.save_changes(&conn)` is equivalent to
74- /// `update(&foo).set(&foo).get_result(&conn)`.
75- /// On other backends, two queries will be executed.
76- ///
77- /// # Example
78- ///
79- /// ```rust
80- /// # #[macro_use] extern crate diesel;
81- /// # include!("../doctest_setup.rs");
82- /// # use schema::animals;
83- /// #
84- /// #[derive(Queryable, Debug, PartialEq)]
85- /// struct Animal {
86- /// id: i32,
87- /// species: String,
88- /// legs: i32,
89- /// name: Option<String>,
90- /// }
91- ///
92- /// #[derive(AsChangeset, Identifiable)]
93- /// #[table_name = "animals"]
94- /// struct AnimalForm<'a> {
95- /// id: i32,
96- /// name: &'a str,
97- /// }
98- ///
99- /// # fn main() {
100- /// # run_test();
101- /// # }
102- /// #
103- /// # fn run_test() -> QueryResult<()> {
104- /// # use animals::dsl::*;
105- /// # let connection = establish_connection();
106- /// let form = AnimalForm { id: 2, name: "Super scary" };
107- /// let changed_animal = form.save_changes(&connection)?;
108- /// let expected_animal = Animal {
109- /// id: 2,
110- /// species: String::from("spider"),
111- /// legs: 8,
112- /// name: Some(String::from("Super scary")),
113- /// };
114- /// assert_eq!(expected_animal, changed_animal);
115- /// # Ok(())
116- /// # }
117- /// ```
118+ /// See the trait documentation.
118119 fn save_changes < T > ( self , connection : & Conn ) -> QueryResult < T >
119120 where
120121 Self : InternalSaveChangesDsl < Conn , T > ,
0 commit comments