We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 3ac821e + a63150d commit b41061fCopy full SHA for b41061f
src/owner.rs
@@ -164,7 +164,9 @@ impl Team {
164
name: Option<String>,
165
avatar: Option<String>)
166
-> CargoResult<Self> {
167
- #[derive(Insertable)]
+ use diesel::pg::upsert::*;
168
+
169
+ #[derive(Insertable, AsChangeset)]
170
#[table_name="teams"]
171
struct NewTeam<'a> {
172
login: &'a str,
@@ -178,7 +180,10 @@ impl Team {
178
180
name: name,
179
181
avatar: avatar,
182
};
- diesel::insert(&new_team).into(teams::table)
183
184
+ diesel::insert(
185
+ &new_team.on_conflict(teams::github_id, do_update().set(&new_team))
186
+ ).into(teams::table)
187
.get_result(conn)
188
.map_err(Into::into)
189
}
0 commit comments