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 {
9999 self . get_host ( ) ,
100100 self . get_port ( ) ,
101101 self . get_username ( ) ,
102- self . get_database ( ) ,
102+ Some ( self . get_database ( ) ) ,
103103 ) ;
104104 }
105105
@@ -533,16 +533,20 @@ impl PgConnectOptions {
533533
534534 /// Get the current database name.
535535 ///
536+ /// Defaults to username if not given.
537+ ///
536538 /// # Example
537539 ///
538540 /// ```rust
539541 /// # 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");
543547 /// ```
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 )
546550 }
547551
548552 /// Get the SSL mode.
You can’t perform that action at this time.
0 commit comments