@@ -231,6 +231,7 @@ pub async fn templates_from_config(
231231
232232fn database_connect_options_from_config (
233233 config : & DatabaseConfig ,
234+ opts : & DatabaseConnectOptions ,
234235) -> Result < PgConnectOptions , anyhow:: Error > {
235236 let options = if let Some ( uri) = config. uri . as_deref ( ) {
236237 uri. parse ( )
@@ -315,17 +316,19 @@ fn database_connect_options_from_config(
315316 None => options,
316317 } ;
317318
318- let options = options
319- . log_statements ( LevelFilter :: Debug )
320- . log_slow_statements ( LevelFilter :: Warn , Duration :: from_millis ( 100 ) ) ;
319+ let mut options = options. log_statements ( LevelFilter :: Debug ) ;
320+
321+ if opts. log_slow_statements {
322+ options = options. log_slow_statements ( LevelFilter :: Warn , Duration :: from_millis ( 100 ) ) ;
323+ }
321324
322325 Ok ( options)
323326}
324327
325328/// Create a database connection pool from the configuration
326329#[ tracing:: instrument( name = "db.connect" , skip_all, err( Debug ) ) ]
327330pub async fn database_pool_from_config ( config : & DatabaseConfig ) -> Result < PgPool , anyhow:: Error > {
328- let options = database_connect_options_from_config ( config) ?;
331+ let options = database_connect_options_from_config ( config, & DatabaseConnectOptions :: default ( ) ) ?;
329332 PgPoolOptions :: new ( )
330333 . max_connections ( config. max_connections . into ( ) )
331334 . min_connections ( config. min_connections )
@@ -337,12 +340,37 @@ pub async fn database_pool_from_config(config: &DatabaseConfig) -> Result<PgPool
337340 . context ( "could not connect to the database" )
338341}
339342
343+ pub struct DatabaseConnectOptions {
344+ pub log_slow_statements : bool ,
345+ }
346+
347+ impl Default for DatabaseConnectOptions {
348+ fn default ( ) -> Self {
349+ Self {
350+ log_slow_statements : true ,
351+ }
352+ }
353+ }
354+
340355/// Create a single database connection from the configuration
341356#[ tracing:: instrument( name = "db.connect" , skip_all, err( Debug ) ) ]
342357pub async fn database_connection_from_config (
343358 config : & DatabaseConfig ,
344359) -> Result < PgConnection , anyhow:: Error > {
345- database_connect_options_from_config ( config) ?
360+ database_connect_options_from_config ( config, & DatabaseConnectOptions :: default ( ) ) ?
361+ . connect ( )
362+ . await
363+ . context ( "could not connect to the database" )
364+ }
365+
366+ /// Create a single database connection from the configuration,
367+ /// with specific options.
368+ #[ tracing:: instrument( name = "db.connect" , skip_all, err( Debug ) ) ]
369+ pub async fn database_connection_from_config_with_options (
370+ config : & DatabaseConfig ,
371+ options : & DatabaseConnectOptions ,
372+ ) -> Result < PgConnection , anyhow:: Error > {
373+ database_connect_options_from_config ( config, options) ?
346374 . connect ( )
347375 . await
348376 . context ( "could not connect to the database" )
0 commit comments