From 44e8b9d7eb0fecfe1568f3cd7058c375f40e6b66 Mon Sep 17 00:00:00 2001 From: Anshul Sanghi Date: Sat, 16 Mar 2024 10:54:58 +0530 Subject: [PATCH 1/5] Expose PostgreSQL Application Name Option Config --- src/database/mod.rs | 20 +++++++++++++++++++- src/driver/sqlx_postgres.rs | 8 ++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/database/mod.rs b/src/database/mod.rs index 67a8d7279..ad824126c 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -63,6 +63,8 @@ pub struct ConnectOptions { /// Schema search path (PostgreSQL only) pub(crate) schema_search_path: Option, pub(crate) test_before_acquire: bool, + #[cfg(feature = "sqlx-postgres")] + pub(crate) application_name: Option<&'static str>, } impl Database { @@ -157,6 +159,8 @@ impl ConnectOptions { sqlcipher_key: None, schema_search_path: None, test_before_acquire: true, + #[cfg(feature = "sqlx-postgres")] + application_name: None, } } @@ -291,10 +295,24 @@ impl ConnectOptions { self.schema_search_path = Some(schema_search_path.into()); self } - + /// If true, the connection will be pinged upon acquiring from the pool (default true). pub fn test_before_acquire(&mut self, value: bool) -> &mut Self { self.test_before_acquire = value; self } + + + /// Set the application name for the connection (PostgreSQL only) + #[cfg(feature = "sqlx-postgres")] + pub fn application_name(&mut self, value: &'static str) -> &mut Self { + self.application_name = Some(value); + self + } + + /// Get the application name for the connection (PostgreSQL only) + #[cfg(feature = "sqlx-postgres")] + pub fn get_application_name(&self) -> Option<&'static str> { + self.application_name + } } diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index ef73001a6..0006619a7 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -49,7 +49,9 @@ impl SqlxPostgresConnector { .url .parse::() .map_err(sqlx_error_to_conn_err)?; + use sqlx::ConnectOptions; + if !options.sqlx_logging { opt = opt.disable_statement_logging(); } else { @@ -61,10 +63,16 @@ impl SqlxPostgresConnector { ); } } + + if let Some(application_name) = options.application_name { + opt = opt.application_name(application_name); + } + let set_search_path_sql = options .schema_search_path .as_ref() .map(|schema| format!("SET search_path = '{schema}'")); + let mut pool_options = options.sqlx_pool_options(); if let Some(sql) = set_search_path_sql { pool_options = pool_options.after_connect(move |conn, _| { From 8c5ec942a9a7ef9a5537d7221decde6d20a87be1 Mon Sep 17 00:00:00 2001 From: Anshul Sanghi Date: Mon, 4 Mar 2024 14:05:16 +0530 Subject: [PATCH 2/5] Fix Formatting --- .../duplicated_many_to_many_paths/bills.rs | 4 ++-- .../users_saved_bills.rs | 4 ++-- .../duplicated_many_to_many_paths/users_votes.rs | 4 ++-- .../src/tests_cfg/many_to_many/bills.rs | 4 ++-- .../src/tests_cfg/many_to_many/users_votes.rs | 4 ++-- .../src/tests_cfg/many_to_many_multiple/bills.rs | 4 ++-- .../many_to_many_multiple/users_votes.rs | 12 ++++++------ .../src/tests_cfg/self_referencing/bills.rs | 8 ++------ .../src/tests_cfg/self_referencing/users.rs | 16 ++++------------ src/database/mod.rs | 3 +-- 10 files changed, 25 insertions(+), 38 deletions(-) diff --git a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs index a3a6911b9..baf33426e 100644 --- a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub user_id: Option , + pub user_id: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -15,7 +15,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "NoAction", - on_delete = "NoAction", + on_delete = "NoAction" )] Users, #[sea_orm(has_many = "super::users_saved_bills::Entity")] diff --git a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs index 4ef0281cd..575bac58f 100644 --- a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs +++ b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs @@ -16,7 +16,7 @@ pub enum Relation { from = "Column::BillId", to = "super::bills::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Bills, #[sea_orm( @@ -24,7 +24,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs index a04ad7fa7..62f9cf7d0 100644 --- a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs +++ b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs @@ -17,7 +17,7 @@ pub enum Relation { from = "Column::BillId", to = "super::bills::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Bills, #[sea_orm( @@ -25,7 +25,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs b/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs index 5a3acef9c..f2de469f0 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub user_id: Option , + pub user_id: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -15,7 +15,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "NoAction", - on_delete = "NoAction", + on_delete = "NoAction" )] Users, #[sea_orm(has_many = "super::users_votes::Entity")] diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs b/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs index a04ad7fa7..62f9cf7d0 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs @@ -17,7 +17,7 @@ pub enum Relation { from = "Column::BillId", to = "super::bills::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Bills, #[sea_orm( @@ -25,7 +25,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs index 5094e5885..6874aeed0 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub user_id: Option , + pub user_id: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -15,7 +15,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "NoAction", - on_delete = "NoAction", + on_delete = "NoAction" )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs index 87187f4c0..29fb173cb 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs @@ -7,8 +7,8 @@ pub struct Model { pub user_id: i32, #[sea_orm(primary_key, auto_increment = false)] pub bill_id: i32, - pub user_idd: Option , - pub bill_idd: Option , + pub user_idd: Option, + pub bill_idd: Option, pub vote: bool, } @@ -17,25 +17,25 @@ pub enum Relation { #[sea_orm( belongs_to = "super::bills::Entity", from = "Column::BillIdd", - to = "super::bills::Column::Id", + to = "super::bills::Column::Id" )] Bills2, #[sea_orm( belongs_to = "super::bills::Entity", from = "Column::BillId", - to = "super::bills::Column::Id", + to = "super::bills::Column::Id" )] Bills1, #[sea_orm( belongs_to = "super::users::Entity", from = "Column::UserIdd", - to = "super::users::Column::Id", + to = "super::users::Column::Id" )] Users2, #[sea_orm( belongs_to = "super::users::Entity", from = "Column::UserId", - to = "super::users::Column::Id", + to = "super::users::Column::Id" )] Users1, } diff --git a/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs b/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs index 583655f67..22cfc4690 100644 --- a/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs @@ -5,16 +5,12 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub self_id: Option , + pub self_id: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { - #[sea_orm( - belongs_to = "Entity", - from = "Column::SelfId", - to = "Column::Id", - )] + #[sea_orm(belongs_to = "Entity", from = "Column::SelfId", to = "Column::Id")] SelfRef, } diff --git a/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs b/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs index b54f3e5e2..487ba9409 100644 --- a/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs +++ b/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs @@ -5,23 +5,15 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub self_id: Option , - pub self_idd: Option , + pub self_id: Option, + pub self_idd: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { - #[sea_orm( - belongs_to = "Entity", - from = "Column::SelfId", - to = "Column::Id", - )] + #[sea_orm(belongs_to = "Entity", from = "Column::SelfId", to = "Column::Id")] SelfRef2, - #[sea_orm( - belongs_to = "Entity", - from = "Column::SelfIdd", - to = "Column::Id", - )] + #[sea_orm(belongs_to = "Entity", from = "Column::SelfIdd", to = "Column::Id")] SelfRef1, } diff --git a/src/database/mod.rs b/src/database/mod.rs index ad824126c..05a530c0c 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -295,14 +295,13 @@ impl ConnectOptions { self.schema_search_path = Some(schema_search_path.into()); self } - + /// If true, the connection will be pinged upon acquiring from the pool (default true). pub fn test_before_acquire(&mut self, value: bool) -> &mut Self { self.test_before_acquire = value; self } - /// Set the application name for the connection (PostgreSQL only) #[cfg(feature = "sqlx-postgres")] pub fn application_name(&mut self, value: &'static str) -> &mut Self { From b2f96cd507c79b9760166ce6ae8f622ec3a7a0ed Mon Sep 17 00:00:00 2001 From: Anshul Sanghi Date: Mon, 4 Mar 2024 14:21:57 +0530 Subject: [PATCH 3/5] Revert "Fix Formatting" This reverts commit 16c4e66096ae4bcf9f444ef9a0462d883f7e6be0. --- .../duplicated_many_to_many_paths/bills.rs | 4 ++-- .../users_saved_bills.rs | 4 ++-- .../duplicated_many_to_many_paths/users_votes.rs | 4 ++-- .../src/tests_cfg/many_to_many/bills.rs | 4 ++-- .../src/tests_cfg/many_to_many/users_votes.rs | 4 ++-- .../src/tests_cfg/many_to_many_multiple/bills.rs | 4 ++-- .../many_to_many_multiple/users_votes.rs | 12 ++++++------ .../src/tests_cfg/self_referencing/bills.rs | 8 ++++++-- .../src/tests_cfg/self_referencing/users.rs | 16 ++++++++++++---- src/database/mod.rs | 3 ++- 10 files changed, 38 insertions(+), 25 deletions(-) diff --git a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs index baf33426e..a3a6911b9 100644 --- a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub user_id: Option, + pub user_id: Option , } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -15,7 +15,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "NoAction", - on_delete = "NoAction" + on_delete = "NoAction", )] Users, #[sea_orm(has_many = "super::users_saved_bills::Entity")] diff --git a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs index 575bac58f..4ef0281cd 100644 --- a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs +++ b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs @@ -16,7 +16,7 @@ pub enum Relation { from = "Column::BillId", to = "super::bills::Column::Id", on_update = "Cascade", - on_delete = "Cascade" + on_delete = "Cascade", )] Bills, #[sea_orm( @@ -24,7 +24,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "Cascade", - on_delete = "Cascade" + on_delete = "Cascade", )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs index 62f9cf7d0..a04ad7fa7 100644 --- a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs +++ b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs @@ -17,7 +17,7 @@ pub enum Relation { from = "Column::BillId", to = "super::bills::Column::Id", on_update = "Cascade", - on_delete = "Cascade" + on_delete = "Cascade", )] Bills, #[sea_orm( @@ -25,7 +25,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "Cascade", - on_delete = "Cascade" + on_delete = "Cascade", )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs b/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs index f2de469f0..5a3acef9c 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub user_id: Option, + pub user_id: Option , } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -15,7 +15,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "NoAction", - on_delete = "NoAction" + on_delete = "NoAction", )] Users, #[sea_orm(has_many = "super::users_votes::Entity")] diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs b/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs index 62f9cf7d0..a04ad7fa7 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs @@ -17,7 +17,7 @@ pub enum Relation { from = "Column::BillId", to = "super::bills::Column::Id", on_update = "Cascade", - on_delete = "Cascade" + on_delete = "Cascade", )] Bills, #[sea_orm( @@ -25,7 +25,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "Cascade", - on_delete = "Cascade" + on_delete = "Cascade", )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs index 6874aeed0..5094e5885 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub user_id: Option, + pub user_id: Option , } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -15,7 +15,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "NoAction", - on_delete = "NoAction" + on_delete = "NoAction", )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs index 29fb173cb..87187f4c0 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs @@ -7,8 +7,8 @@ pub struct Model { pub user_id: i32, #[sea_orm(primary_key, auto_increment = false)] pub bill_id: i32, - pub user_idd: Option, - pub bill_idd: Option, + pub user_idd: Option , + pub bill_idd: Option , pub vote: bool, } @@ -17,25 +17,25 @@ pub enum Relation { #[sea_orm( belongs_to = "super::bills::Entity", from = "Column::BillIdd", - to = "super::bills::Column::Id" + to = "super::bills::Column::Id", )] Bills2, #[sea_orm( belongs_to = "super::bills::Entity", from = "Column::BillId", - to = "super::bills::Column::Id" + to = "super::bills::Column::Id", )] Bills1, #[sea_orm( belongs_to = "super::users::Entity", from = "Column::UserIdd", - to = "super::users::Column::Id" + to = "super::users::Column::Id", )] Users2, #[sea_orm( belongs_to = "super::users::Entity", from = "Column::UserId", - to = "super::users::Column::Id" + to = "super::users::Column::Id", )] Users1, } diff --git a/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs b/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs index 22cfc4690..583655f67 100644 --- a/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs @@ -5,12 +5,16 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub self_id: Option, + pub self_id: Option , } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { - #[sea_orm(belongs_to = "Entity", from = "Column::SelfId", to = "Column::Id")] + #[sea_orm( + belongs_to = "Entity", + from = "Column::SelfId", + to = "Column::Id", + )] SelfRef, } diff --git a/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs b/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs index 487ba9409..b54f3e5e2 100644 --- a/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs +++ b/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs @@ -5,15 +5,23 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub self_id: Option, - pub self_idd: Option, + pub self_id: Option , + pub self_idd: Option , } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { - #[sea_orm(belongs_to = "Entity", from = "Column::SelfId", to = "Column::Id")] + #[sea_orm( + belongs_to = "Entity", + from = "Column::SelfId", + to = "Column::Id", + )] SelfRef2, - #[sea_orm(belongs_to = "Entity", from = "Column::SelfIdd", to = "Column::Id")] + #[sea_orm( + belongs_to = "Entity", + from = "Column::SelfIdd", + to = "Column::Id", + )] SelfRef1, } diff --git a/src/database/mod.rs b/src/database/mod.rs index 05a530c0c..ad824126c 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -295,13 +295,14 @@ impl ConnectOptions { self.schema_search_path = Some(schema_search_path.into()); self } - + /// If true, the connection will be pinged upon acquiring from the pool (default true). pub fn test_before_acquire(&mut self, value: bool) -> &mut Self { self.test_before_acquire = value; self } + /// Set the application name for the connection (PostgreSQL only) #[cfg(feature = "sqlx-postgres")] pub fn application_name(&mut self, value: &'static str) -> &mut Self { From f8f35dd2d81606aea14620b287318d2dd63f5afd Mon Sep 17 00:00:00 2001 From: Anshul Sanghi Date: Mon, 4 Mar 2024 14:26:18 +0530 Subject: [PATCH 4/5] Fix Formatting --- src/database/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/database/mod.rs b/src/database/mod.rs index ad824126c..05a530c0c 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -295,14 +295,13 @@ impl ConnectOptions { self.schema_search_path = Some(schema_search_path.into()); self } - + /// If true, the connection will be pinged upon acquiring from the pool (default true). pub fn test_before_acquire(&mut self, value: bool) -> &mut Self { self.test_before_acquire = value; self } - /// Set the application name for the connection (PostgreSQL only) #[cfg(feature = "sqlx-postgres")] pub fn application_name(&mut self, value: &'static str) -> &mut Self { From cdf9c965d8d767ec904dd4b3c957301e833a52fe Mon Sep 17 00:00:00 2001 From: Anshul Sanghi Date: Wed, 1 May 2024 16:00:50 +0530 Subject: [PATCH 5/5] Remove Unnecessary Feature Guards --- src/database/mod.rs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/database/mod.rs b/src/database/mod.rs index 05a530c0c..7d357a2fa 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -1,16 +1,7 @@ +use std::borrow::Cow; use std::time::Duration; -mod connection; -mod db_connection; -#[cfg(feature = "mock")] -#[cfg_attr(docsrs, doc(cfg(feature = "mock")))] -mod mock; -#[cfg(feature = "proxy")] -#[cfg_attr(docsrs, doc(cfg(feature = "proxy")))] -mod proxy; -mod statement; -mod stream; -mod transaction; +use tracing::instrument; pub use connection::*; pub use db_connection::*; @@ -21,13 +12,23 @@ pub use mock::*; #[cfg_attr(docsrs, doc(cfg(feature = "proxy")))] pub use proxy::*; pub use statement::*; -use std::borrow::Cow; pub use stream::*; -use tracing::instrument; pub use transaction::*; use crate::error::*; +mod connection; +mod db_connection; +#[cfg(feature = "mock")] +#[cfg_attr(docsrs, doc(cfg(feature = "mock")))] +mod mock; +#[cfg(feature = "proxy")] +#[cfg_attr(docsrs, doc(cfg(feature = "proxy")))] +mod proxy; +mod statement; +mod stream; +mod transaction; + /// Defines a database #[derive(Debug, Default)] pub struct Database; @@ -63,7 +64,6 @@ pub struct ConnectOptions { /// Schema search path (PostgreSQL only) pub(crate) schema_search_path: Option, pub(crate) test_before_acquire: bool, - #[cfg(feature = "sqlx-postgres")] pub(crate) application_name: Option<&'static str>, } @@ -159,7 +159,6 @@ impl ConnectOptions { sqlcipher_key: None, schema_search_path: None, test_before_acquire: true, - #[cfg(feature = "sqlx-postgres")] application_name: None, } } @@ -303,14 +302,12 @@ impl ConnectOptions { } /// Set the application name for the connection (PostgreSQL only) - #[cfg(feature = "sqlx-postgres")] pub fn application_name(&mut self, value: &'static str) -> &mut Self { self.application_name = Some(value); self } /// Get the application name for the connection (PostgreSQL only) - #[cfg(feature = "sqlx-postgres")] pub fn get_application_name(&self) -> Option<&'static str> { self.application_name }