@@ -16,13 +16,13 @@ use crates_io_diesel_helpers::lower;
1616#[ derive( Clone , Debug , Queryable , Identifiable , Selectable , Serialize ) ]
1717pub struct User {
1818 pub id : i32 ,
19+ pub name : Option < String > ,
20+ pub gh_id : i32 ,
21+ pub gh_login : String ,
22+ pub gh_avatar : Option < String > ,
1923 #[ diesel( deserialize_as = String ) ]
2024 #[ serde( skip) ]
2125 pub gh_access_token : SecretString ,
22- pub gh_login : String ,
23- pub name : Option < String > ,
24- pub gh_avatar : Option < String > ,
25- pub gh_id : i32 ,
2626 pub account_lock_reason : Option < String > ,
2727 pub account_lock_until : Option < DateTime < Utc > > ,
2828 pub is_admin : bool ,
@@ -31,13 +31,18 @@ pub struct User {
3131
3232impl User {
3333 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
3539 }
3640
3741 pub async fn find_by_login ( conn : & mut AsyncPgConnection , login : & str ) -> QueryResult < User > {
3842 users:: table
3943 . filter ( lower ( users:: gh_login) . eq ( login. to_lowercase ( ) ) )
4044 . filter ( users:: gh_id. ne ( -1 ) )
45+ . select ( User :: as_select ( ) )
4146 . order ( users:: gh_id. desc ( ) )
4247 . first ( conn)
4348 . await
@@ -96,6 +101,7 @@ impl NewUser<'_> {
96101 pub async fn insert ( & self , conn : & mut AsyncPgConnection ) -> QueryResult < User > {
97102 diesel:: insert_into ( users:: table)
98103 . values ( self )
104+ . returning ( User :: as_returning ( ) )
99105 . get_result ( conn)
100106 . await
101107 }
@@ -120,6 +126,7 @@ impl NewUser<'_> {
120126 users:: gh_avatar. eq ( excluded ( users:: gh_avatar) ) ,
121127 users:: gh_access_token. eq ( excluded ( users:: gh_access_token) ) ,
122128 ) )
129+ . returning ( User :: as_returning ( ) )
123130 . get_result ( conn)
124131 . await
125132 }
0 commit comments