@@ -30,9 +30,9 @@ pub enum AttachedMode {
3030 ReadWrite ,
3131}
3232
33- /// Guard holding a read connection with attached databases
33+ /// Guard holding a read connection with attached database(s)
3434///
35- /// **Important**: Call `detach_all()` before dropping to properly clean up attached databases .
35+ /// **Important**: Call `detach_all()` before dropping to properly clean up attached database(s) .
3636/// Without explicit cleanup, attached databases persist on the pooled connection until
3737/// it's eventually closed. Derefs to `SqliteConnection` for executing queries.
3838#[ must_use = "if unused, the attached connection and locks are immediately dropped" ]
@@ -100,7 +100,7 @@ impl Drop for AttachedReadConnection {
100100 }
101101}
102102
103- /// Guard holding a write connection with attached databases
103+ /// Guard holding a write connection with attached database(s)
104104///
105105/// **Important**: Call `detach_all()` before dropping to properly clean up attached databases.
106106/// Without explicit cleanup, attached databases persist on the pooled connection until
@@ -189,7 +189,7 @@ fn is_valid_schema_name(name: &str) -> bool {
189189 && !name. chars ( ) . next ( ) . unwrap ( ) . is_ascii_digit ( )
190190}
191191
192- /// Acquire a read connection with attached databases
192+ /// Acquire a read connection with attached database(s)
193193///
194194/// This function:
195195/// 1. Acquires a read connection from the main database's read pool
@@ -231,7 +231,7 @@ pub async fn acquire_reader_with_attached(
231231 for spec in & specs {
232232 let path = spec. database . path_str ( ) ;
233233 if !seen_paths. insert ( path. clone ( ) ) {
234- return Err ( Error :: DuplicateDatabaseAttachment ( path) ) ;
234+ return Err ( Error :: DuplicateAttachedDatabase ( path) ) ;
235235 }
236236 }
237237
@@ -261,7 +261,7 @@ pub async fn acquire_reader_with_attached(
261261 Ok ( AttachedReadConnection :: new ( conn, Vec :: new ( ) , schema_names) )
262262}
263263
264- /// Acquire a write connection with attached databases
264+ /// Acquire a write connection with attached database(s)
265265///
266266/// This function:
267267/// 1. Acquires the write connection from the main database
@@ -320,7 +320,7 @@ pub async fn acquire_writer_with_attached(
320320 let mut seen_paths = HashSet :: new ( ) ;
321321 for ( path, _) in & db_entries {
322322 if !seen_paths. insert ( path. as_str ( ) ) {
323- return Err ( Error :: DuplicateDatabaseAttachment ( path. clone ( ) ) ) ;
323+ return Err ( Error :: DuplicateAttachedDatabase ( path. clone ( ) ) ) ;
324324 }
325325 }
326326
@@ -517,19 +517,21 @@ mod tests {
517517 . fetch_one ( & mut * conn)
518518 . await
519519 . unwrap ( ) ;
520+
520521 let value1: String = row1. get ( 0 ) ;
521522 assert_eq ! ( value1, "test_data" ) ;
522523
523524 let row2 = sqlx:: query ( "SELECT value FROM db2.db2 LIMIT 1" )
524525 . fetch_one ( & mut * conn)
525526 . await
526527 . unwrap ( ) ;
528+
527529 let value2: String = row2. get ( 0 ) ;
528530 assert_eq ! ( value2, "test_data" ) ;
529531 }
530532
531533 #[ tokio:: test]
532- async fn test_readwrite_attachment_holds_writer_lock ( ) {
534+ async fn test_attached_database_in_readwrite_mode_holds_writer_lock ( ) {
533535 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
534536 let main_db = create_test_db ( "main.db" , & temp_dir) . await ;
535537 let other_db = create_test_db ( "other.db" , & temp_dir) . await ;
@@ -541,7 +543,7 @@ mod tests {
541543 } ] ;
542544
543545 // Acquire writer with attached database (holds other_db's writer)
544- let _attached_writer = acquire_writer_with_attached ( & main_db, specs) . await . unwrap ( ) ;
546+ let _guard = acquire_writer_with_attached ( & main_db, specs) . await . unwrap ( ) ;
545547
546548 // Try to acquire other_db's writer directly - should block/timeout
547549 let acquire_result = tokio:: time:: timeout (
@@ -571,7 +573,7 @@ mod tests {
571573
572574 // Acquire and drop
573575 {
574- let _attached_writer = acquire_writer_with_attached ( & main_db, specs) . await . unwrap ( ) ;
576+ let _ = acquire_writer_with_attached ( & main_db, specs) . await . unwrap ( ) ;
575577 // Dropped at end of scope
576578 }
577579
@@ -646,7 +648,7 @@ mod tests {
646648 }
647649
648650 #[ tokio:: test]
649- async fn test_attached_sorting_prevents_deadlock ( ) {
651+ async fn test_sorting_attached_databases_prevents_deadlock ( ) {
650652 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
651653 let main_db = create_test_db ( "main.db" , & temp_dir) . await ;
652654 let db_a = create_test_db ( "a.db" , & temp_dir) . await ;
@@ -675,7 +677,7 @@ mod tests {
675677 }
676678
677679 #[ tokio:: test]
678- async fn test_cross_database_attachment_no_deadlock ( ) {
680+ async fn test_attaching_same_databases_in_different_order_concurrently_no_deadlock ( ) {
679681 // This test verifies the fix for the deadlock scenario:
680682 // Thread 1: main=A, attach B
681683 // Thread 2: main=B, attach A
@@ -765,7 +767,7 @@ mod tests {
765767 }
766768
767769 #[ tokio:: test]
768- async fn test_duplicate_database_rejected ( ) {
770+ async fn test_duplicate_attached_database_rejected ( ) {
769771 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
770772 let main_db = create_test_db ( "main.db" , & temp_dir) . await ;
771773 let other_db = create_test_db ( "other.db" , & temp_dir) . await ;
@@ -786,8 +788,8 @@ mod tests {
786788
787789 let result = acquire_writer_with_attached ( & main_db, specs) . await ;
788790 assert ! (
789- matches!( result, Err ( Error :: DuplicateDatabaseAttachment ( _) ) ) ,
790- "Should reject duplicate database attachment "
791+ matches!( result, Err ( Error :: DuplicateAttachedDatabase ( _) ) ) ,
792+ "Should reject duplicate attached database "
791793 ) ;
792794 }
793795
@@ -805,7 +807,7 @@ mod tests {
805807
806808 let result = acquire_writer_with_attached ( & main_db, specs) . await ;
807809 assert ! (
808- matches!( result, Err ( Error :: DuplicateDatabaseAttachment ( _) ) ) ,
810+ matches!( result, Err ( Error :: DuplicateAttachedDatabase ( _) ) ) ,
809811 "Should reject attaching main database to itself"
810812 ) ;
811813 }
0 commit comments