File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
sqlx-postgres/src/options Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ impl PgConnectOptions {
99
99
self . get_host ( ) ,
100
100
self . get_port ( ) ,
101
101
self . get_username ( ) ,
102
- self . get_database ( ) ,
102
+ Some ( self . get_database ( ) ) ,
103
103
) ;
104
104
}
105
105
@@ -533,16 +533,20 @@ impl PgConnectOptions {
533
533
534
534
/// Get the current database name.
535
535
///
536
+ /// Defaults to username if not given.
537
+ ///
536
538
/// # Example
537
539
///
538
540
/// ```rust
539
541
/// # use sqlx_postgres::PgConnectOptions;
540
- /// let options = PgConnectOptions::new()
541
- /// .database("postgres");
542
- /// assert!(options.get_database().is_some());
542
+ /// let options = PgConnectOptions::new().database("postgres");
543
+ /// assert_eq!(options.get_database(), "postgres");
544
+ ///
545
+ /// let options = PgConnectOptions::new().username("alice");
546
+ /// assert_eq!(options.get_database(), "alice");
543
547
/// ```
544
- pub fn get_database ( & self ) -> Option < & str > {
545
- self . database . as_deref ( )
548
+ pub fn get_database ( & self ) -> & str {
549
+ self . database . as_deref ( ) . unwrap_or ( & self . username )
546
550
}
547
551
548
552
/// Get the SSL mode.
You can’t perform that action at this time.
0 commit comments