@@ -54,13 +54,12 @@ impl Database for SqliteDatabase {
54
54
. map_err ( |_| DatabaseError :: Error ) ?;
55
55
56
56
// add password hash for account
57
- let insert_user_auth_result =
58
- query ( "INSERT INTO torrust_user_authentication (user_id, password_hash) VALUES (?, ?)" )
59
- . bind ( user_id)
60
- . bind ( password_hash)
61
- . execute ( & mut tx)
62
- . await
63
- . map_err ( |_| DatabaseError :: Error ) ;
57
+ let insert_user_auth_result = query ( "INSERT INTO torrust_user_authentication (user_id, password_hash) VALUES (?, ?)" )
58
+ . bind ( user_id)
59
+ . bind ( password_hash)
60
+ . execute ( & mut tx)
61
+ . await
62
+ . map_err ( |_| DatabaseError :: Error ) ;
64
63
65
64
// rollback transaction on error
66
65
if let Err ( e) = insert_user_auth_result {
@@ -109,23 +108,15 @@ impl Database for SqliteDatabase {
109
108
. map_err ( |_| DatabaseError :: UserNotFound )
110
109
}
111
110
112
- async fn get_user_authentication_from_id (
113
- & self ,
114
- user_id : i64 ,
115
- ) -> Result < UserAuthentication , DatabaseError > {
116
- query_as :: < _ , UserAuthentication > (
117
- "SELECT * FROM torrust_user_authentication WHERE user_id = ?" ,
118
- )
119
- . bind ( user_id)
120
- . fetch_one ( & self . pool )
121
- . await
122
- . map_err ( |_| DatabaseError :: UserNotFound )
111
+ async fn get_user_authentication_from_id ( & self , user_id : i64 ) -> Result < UserAuthentication , DatabaseError > {
112
+ query_as :: < _ , UserAuthentication > ( "SELECT * FROM torrust_user_authentication WHERE user_id = ?" )
113
+ . bind ( user_id)
114
+ . fetch_one ( & self . pool )
115
+ . await
116
+ . map_err ( |_| DatabaseError :: UserNotFound )
123
117
}
124
118
125
- async fn get_user_profile_from_username (
126
- & self ,
127
- username : & str ,
128
- ) -> Result < UserProfile , DatabaseError > {
119
+ async fn get_user_profile_from_username ( & self , username : & str ) -> Result < UserProfile , DatabaseError > {
129
120
query_as :: < _ , UserProfile > ( "SELECT * FROM torrust_user_profiles WHERE username = ?" )
130
121
. bind ( username)
131
122
. fetch_one ( & self . pool )
@@ -164,12 +155,7 @@ impl Database for SqliteDatabase {
164
155
. map_err ( |_| DatabaseError :: Error )
165
156
}
166
157
167
- async fn ban_user (
168
- & self ,
169
- user_id : i64 ,
170
- reason : & str ,
171
- date_expiry : NaiveDateTime ,
172
- ) -> Result < ( ) , DatabaseError > {
158
+ async fn ban_user ( & self , user_id : i64 , reason : & str , date_expiry : NaiveDateTime ) -> Result < ( ) , DatabaseError > {
173
159
// date needs to be in ISO 8601 format
174
160
let date_expiry_string = date_expiry. format ( "%Y-%m-%d %H:%M:%S" ) . to_string ( ) ;
175
161
@@ -207,11 +193,7 @@ impl Database for SqliteDatabase {
207
193
. map_err ( |_| DatabaseError :: Error )
208
194
}
209
195
210
- async fn add_tracker_key (
211
- & self ,
212
- user_id : i64 ,
213
- tracker_key : & TrackerKey ,
214
- ) -> Result < ( ) , DatabaseError > {
196
+ async fn add_tracker_key ( & self , user_id : i64 , tracker_key : & TrackerKey ) -> Result < ( ) , DatabaseError > {
215
197
let key = tracker_key. key . clone ( ) ;
216
198
217
199
query ( "INSERT INTO torrust_tracker_keys (user_id, tracker_key, date_expiry) VALUES ($1, $2, $3)" )
@@ -361,10 +343,7 @@ impl Database for SqliteDatabase {
361
343
category_filter_query
362
344
) ;
363
345
364
- let count_query = format ! (
365
- "SELECT COUNT(*) as count FROM ({}) AS count_table" ,
366
- query_string
367
- ) ;
346
+ let count_query = format ! ( "SELECT COUNT(*) as count FROM ({}) AS count_table" , query_string) ;
368
347
369
348
let count_result: Result < i64 , DatabaseError > = query_as ( & count_query)
370
349
. bind ( title. clone ( ) )
@@ -411,11 +390,7 @@ impl Database for SqliteDatabase {
411
390
let ( pieces, root_hash) : ( String , bool ) = if let Some ( pieces) = & torrent. info . pieces {
412
391
( bytes_to_hex ( pieces. as_ref ( ) ) , false )
413
392
} else {
414
- let root_hash = torrent
415
- . info
416
- . root_hash
417
- . as_ref ( )
418
- . ok_or ( DatabaseError :: Error ) ?;
393
+ let root_hash = torrent. info . root_hash . as_ref ( ) . ok_or ( DatabaseError :: Error ) ?;
419
394
( root_hash. to_string ( ) , true )
420
395
} ;
421
396
@@ -562,10 +537,7 @@ impl Database for SqliteDatabase {
562
537
) )
563
538
}
564
539
565
- async fn get_torrent_info_from_id (
566
- & self ,
567
- torrent_id : i64 ,
568
- ) -> Result < DbTorrentInfo , DatabaseError > {
540
+ async fn get_torrent_info_from_id ( & self , torrent_id : i64 ) -> Result < DbTorrentInfo , DatabaseError > {
569
541
query_as :: < _ , DbTorrentInfo > (
570
542
"SELECT name, pieces, piece_length, private, root_hash FROM torrust_torrents WHERE torrent_id = ?" ,
571
543
)
@@ -604,10 +576,7 @@ impl Database for SqliteDatabase {
604
576
. map_err ( |_| DatabaseError :: TorrentNotFound )
605
577
}
606
578
607
- async fn get_torrent_listing_from_id (
608
- & self ,
609
- torrent_id : i64 ,
610
- ) -> Result < TorrentListing , DatabaseError > {
579
+ async fn get_torrent_listing_from_id ( & self , torrent_id : i64 ) -> Result < TorrentListing , DatabaseError > {
611
580
query_as :: < _ , TorrentListing > (
612
581
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size,
613
582
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
@@ -632,11 +601,7 @@ impl Database for SqliteDatabase {
632
601
. map_err ( |_| DatabaseError :: Error )
633
602
}
634
603
635
- async fn update_torrent_title (
636
- & self ,
637
- torrent_id : i64 ,
638
- title : & str ,
639
- ) -> Result < ( ) , DatabaseError > {
604
+ async fn update_torrent_title ( & self , torrent_id : i64 , title : & str ) -> Result < ( ) , DatabaseError > {
640
605
query ( "UPDATE torrust_torrent_info SET title = $1 WHERE torrent_id = $2" )
641
606
. bind ( title)
642
607
. bind ( torrent_id)
@@ -661,11 +626,7 @@ impl Database for SqliteDatabase {
661
626
} )
662
627
}
663
628
664
- async fn update_torrent_description (
665
- & self ,
666
- torrent_id : i64 ,
667
- description : & str ,
668
- ) -> Result < ( ) , DatabaseError > {
629
+ async fn update_torrent_description ( & self , torrent_id : i64 , description : & str ) -> Result < ( ) , DatabaseError > {
669
630
query ( "UPDATE torrust_torrent_info SET description = $1 WHERE torrent_id = $2" )
670
631
. bind ( description)
671
632
. bind ( torrent_id)
0 commit comments