@@ -119,7 +119,7 @@ pub trait Connection: Send {
119119 {
120120 let options = url. parse ( ) ;
121121
122- Box :: pin ( async move { Ok ( Self :: connect_with ( & options?) . await ? ) } )
122+ Box :: pin ( async move { Self :: connect_with ( & options?) . await } )
123123 }
124124
125125 /// Establish a new database connection with the provided options.
@@ -158,24 +158,22 @@ impl LogSettings {
158158 }
159159}
160160
161- pub trait ConnectOptions : ' static + Send + Sync + FromStr < Err = Error > + Debug + Clone {
162- type Connection : Connection + ? Sized ;
161+ pub trait ConnectOptions : Sized + Send + Sync + ' static {
162+ type Connection : Connection ;
163163
164- /// Establish a new database connection with the options specified by `self`.
165- fn connect ( & self ) -> BoxFuture < ' _ , Result < Self :: Connection , Error > >
166- where
167- Self :: Connection : Sized ;
164+ fn from_url ( url : & str ) -> Result < Self , Error > ;
168165
169- /// Log executed statements with the specified `level`
170- fn log_statements ( & mut self , level : LevelFilter ) -> & mut Self ;
166+ fn connect ( & self ) -> BoxFuture < ' _ , Result < Self :: Connection , Error > > ;
171167
172- /// Log executed statements with a duration above the specified `duration`
173- /// at the specified `level`.
174- fn log_slow_statements ( & mut self , level : LevelFilter , duration : Duration ) -> & mut Self ;
168+ fn connect_with ( options : & Self ) -> BoxFuture < ' _ , Result < Self :: Connection , Error > > ;
175169
176- /// Entirely disables statement logging (both slow and regular).
177- fn disable_statement_logging ( & mut self ) -> & mut Self {
178- self . log_statements ( LevelFilter :: Off )
179- . log_slow_statements ( LevelFilter :: Off , Duration :: default ( ) )
170+ fn from_env ( ) -> Result < Self , Error > {
171+ let options = Self :: from_url ( & std:: env:: var ( "DATABASE_URL" ) ?) ?;
172+ Box :: pin ( async move { Self :: connect_with ( & options?) . await } )
180173 }
174+
175+ fn create_pool (
176+ & self ,
177+ options : crate :: pool:: PoolOptions < Self :: Connection > ,
178+ ) -> Result < crate :: pool:: Pool < Self :: Connection > , Error > ;
181179}
0 commit comments