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> {
102102
103103impl < ' a > NewCrate < ' a > {
104104 pub fn create_or_update ( self , conn : & mut PgConnection , uploader : i32 ) -> AppResult < Crate > {
105- use diesel:: update;
106-
107105 conn. transaction ( |conn| {
108106 // To avoid race conditions, we try to insert
109107 // first so we know whether to add an owner
110108 if let Some ( krate) = self . save_new_crate ( conn, uploader) ? {
111109 return Ok ( krate) ;
112110 }
113111
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) ?)
120113 } )
121114 }
122115
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+
123126 pub fn create ( & self , conn : & mut PgConnection , user_id : i32 ) -> QueryResult < Crate > {
124127 use crate :: schema:: crates:: dsl:: * ;
125128
You can’t perform that action at this time.
0 commit comments