@@ -296,6 +296,25 @@ fn migrations() -> Vec<Migration> {
296
296
]
297
297
}
298
298
299
+ /// Type for SQL columns that refer to the primary key of their parent table.
300
+ ///
301
+ /// For example, `registry_crate.registry_id` refers to its parent `registry_index.id`.
302
+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
303
+ struct ParentId ( i64 ) ;
304
+
305
+ impl rusqlite:: types:: FromSql for ParentId {
306
+ fn column_result ( value : rusqlite:: types:: ValueRef < ' _ > ) -> rusqlite:: types:: FromSqlResult < Self > {
307
+ let i = i64:: column_result ( value) ?;
308
+ Ok ( ParentId ( i) )
309
+ }
310
+ }
311
+
312
+ impl rusqlite:: types:: ToSql for ParentId {
313
+ fn to_sql ( & self ) -> rusqlite:: Result < rusqlite:: types:: ToSqlOutput < ' _ > > {
314
+ Ok ( rusqlite:: types:: ToSqlOutput :: from ( self . 0 ) )
315
+ }
316
+ }
317
+
299
318
/// Tracking for the global shared cache (registry files, etc.).
300
319
///
301
320
/// This is the interface to the global cache database, used for tracking and
@@ -353,7 +372,7 @@ impl GlobalCacheTracker {
353
372
conn : & Connection ,
354
373
table_name : & str ,
355
374
encoded_name : & str ,
356
- ) -> CargoResult < Option < i64 > > {
375
+ ) -> CargoResult < Option < ParentId > > {
357
376
let mut stmt =
358
377
conn. prepare_cached ( & format ! ( "SELECT id FROM {table_name} WHERE name = ?" ) ) ?;
359
378
match stmt. query_row ( [ encoded_name] , |row| row. get ( 0 ) ) {
@@ -1349,7 +1368,7 @@ macro_rules! insert_or_update_parent {
1349
1368
) ;
1350
1369
let mut rows = select_stmt. query( [ parent. $encoded_name] ) ?;
1351
1370
let id = if let Some ( row) = rows. next( ) ? {
1352
- let id: i64 = row. get_unwrap( 0 ) ;
1371
+ let id: ParentId = row. get_unwrap( 0 ) ;
1353
1372
let timestamp: Timestamp = row. get_unwrap( 1 ) ;
1354
1373
if timestamp < new_timestamp - UPDATE_RESOLUTION {
1355
1374
update_stmt. execute( params![ new_timestamp, id] ) ?;
@@ -1383,12 +1402,12 @@ pub struct DeferredGlobalLastUse {
1383
1402
///
1384
1403
/// The key is the registry name (which is its directory name) and the
1385
1404
/// value is the `id` in the `registry_index` table.
1386
- registry_keys : HashMap < InternedString , i64 > ,
1405
+ registry_keys : HashMap < InternedString , ParentId > ,
1387
1406
/// Cache of git keys, used for faster fetching.
1388
1407
///
1389
1408
/// The key is the git db name (which is its directory name) and the value
1390
1409
/// is the `id` in the `git_db` table.
1391
- git_keys : HashMap < InternedString , i64 > ,
1410
+ git_keys : HashMap < InternedString , ParentId > ,
1392
1411
1393
1412
/// New registry index entries to insert.
1394
1413
registry_index_timestamps : HashMap < RegistryIndex , Timestamp > ,
@@ -1691,7 +1710,7 @@ impl DeferredGlobalLastUse {
1691
1710
& mut self ,
1692
1711
conn : & Connection ,
1693
1712
encoded_registry_name : InternedString ,
1694
- ) -> CargoResult < i64 > {
1713
+ ) -> CargoResult < ParentId > {
1695
1714
match self . registry_keys . get ( & encoded_registry_name) {
1696
1715
Some ( i) => Ok ( * i) ,
1697
1716
None => {
@@ -1713,7 +1732,11 @@ impl DeferredGlobalLastUse {
1713
1732
/// cache, or getting it from the database.
1714
1733
///
1715
1734
/// It is an error if the git db does not exist.
1716
- fn git_id ( & mut self , conn : & Connection , encoded_git_name : InternedString ) -> CargoResult < i64 > {
1735
+ fn git_id (
1736
+ & mut self ,
1737
+ conn : & Connection ,
1738
+ encoded_git_name : InternedString ,
1739
+ ) -> CargoResult < ParentId > {
1717
1740
match self . git_keys . get ( & encoded_git_name) {
1718
1741
Some ( i) => Ok ( * i) ,
1719
1742
None => {
0 commit comments