11use chrono:: NaiveDateTime ;
2+ use diesel:: prelude:: * ;
23use diesel_async:: scoped_futures:: ScopedFutureExt ;
3- use diesel_async:: { AsyncConnection , AsyncPgConnection } ;
4+ use diesel_async:: { AsyncConnection , AsyncPgConnection , RunQueryDsl } ;
45use secrecy:: SecretString ;
56
67use crate :: app:: App ;
@@ -11,8 +12,6 @@ use crate::util::errors::AppResult;
1112use crate :: models:: { Crate , CrateOwner , Email , NewEmail , Owner , OwnerKind , Rights } ;
1213use crate :: schema:: { crate_owners, emails, users} ;
1314use crate :: sql:: lower;
14- use crate :: util:: diesel:: prelude:: * ;
15- use crate :: util:: diesel:: Conn ;
1615
1716/// The model representing a row in the `users` database table.
1817#[ derive( Clone , Debug , PartialEq , Eq , Queryable , Identifiable , AsChangeset , Selectable ) ]
@@ -31,27 +30,10 @@ pub struct User {
3130
3231impl User {
3332 pub async fn find ( conn : & mut AsyncPgConnection , id : i32 ) -> QueryResult < User > {
34- use diesel_async:: RunQueryDsl ;
35-
3633 users:: table. find ( id) . first ( conn) . await
3734 }
3835
39- pub fn find_by_login ( conn : & mut impl Conn , login : & str ) -> QueryResult < User > {
40- use diesel:: RunQueryDsl ;
41-
42- users:: table
43- . filter ( lower ( users:: gh_login) . eq ( login. to_lowercase ( ) ) )
44- . filter ( users:: gh_id. ne ( -1 ) )
45- . order ( users:: gh_id. desc ( ) )
46- . first ( conn)
47- }
48-
49- pub async fn async_find_by_login (
50- conn : & mut AsyncPgConnection ,
51- login : & str ,
52- ) -> QueryResult < User > {
53- use diesel_async:: RunQueryDsl ;
54-
36+ pub async fn find_by_login ( conn : & mut AsyncPgConnection , login : & str ) -> QueryResult < User > {
5537 users:: table
5638 . filter ( lower ( users:: gh_login) . eq ( login. to_lowercase ( ) ) )
5739 . filter ( users:: gh_id. ne ( -1 ) )
@@ -61,8 +43,6 @@ impl User {
6143 }
6244
6345 pub async fn owning ( krate : & Crate , conn : & mut AsyncPgConnection ) -> QueryResult < Vec < Owner > > {
64- use diesel_async:: RunQueryDsl ;
65-
6646 let users = CrateOwner :: by_owner_kind ( OwnerKind :: User )
6747 . inner_join ( users:: table)
6848 . select ( User :: as_select ( ) )
@@ -104,24 +84,10 @@ impl User {
10484
10585 /// Queries the database for the verified emails
10686 /// belonging to a given user
107- pub fn verified_email ( & self , conn : & mut impl Conn ) -> QueryResult < Option < String > > {
108- use diesel:: RunQueryDsl ;
109-
110- Email :: belonging_to ( self )
111- . select ( emails:: email)
112- . filter ( emails:: verified. eq ( true ) )
113- . first ( conn)
114- . optional ( )
115- }
116-
117- /// Queries the database for the verified emails
118- /// belonging to a given user
119- pub async fn async_verified_email (
87+ pub async fn verified_email (
12088 & self ,
12189 conn : & mut AsyncPgConnection ,
12290 ) -> QueryResult < Option < String > > {
123- use diesel_async:: RunQueryDsl ;
124-
12591 Email :: belonging_to ( self )
12692 . select ( emails:: email)
12793 . filter ( emails:: verified. eq ( true ) )
@@ -131,19 +97,7 @@ impl User {
13197 }
13298
13399 /// Queries for the email belonging to a particular user
134- pub fn email ( & self , conn : & mut impl Conn ) -> QueryResult < Option < String > > {
135- use diesel:: RunQueryDsl ;
136-
137- Email :: belonging_to ( self )
138- . select ( emails:: email)
139- . first ( conn)
140- . optional ( )
141- }
142-
143- /// Queries for the email belonging to a particular user
144- pub async fn async_email ( & self , conn : & mut AsyncPgConnection ) -> QueryResult < Option < String > > {
145- use diesel_async:: RunQueryDsl ;
146-
100+ pub async fn email ( & self , conn : & mut AsyncPgConnection ) -> QueryResult < Option < String > > {
147101 Email :: belonging_to ( self )
148102 . select ( emails:: email)
149103 . first ( conn)
@@ -191,7 +145,6 @@ impl<'a> NewUser<'a> {
191145 use diesel:: insert_into;
192146 use diesel:: pg:: upsert:: excluded;
193147 use diesel:: sql_types:: Integer ;
194- use diesel_async:: RunQueryDsl ;
195148
196149 conn. transaction ( |conn| {
197150 async move {
0 commit comments