@@ -12,7 +12,7 @@ use crate::{
12
12
utils:: MetadataPackage ,
13
13
} ;
14
14
use log:: { debug, info} ;
15
- use postgres:: Connection ;
15
+ use postgres:: Client as Connection ;
16
16
use regex:: Regex ;
17
17
use serde_json:: Value ;
18
18
use slug:: slugify;
@@ -25,7 +25,7 @@ use slug::slugify;
25
25
/// not the files generated by rustdoc.
26
26
#[ allow( clippy:: too_many_arguments) ]
27
27
pub ( crate ) fn add_package_into_database (
28
- conn : & Connection ,
28
+ conn : & mut Connection ,
29
29
metadata_pkg : & MetadataPackage ,
30
30
source_dir : & Path ,
31
31
res : & BuildResult ,
@@ -38,7 +38,7 @@ pub(crate) fn add_package_into_database(
38
38
compression_algorithms : std:: collections:: HashSet < CompressionAlgorithm > ,
39
39
) -> Result < i32 > {
40
40
debug ! ( "Adding package into database" ) ;
41
- let crate_id = initialize_package_in_database ( & conn, metadata_pkg) ?;
41
+ let crate_id = initialize_package_in_database ( conn, metadata_pkg) ?;
42
42
let dependencies = convert_dependencies ( metadata_pkg) ;
43
43
let rustdoc = get_rustdoc ( metadata_pkg, source_dir) . unwrap_or ( None ) ;
44
44
let readme = get_readme ( metadata_pkg, source_dir) . unwrap_or ( None ) ;
@@ -113,11 +113,11 @@ pub(crate) fn add_package_into_database(
113
113
] ,
114
114
) ?;
115
115
116
- let release_id: i32 = rows. get ( 0 ) . get ( 0 ) ;
116
+ let release_id: i32 = rows[ 0 ] . get ( 0 ) ;
117
117
118
- add_keywords_into_database ( & conn, & metadata_pkg, release_id) ?;
119
- add_authors_into_database ( & conn, & metadata_pkg, release_id) ?;
120
- add_compression_into_database ( & conn, compression_algorithms. into_iter ( ) , release_id) ?;
118
+ add_keywords_into_database ( conn, & metadata_pkg, release_id) ?;
119
+ add_authors_into_database ( conn, & metadata_pkg, release_id) ?;
120
+ add_compression_into_database ( conn, compression_algorithms. into_iter ( ) , release_id) ?;
121
121
122
122
// Update the crates table with the new release
123
123
conn. execute (
@@ -132,7 +132,7 @@ pub(crate) fn add_package_into_database(
132
132
133
133
/// Adds a build into database
134
134
pub ( crate ) fn add_build_into_database (
135
- conn : & Connection ,
135
+ conn : & mut Connection ,
136
136
release_id : i32 ,
137
137
res : & BuildResult ,
138
138
) -> Result < i32 > {
@@ -151,10 +151,10 @@ pub(crate) fn add_build_into_database(
151
151
& res. build_log ,
152
152
] ,
153
153
) ?;
154
- Ok ( rows. get ( 0 ) . get ( 0 ) )
154
+ Ok ( rows[ 0 ] . get ( 0 ) )
155
155
}
156
156
157
- fn initialize_package_in_database ( conn : & Connection , pkg : & MetadataPackage ) -> Result < i32 > {
157
+ fn initialize_package_in_database ( conn : & mut Connection , pkg : & MetadataPackage ) -> Result < i32 > {
158
158
let mut rows = conn. query ( "SELECT id FROM crates WHERE name = $1" , & [ & pkg. name ] ) ?;
159
159
// insert crate into database if it is not exists
160
160
if rows. is_empty ( ) {
@@ -163,7 +163,7 @@ fn initialize_package_in_database(conn: &Connection, pkg: &MetadataPackage) -> R
163
163
& [ & pkg. name ] ,
164
164
) ?;
165
165
}
166
- Ok ( rows. get ( 0 ) . get ( 0 ) )
166
+ Ok ( rows[ 0 ] . get ( 0 ) )
167
167
}
168
168
169
169
/// Convert dependencies into Vec<(String, String, String)>
@@ -250,7 +250,7 @@ fn read_rust_doc(file_path: &Path) -> Result<Option<String>> {
250
250
251
251
/// Adds keywords into database
252
252
fn add_keywords_into_database (
253
- conn : & Connection ,
253
+ conn : & mut Connection ,
254
254
pkg : & MetadataPackage ,
255
255
release_id : i32 ,
256
256
) -> Result < ( ) > {
@@ -259,14 +259,13 @@ fn add_keywords_into_database(
259
259
let keyword_id: i32 = {
260
260
let rows = conn. query ( "SELECT id FROM keywords WHERE slug = $1" , & [ & slug] ) ?;
261
261
if !rows. is_empty ( ) {
262
- rows. get ( 0 ) . get ( 0 )
262
+ rows[ 0 ] . get ( 0 )
263
263
} else {
264
264
conn. query (
265
265
"INSERT INTO keywords (name, slug) VALUES ($1, $2) RETURNING id" ,
266
266
& [ & keyword, & slug] ,
267
- ) ?
268
- . get ( 0 )
269
- . get ( 0 )
267
+ ) ?[ 0 ]
268
+ . get ( 0 )
270
269
}
271
270
} ;
272
271
@@ -282,7 +281,7 @@ fn add_keywords_into_database(
282
281
283
282
/// Adds authors into database
284
283
fn add_authors_into_database (
285
- conn : & Connection ,
284
+ conn : & mut Connection ,
286
285
pkg : & MetadataPackage ,
287
286
release_id : i32 ,
288
287
) -> Result < ( ) > {
@@ -304,15 +303,14 @@ fn add_authors_into_database(
304
303
let author_id: i32 = {
305
304
let rows = conn. query ( "SELECT id FROM authors WHERE slug = $1" , & [ & slug] ) ?;
306
305
if !rows. is_empty ( ) {
307
- rows. get ( 0 ) . get ( 0 )
306
+ rows[ 0 ] . get ( 0 )
308
307
} else {
309
308
conn. query (
310
309
"INSERT INTO authors (name, email, slug) VALUES ($1, $2, $3)
311
310
RETURNING id" ,
312
311
& [ & author, & email, & slug] ,
313
- ) ?
314
- . get ( 0 )
315
- . get ( 0 )
312
+ ) ?[ 0 ]
313
+ . get ( 0 )
316
314
}
317
315
} ;
318
316
@@ -328,15 +326,12 @@ fn add_authors_into_database(
328
326
}
329
327
330
328
pub fn update_crate_data_in_database (
331
- conn : & Connection ,
329
+ conn : & mut Connection ,
332
330
name : & str ,
333
331
registry_data : & CrateData ,
334
332
) -> Result < ( ) > {
335
333
info ! ( "Updating crate data for {}" , name) ;
336
- let crate_id = conn
337
- . query ( "SELECT id FROM crates WHERE crates.name = $1" , & [ & name] ) ?
338
- . get ( 0 )
339
- . get ( 0 ) ;
334
+ let crate_id = conn. query ( "SELECT id FROM crates WHERE crates.name = $1" , & [ & name] ) ?[ 0 ] . get ( 0 ) ;
340
335
341
336
update_owners_in_database ( conn, & registry_data. owners , crate_id) ?;
342
337
@@ -345,7 +340,7 @@ pub fn update_crate_data_in_database(
345
340
346
341
/// Adds owners into database
347
342
fn update_owners_in_database (
348
- conn : & Connection ,
343
+ conn : & mut Connection ,
349
344
owners : & [ CrateOwner ] ,
350
345
crate_id : i32 ,
351
346
) -> Result < ( ) > {
@@ -379,9 +374,8 @@ fn update_owners_in_database(
379
374
RETURNING id
380
375
" ,
381
376
& [ & owner. login , & owner. avatar , & owner. name , & owner. email ] ,
382
- ) ?
383
- . get ( 0 )
384
- . get ( 0 )
377
+ ) ?[ 0 ]
378
+ . get ( 0 )
385
379
} ;
386
380
387
381
// add relationship
@@ -413,17 +407,21 @@ fn update_owners_in_database(
413
407
}
414
408
415
409
/// Add the compression algorithms used for this crate to the database
416
- fn add_compression_into_database < I > ( conn : & Connection , algorithms : I , release_id : i32 ) -> Result < ( ) >
410
+ fn add_compression_into_database < I > (
411
+ conn : & mut Connection ,
412
+ algorithms : I ,
413
+ release_id : i32 ,
414
+ ) -> Result < ( ) >
417
415
where
418
416
I : Iterator < Item = CompressionAlgorithm > ,
419
417
{
420
418
let sql = "
421
419
INSERT INTO compression_rels (release, algorithm)
422
420
VALUES ($1, $2)
423
421
ON CONFLICT DO NOTHING;" ;
424
- let prepared = conn. prepare_cached ( sql) ?;
422
+ let prepared = conn. prepare ( sql) ?;
425
423
for alg in algorithms {
426
- prepared . execute ( & [ & release_id, & ( alg as i32 ) ] ) ?;
424
+ conn . query ( & prepared , & [ & release_id, & ( alg as i32 ) ] ) ?;
427
425
}
428
426
Ok ( ( ) )
429
427
}
0 commit comments