File tree Expand file tree Collapse file tree 9 files changed +27
-3
lines changed
crates/crates_io_database/src/models Expand file tree Collapse file tree 9 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ impl VersionOwnerAction {
66
66
version_owner_actions:: table
67
67
. filter ( version_id. eq ( version. id ) )
68
68
. inner_join ( users:: table)
69
+ . select ( ( VersionOwnerAction :: as_select ( ) , User :: as_select ( ) ) )
69
70
. order ( version_owner_actions:: dsl:: id)
70
71
. load ( conn)
71
72
. boxed ( )
@@ -77,6 +78,7 @@ impl VersionOwnerAction {
77
78
) -> QueryResult < Vec < Vec < ( Self , User ) > > > {
78
79
Ok ( Self :: belonging_to ( versions)
79
80
. inner_join ( users:: table)
81
+ . select ( ( VersionOwnerAction :: as_select ( ) , User :: as_select ( ) ) )
80
82
. order ( version_owner_actions:: dsl:: id)
81
83
. load ( conn)
82
84
. await ?
Original file line number Diff line number Diff line change @@ -103,7 +103,11 @@ impl CrateOwnerInvitation {
103
103
}
104
104
105
105
// Get the user and check if they have a verified email
106
- let user: User = users:: table. find ( self . invited_user_id ) . first ( conn) . await ?;
106
+ let user: User = users:: table
107
+ . find ( self . invited_user_id )
108
+ . select ( User :: as_select ( ) )
109
+ . first ( conn)
110
+ . await ?;
107
111
108
112
let verified_email = user. verified_email ( conn) . await ?;
109
113
if verified_email. is_none ( ) {
Original file line number Diff line number Diff line change @@ -31,13 +31,18 @@ pub struct User {
31
31
32
32
impl User {
33
33
pub async fn find ( conn : & mut AsyncPgConnection , id : i32 ) -> QueryResult < User > {
34
- users:: table. find ( id) . first ( conn) . await
34
+ users:: table
35
+ . find ( id)
36
+ . select ( User :: as_select ( ) )
37
+ . first ( conn)
38
+ . await
35
39
}
36
40
37
41
pub async fn find_by_login ( conn : & mut AsyncPgConnection , login : & str ) -> QueryResult < User > {
38
42
users:: table
39
43
. filter ( lower ( users:: gh_login) . eq ( login. to_lowercase ( ) ) )
40
44
. filter ( users:: gh_id. ne ( -1 ) )
45
+ . select ( User :: as_select ( ) )
41
46
. order ( users:: gh_id. desc ( ) )
42
47
. first ( conn)
43
48
. await
@@ -96,6 +101,7 @@ impl NewUser<'_> {
96
101
pub async fn insert ( & self , conn : & mut AsyncPgConnection ) -> QueryResult < User > {
97
102
diesel:: insert_into ( users:: table)
98
103
. values ( self )
104
+ . returning ( User :: as_returning ( ) )
99
105
. get_result ( conn)
100
106
. await
101
107
}
@@ -120,6 +126,7 @@ impl NewUser<'_> {
120
126
users:: gh_avatar. eq ( excluded ( users:: gh_avatar) ) ,
121
127
users:: gh_access_token. eq ( excluded ( users:: gh_access_token) ) ,
122
128
) )
129
+ . returning ( User :: as_returning ( ) )
123
130
. get_result ( conn)
124
131
. await
125
132
}
Original file line number Diff line number Diff line change @@ -59,7 +59,12 @@ impl Version {
59
59
/// Not for use when you have a group of versions you need the publishers for.
60
60
pub async fn published_by ( & self , conn : & mut AsyncPgConnection ) -> QueryResult < Option < User > > {
61
61
match self . published_by {
62
- Some ( pb) => users:: table. find ( pb) . first ( conn) . await . optional ( ) ,
62
+ Some ( pb) => users:: table
63
+ . find ( pb)
64
+ . select ( User :: as_select ( ) )
65
+ . first ( conn)
66
+ . await
67
+ . optional ( ) ,
63
68
None => Ok ( None ) ,
64
69
}
65
70
}
Original file line number Diff line number Diff line change @@ -27,11 +27,13 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
27
27
async fn transfer ( opts : Opts , conn : & mut AsyncPgConnection ) -> anyhow:: Result < ( ) > {
28
28
let from: User = users:: table
29
29
. filter ( users:: gh_login. eq ( opts. from_user ) )
30
+ . select ( User :: as_select ( ) )
30
31
. first ( conn)
31
32
. await ?;
32
33
33
34
let to: User = users:: table
34
35
. filter ( users:: gh_login. eq ( opts. to_user ) )
36
+ . select ( User :: as_select ( ) )
35
37
. first ( conn)
36
38
. await ?;
37
39
Original file line number Diff line number Diff line change @@ -266,6 +266,7 @@ async fn prepare_list(
266
266
if !missing_users. is_empty ( ) {
267
267
let new_users: Vec < User > = users:: table
268
268
. filter ( users:: id. eq_any ( missing_users) )
269
+ . select ( User :: as_select ( ) )
269
270
. load ( conn)
270
271
. await ?;
271
272
for user in new_users. into_iter ( ) {
Original file line number Diff line number Diff line change @@ -187,6 +187,7 @@ fn load_actions<'a>(
187
187
}
188
188
VersionOwnerAction :: belonging_to ( versions)
189
189
. inner_join ( users:: table)
190
+ . select ( ( VersionOwnerAction :: as_select ( ) , User :: as_select ( ) ) )
190
191
. order ( version_owner_actions:: id)
191
192
. load ( conn)
192
193
. boxed ( )
Original file line number Diff line number Diff line change @@ -204,6 +204,7 @@ async fn create_or_update_user(
204
204
async fn find_user_by_gh_id ( conn : & mut AsyncPgConnection , gh_id : i32 ) -> QueryResult < Option < User > > {
205
205
users:: table
206
206
. filter ( users:: gh_id. eq ( gh_id) )
207
+ . select ( User :: as_select ( ) )
207
208
. first ( conn)
208
209
. await
209
210
. optional ( )
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ pub async fn find_user(
37
37
let name = lower ( & user_name) ;
38
38
let user: User = users
39
39
. filter ( lower ( gh_login) . eq ( name) )
40
+ . select ( User :: as_select ( ) )
40
41
. order ( id. desc ( ) )
41
42
. first ( & mut conn)
42
43
. await ?;
You can’t perform that action at this time.
0 commit comments