@@ -84,54 +84,52 @@ impl<S: app_builder::State> AppBuilder<S> {
8484
8585 self . github_oauth ( github_oauth)
8686 }
87- }
8887
89- impl App {
90- /// Creates a new `App` with a given `Config` and an optional HTTP `Client`
91- ///
92- /// Configures and sets up:
93- ///
94- /// - GitHub OAuth
95- /// - Database connection pools
96- /// - A `git2::Repository` instance from the index repo checkout (that server.rs ensures exists)
97- pub fn new ( config : config:: Server , emails : Emails , github : Box < dyn GitHubClient > ) -> App {
88+ pub fn databases_from_config (
89+ self ,
90+ config : & config:: DatabasePools ,
91+ ) -> AppBuilder < app_builder:: SetReplicaDatabase < app_builder:: SetPrimaryDatabase < S > > >
92+ where
93+ S :: PrimaryDatabase : app_builder:: IsUnset ,
94+ S :: ReplicaDatabase : app_builder:: IsUnset ,
95+ {
9896 let primary_database = {
9997 use secrecy:: ExposeSecret ;
10098
10199 let primary_db_connection_config = ConnectionConfig {
102- statement_timeout : config. db . statement_timeout ,
103- read_only : config. db . primary . read_only_mode ,
100+ statement_timeout : config. statement_timeout ,
101+ read_only : config. primary . read_only_mode ,
104102 } ;
105103
106- let url = connection_url ( & config. db , config. db . primary . url . expose_secret ( ) ) ;
107- let manager_config = make_manager_config ( config. db . enforce_tls ) ;
104+ let url = connection_url ( config, config. primary . url . expose_secret ( ) ) ;
105+ let manager_config = make_manager_config ( config. enforce_tls ) ;
108106 let manager = AsyncDieselConnectionManager :: new_with_config ( url, manager_config) ;
109107
110108 DeadpoolPool :: builder ( manager)
111109 . runtime ( Runtime :: Tokio1 )
112- . max_size ( config. db . primary . pool_size )
113- . wait_timeout ( Some ( config. db . connection_timeout ) )
110+ . max_size ( config. primary . pool_size )
111+ . wait_timeout ( Some ( config. connection_timeout ) )
114112 . post_create ( primary_db_connection_config)
115113 . build ( )
116114 . unwrap ( )
117115 } ;
118116
119- let replica_database = if let Some ( pool_config) = config. db . replica . as_ref ( ) {
117+ let replica_database = if let Some ( pool_config) = config. replica . as_ref ( ) {
120118 use secrecy:: ExposeSecret ;
121119
122120 let replica_db_connection_config = ConnectionConfig {
123- statement_timeout : config. db . statement_timeout ,
121+ statement_timeout : config. statement_timeout ,
124122 read_only : pool_config. read_only_mode ,
125123 } ;
126124
127- let url = connection_url ( & config. db , pool_config. url . expose_secret ( ) ) ;
128- let manager_config = make_manager_config ( config. db . enforce_tls ) ;
125+ let url = connection_url ( config, pool_config. url . expose_secret ( ) ) ;
126+ let manager_config = make_manager_config ( config. enforce_tls ) ;
129127 let manager = AsyncDieselConnectionManager :: new_with_config ( url, manager_config) ;
130128
131129 let pool = DeadpoolPool :: builder ( manager)
132130 . runtime ( Runtime :: Tokio1 )
133131 . max_size ( pool_config. pool_size )
134- . wait_timeout ( Some ( config. db . connection_timeout ) )
132+ . wait_timeout ( Some ( config. connection_timeout ) )
135133 . post_create ( replica_db_connection_config)
136134 . build ( )
137135 . unwrap ( ) ;
@@ -141,9 +139,22 @@ impl App {
141139 None
142140 } ;
143141
144- App :: builder ( )
145- . primary_database ( primary_database)
142+ self . primary_database ( primary_database)
146143 . maybe_replica_database ( replica_database)
144+ }
145+ }
146+
147+ impl App {
148+ /// Creates a new `App` with a given `Config` and an optional HTTP `Client`
149+ ///
150+ /// Configures and sets up:
151+ ///
152+ /// - GitHub OAuth
153+ /// - Database connection pools
154+ /// - A `git2::Repository` instance from the index repo checkout (that server.rs ensures exists)
155+ pub fn new ( config : config:: Server , emails : Emails , github : Box < dyn GitHubClient > ) -> App {
156+ App :: builder ( )
157+ . databases_from_config ( & config. db )
147158 . github ( github)
148159 . github_oauth_from_config ( & config)
149160 . emails ( emails)
0 commit comments