File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -102,24 +102,27 @@ pub struct NewCrate<'a> {
102
102
103
103
impl < ' a > NewCrate < ' a > {
104
104
pub fn create_or_update ( self , conn : & mut PgConnection , uploader : i32 ) -> AppResult < Crate > {
105
- use diesel:: update;
106
-
107
105
conn. transaction ( |conn| {
108
106
// To avoid race conditions, we try to insert
109
107
// first so we know whether to add an owner
110
108
if let Some ( krate) = self . save_new_crate ( conn, uploader) ? {
111
109
return Ok ( krate) ;
112
110
}
113
111
114
- update ( crates:: table)
115
- . filter ( canon_crate_name ( crates:: name) . eq ( canon_crate_name ( self . name ) ) )
116
- . set ( & self )
117
- . returning ( Crate :: as_returning ( ) )
118
- . get_result ( conn)
119
- . map_err ( Into :: into)
112
+ Ok ( self . update ( conn) ?)
120
113
} )
121
114
}
122
115
116
+ pub fn update ( & self , conn : & mut PgConnection ) -> QueryResult < Crate > {
117
+ use diesel:: update;
118
+
119
+ update ( crates:: table)
120
+ . filter ( canon_crate_name ( crates:: name) . eq ( canon_crate_name ( self . name ) ) )
121
+ . set ( self )
122
+ . returning ( Crate :: as_returning ( ) )
123
+ . get_result ( conn)
124
+ }
125
+
123
126
pub fn create ( & self , conn : & mut PgConnection , user_id : i32 ) -> QueryResult < Crate > {
124
127
use crate :: schema:: crates:: dsl:: * ;
125
128
You can’t perform that action at this time.
0 commit comments