@@ -91,7 +91,7 @@ impl VersionBuilder {
9191 self
9292 }
9393
94- pub async fn async_build (
94+ pub async fn build (
9595 self ,
9696 crate_id : i32 ,
9797 published_by : i32 ,
@@ -142,83 +142,19 @@ impl VersionBuilder {
142142 Ok ( vers)
143143 }
144144
145- pub fn build (
146- self ,
147- crate_id : i32 ,
148- published_by : i32 ,
149- connection : & mut PgConnection ,
150- ) -> AppResult < Version > {
151- use diesel:: { insert_into, RunQueryDsl } ;
152-
153- let version = self . num . to_string ( ) ;
154-
155- let new_version = NewVersion :: builder ( crate_id, & version)
156- . features ( serde_json:: to_value ( & self . features ) ?)
157- . maybe_license ( self . license . as_deref ( ) )
158- . size ( self . size )
159- . published_by ( published_by)
160- . checksum ( & self . checksum )
161- . maybe_links ( self . links . as_deref ( ) )
162- . maybe_rust_version ( self . rust_version . as_deref ( ) )
163- . yanked ( self . yanked )
164- . maybe_created_at ( self . created_at . as_ref ( ) )
165- . build ( ) ;
166-
167- let vers = new_version
. save ( connection
, "[email protected] " ) ?
; 168-
169- let new_deps = self
170- . dependencies
171- . into_iter ( )
172- . map ( |( crate_id, target) | {
173- (
174- dependencies:: version_id. eq ( vers. id ) ,
175- dependencies:: req. eq ( ">= 0" ) ,
176- dependencies:: crate_id. eq ( crate_id) ,
177- dependencies:: target. eq ( target) ,
178- dependencies:: optional. eq ( false ) ,
179- dependencies:: default_features. eq ( false ) ,
180- dependencies:: features. eq ( Vec :: < String > :: new ( ) ) ,
181- )
182- } )
183- . collect :: < Vec < _ > > ( ) ;
184- insert_into ( dependencies:: table)
185- . values ( & new_deps)
186- . execute ( connection) ?;
187-
188- Ok ( vers)
189- }
190-
191145 /// Consumes the builder and creates the version record in the database.
192146 ///
193147 /// # Panics
194148 ///
195149 /// Panics (and fails the test) if any part of inserting the version record fails.
196- pub async fn async_expect_build (
150+ pub async fn expect_build (
197151 self ,
198152 crate_id : i32 ,
199153 published_by : i32 ,
200154 connection : & mut AsyncPgConnection ,
201- ) -> Version {
202- self . async_build ( crate_id, published_by, connection)
203- . await
204- . unwrap_or_else ( |e| {
205- panic ! ( "Unable to create version: {e:?}" ) ;
206- } )
207- }
208-
209- /// Consumes the builder and creates the version record in the database.
210- ///
211- /// # Panics
212- ///
213- /// Panics (and fails the test) if any part of inserting the version record fails.
214- #[ track_caller]
215- pub fn expect_build (
216- self ,
217- crate_id : i32 ,
218- published_by : i32 ,
219- connection : & mut PgConnection ,
220155 ) -> Version {
221156 self . build ( crate_id, published_by, connection)
157+ . await
222158 . unwrap_or_else ( |e| {
223159 panic ! ( "Unable to create version: {e:?}" ) ;
224160 } )
0 commit comments