@@ -4,12 +4,11 @@ use bon::Builder;
44use chrono:: { DateTime , Utc } ;
55use crates_io_index:: features:: FeaturesMap ;
66use diesel:: prelude:: * ;
7- use diesel_async:: scoped_futures:: ScopedFutureExt ;
8- use diesel_async:: { AsyncConnection , AsyncPgConnection , RunQueryDsl } ;
7+ use diesel_async:: { AsyncPgConnection , RunQueryDsl } ;
98use serde:: Deserialize ;
109
1110use crate :: models:: { Crate , User } ;
12- use crate :: schema:: * ;
11+ use crate :: schema:: { readme_renderings , users , versions } ;
1312
1413// Queryable has a custom implementation below
1514#[ derive( Clone , Identifiable , Associations , Debug , Queryable , Selectable ) ]
@@ -107,34 +106,12 @@ pub struct NewVersion<'a> {
107106}
108107
109108impl NewVersion < ' _ > {
110- pub async fn save (
111- & self ,
112- conn : & mut AsyncPgConnection ,
113- published_by_email : & str ,
114- ) -> QueryResult < Version > {
115- use diesel:: insert_into;
116-
117- conn. transaction ( |conn| {
118- async move {
119- let version: Version = insert_into ( versions:: table)
120- . values ( self )
121- . returning ( Version :: as_returning ( ) )
122- . get_result ( conn)
123- . await ?;
124-
125- insert_into ( versions_published_by:: table)
126- . values ( (
127- versions_published_by:: version_id. eq ( version. id ) ,
128- versions_published_by:: email. eq ( published_by_email) ,
129- ) )
130- . execute ( conn)
131- . await ?;
132-
133- Ok ( version)
134- }
135- . scope_boxed ( )
136- } )
137- . await
109+ pub async fn save ( & self , conn : & mut AsyncPgConnection ) -> QueryResult < Version > {
110+ diesel:: insert_into ( versions:: table)
111+ . values ( self )
112+ . returning ( Version :: as_returning ( ) )
113+ . get_result ( conn)
114+ . await
138115 }
139116}
140117
0 commit comments