@@ -219,6 +219,7 @@ pub async fn templates_from_config(
219219
220220fn database_connect_options_from_config (
221221 config : & DatabaseConfig ,
222+ opts : & DatabaseConnectOptions ,
222223) -> Result < PgConnectOptions , anyhow:: Error > {
223224 let options = if let Some ( uri) = config. uri . as_deref ( ) {
224225 uri. parse ( )
@@ -301,17 +302,19 @@ fn database_connect_options_from_config(
301302 None => options,
302303 } ;
303304
304- let options = options
305- . log_statements ( LevelFilter :: Debug )
306- . log_slow_statements ( LevelFilter :: Warn , Duration :: from_millis ( 100 ) ) ;
305+ let mut options = options. log_statements ( LevelFilter :: Debug ) ;
306+
307+ if opts. log_slow_statements {
308+ options = options. log_slow_statements ( LevelFilter :: Warn , Duration :: from_millis ( 100 ) ) ;
309+ }
307310
308311 Ok ( options)
309312}
310313
311314/// Create a database connection pool from the configuration
312315#[ tracing:: instrument( name = "db.connect" , skip_all, err( Debug ) ) ]
313316pub async fn database_pool_from_config ( config : & DatabaseConfig ) -> Result < PgPool , anyhow:: Error > {
314- let options = database_connect_options_from_config ( config) ?;
317+ let options = database_connect_options_from_config ( config, & Default :: default ( ) ) ?;
315318 PgPoolOptions :: new ( )
316319 . max_connections ( config. max_connections . into ( ) )
317320 . min_connections ( config. min_connections )
@@ -323,12 +326,37 @@ pub async fn database_pool_from_config(config: &DatabaseConfig) -> Result<PgPool
323326 . context ( "could not connect to the database" )
324327}
325328
329+ pub struct DatabaseConnectOptions {
330+ pub log_slow_statements : bool ,
331+ }
332+
333+ impl Default for DatabaseConnectOptions {
334+ fn default ( ) -> Self {
335+ Self {
336+ log_slow_statements : true ,
337+ }
338+ }
339+ }
340+
326341/// Create a single database connection from the configuration
327342#[ tracing:: instrument( name = "db.connect" , skip_all, err( Debug ) ) ]
328343pub async fn database_connection_from_config (
329344 config : & DatabaseConfig ,
330345) -> Result < PgConnection , anyhow:: Error > {
331- database_connect_options_from_config ( config) ?
346+ database_connect_options_from_config ( config, & Default :: default ( ) ) ?
347+ . connect ( )
348+ . await
349+ . context ( "could not connect to the database" )
350+ }
351+
352+ /// Create a single database connection from the configuration,
353+ /// with specific options.
354+ #[ tracing:: instrument( name = "db.connect" , skip_all, err( Debug ) ) ]
355+ pub async fn database_connection_from_config_with_options (
356+ config : & DatabaseConfig ,
357+ options : & DatabaseConnectOptions ,
358+ ) -> Result < PgConnection , anyhow:: Error > {
359+ database_connect_options_from_config ( config, options) ?
332360 . connect ( )
333361 . await
334362 . context ( "could not connect to the database" )
0 commit comments