Skip to content

Commit aebe432

Browse files
committed
chore: renamed DatabaseConnection to DatabaseConnector
1 parent 49ff2ed commit aebe432

9 files changed

Lines changed: 62 additions & 62 deletions

File tree

canyon_core/src/canyon.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use crate::connection::conn_errors::DatasourceNotFound;
22
use crate::connection::database_type::DatabaseType;
33
use crate::connection::datasources::{CanyonSqlConfig, DatasourceConfig, Datasources};
44
use crate::connection::{CANYON_INSTANCE, db_connector, get_canyon_tokio_runtime};
5-
use db_connector::DatabaseConnection;
5+
use db_connector::DatabaseConnector;
66
use std::collections::HashMap;
77
use std::sync::Arc;
88
use std::{error::Error, fs};
99
use tokio::sync::Mutex;
1010

11-
pub type SharedConnection = Arc<Mutex<DatabaseConnection>>;
11+
pub type SharedConnection = Arc<Mutex<DatabaseConnector>>;
1212

1313
/// The `Canyon` struct provides the main entry point for interacting with the Canyon-SQL context.
1414
///
@@ -53,8 +53,8 @@ pub type SharedConnection = Arc<Mutex<DatabaseConnection>>;
5353
/// - `get_mut_connection`: Retrieves a mutable connection from the cache.
5454
pub struct Canyon {
5555
config: Datasources,
56-
connections: HashMap<&'static str, DatabaseConnection>,
57-
default_connection: Option<DatabaseConnection>,
56+
connections: HashMap<&'static str, DatabaseConnector>,
57+
default_connection: Option<DatabaseConnector>,
5858
default_db_type: Option<DatabaseType>,
5959
}
6060

@@ -112,8 +112,8 @@ impl Canyon {
112112
let config_content = fs::read_to_string(&path)?;
113113
let config: Datasources = toml::from_str::<CanyonSqlConfig>(&config_content)?.canyon_sql;
114114

115-
let mut connections: HashMap<&str, DatabaseConnection> = HashMap::new();
116-
let mut default_connection: Option<DatabaseConnection> = None;
115+
let mut connections: HashMap<&str, DatabaseConnector> = HashMap::new();
116+
let mut default_connection: Option<DatabaseConnector> = None;
117117
let mut default_db_type: Option<DatabaseType> = None;
118118

119119
for ds in config.datasources.iter() {
@@ -178,7 +178,7 @@ impl Canyon {
178178
}
179179

180180
// Retrieve a read-only connection from the cache
181-
pub fn get_default_connection(&self) -> Result<&DatabaseConnection, DatasourceNotFound> {
181+
pub fn get_default_connection(&self) -> Result<&DatabaseConnector, DatasourceNotFound> {
182182
self.default_connection
183183
.as_ref()
184184
.ok_or_else(|| DatasourceNotFound::from(None))
@@ -188,8 +188,8 @@ impl Canyon {
188188
///
189189
/// This is a fast and efficient operation: cloning the [`SharedConnection`]
190190
/// simply increases the reference count [`Arc`] without duplicating the underlying
191-
/// [`DatabaseConnection`]. Returns an error if no default connection is configured.
192-
pub fn get_connection(&self, name: &str) -> Result<&DatabaseConnection, DatasourceNotFound> {
191+
/// [`DatabaseConnector`]. Returns an error if no default connection is configured.
192+
pub fn get_connection(&self, name: &str) -> Result<&DatabaseConnector, DatasourceNotFound> {
193193
if name.is_empty() {
194194
return self.get_default_connection();
195195
}
@@ -207,7 +207,7 @@ impl Canyon {
207207
pub async fn get_fast_connection(
208208
&self,
209209
name: &str,
210-
) -> Result<&DatabaseConnection, DatasourceNotFound> {
210+
) -> Result<&DatabaseConnector, DatasourceNotFound> {
211211
// For now, fall back to the regular connection
212212
// In the future, this could automatically use the pool
213213
self.get_connection(name)
@@ -217,7 +217,7 @@ impl Canyon {
217217
mod __impl {
218218
use crate::connection::database_type::DatabaseType;
219219
use crate::connection::datasources::DatasourceConfig;
220-
use crate::connection::db_connector::DatabaseConnection;
220+
use crate::connection::db_connector::DatabaseConnector;
221221
use std::collections::HashMap;
222222
use std::error::Error;
223223
use std::path::PathBuf;
@@ -247,15 +247,15 @@ mod __impl {
247247

248248
pub(crate) async fn process_new_conn_by_datasource(
249249
ds: &DatasourceConfig,
250-
connections: &mut HashMap<&str, DatabaseConnection>,
251-
default: &mut Option<DatabaseConnection>,
250+
connections: &mut HashMap<&str, DatabaseConnector>,
251+
default: &mut Option<DatabaseConnector>,
252252
default_db_type: &mut Option<DatabaseType>,
253253
) -> Result<(), Box<dyn Error + Send + Sync>> {
254254
if default.is_none() {
255255
let cloned_ds_for_default = ds.clone();
256-
*default = Some(DatabaseConnection::new(&cloned_ds_for_default).await?); // Only cloning the smart pointer
256+
*default = Some(DatabaseConnector::new(&cloned_ds_for_default).await?); // Only cloning the smart pointer
257257
}
258-
let conn = DatabaseConnection::new(ds).await?;
258+
let conn = DatabaseConnector::new(ds).await?;
259259
let name: &'static str = Box::leak(ds.name.clone().into_boxed_str());
260260

261261
if default_db_type.is_none() {

canyon_core/src/connection/contracts/impl/database_connection.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use crate::{
22
connection::{
3-
contracts::DbConnection, database_type::DatabaseType, db_connector::DatabaseConnection,
3+
contracts::DbConnection, database_type::DatabaseType, db_connector::DatabaseConnector,
44
},
55
mapper::RowMapper,
66
query::parameters::QueryParameter,
77
rows::{CanyonRows, FromSqlOwnedValue},
88
};
99
use std::error::Error;
1010

11-
impl DbConnection for DatabaseConnection {
11+
impl DbConnection for DatabaseConnector {
1212
async fn query_rows(
1313
&self,
1414
stmt: &str,
@@ -62,7 +62,7 @@ impl DbConnection for DatabaseConnection {
6262
}
6363
}
6464

65-
impl DbConnection for &DatabaseConnection {
65+
impl DbConnection for &DatabaseConnector {
6666
async fn query_rows(
6767
&self,
6868
stmt: &str,
@@ -116,7 +116,7 @@ impl DbConnection for &DatabaseConnection {
116116
}
117117
}
118118

119-
impl DbConnection for &mut DatabaseConnection {
119+
impl DbConnection for &mut DatabaseConnector {
120120
async fn query_rows(
121121
&self,
122122
stmt: &str,
@@ -171,24 +171,24 @@ impl DbConnection for &mut DatabaseConnection {
171171
}
172172

173173
pub(crate) async fn db_conn_query_rows_impl<'a>(
174-
c: &DatabaseConnection,
174+
c: &DatabaseConnector,
175175
stmt: &str,
176176
params: &[&'a (dyn QueryParameter + 'a)],
177177
) -> Result<CanyonRows, Box<dyn Error + Send + Sync>> {
178178
match c {
179179
#[cfg(feature = "postgres")]
180-
DatabaseConnection::Postgres(client) => client.query_rows(stmt, params).await,
180+
DatabaseConnector::Postgres(client) => client.query_rows(stmt, params).await,
181181

182182
#[cfg(feature = "mssql")]
183-
DatabaseConnection::SqlServer(client) => client.query_rows(stmt, params).await,
183+
DatabaseConnector::SqlServer(client) => client.query_rows(stmt, params).await,
184184

185185
#[cfg(feature = "mysql")]
186-
DatabaseConnection::MySQL(client) => client.query_rows(stmt, params).await,
186+
DatabaseConnector::MySQL(client) => client.query_rows(stmt, params).await,
187187
}
188188
}
189189

190190
pub(crate) async fn db_conn_query_one_impl<R>(
191-
c: &DatabaseConnection,
191+
c: &DatabaseConnector,
192192
stmt: &str,
193193
params: &[&'_ (dyn QueryParameter + '_)],
194194
) -> Result<Option<R::Output>, Box<dyn Error + Send + Sync>>
@@ -197,18 +197,18 @@ where
197197
{
198198
match c {
199199
#[cfg(feature = "postgres")]
200-
DatabaseConnection::Postgres(client) => client.query_one::<R>(stmt, params).await,
200+
DatabaseConnector::Postgres(client) => client.query_one::<R>(stmt, params).await,
201201

202202
#[cfg(feature = "mssql")]
203-
DatabaseConnection::SqlServer(client) => client.query_one::<R>(stmt, params).await,
203+
DatabaseConnector::SqlServer(client) => client.query_one::<R>(stmt, params).await,
204204

205205
#[cfg(feature = "mysql")]
206-
DatabaseConnection::MySQL(client) => client.query_one::<R>(stmt, params).await,
206+
DatabaseConnector::MySQL(client) => client.query_one::<R>(stmt, params).await,
207207
}
208208
}
209209

210210
pub(crate) async fn db_conn_query_impl<S, R>(
211-
c: &DatabaseConnection,
211+
c: &DatabaseConnector,
212212
stmt: S,
213213
params: &[&'_ dyn QueryParameter],
214214
) -> Result<Vec<R>, Box<dyn Error + Send + Sync>>
@@ -219,18 +219,18 @@ where
219219
{
220220
match c {
221221
#[cfg(feature = "postgres")]
222-
DatabaseConnection::Postgres(client) => client.query(stmt, params).await,
222+
DatabaseConnector::Postgres(client) => client.query(stmt, params).await,
223223

224224
#[cfg(feature = "mssql")]
225-
DatabaseConnection::SqlServer(client) => client.query(stmt, params).await,
225+
DatabaseConnector::SqlServer(client) => client.query(stmt, params).await,
226226

227227
#[cfg(feature = "mysql")]
228-
DatabaseConnection::MySQL(client) => client.query(stmt, params).await,
228+
DatabaseConnector::MySQL(client) => client.query(stmt, params).await,
229229
}
230230
}
231231

232232
pub(crate) async fn db_conn_query_one_for_impl<T>(
233-
c: &DatabaseConnection,
233+
c: &DatabaseConnector,
234234
stmt: &str,
235235
params: &[&'_ dyn QueryParameter],
236236
) -> Result<T, Box<dyn Error + Send + Sync>>
@@ -239,29 +239,29 @@ where
239239
{
240240
match c {
241241
#[cfg(feature = "postgres")]
242-
DatabaseConnection::Postgres(client) => client.query_one_for(stmt, params).await,
242+
DatabaseConnector::Postgres(client) => client.query_one_for(stmt, params).await,
243243

244244
#[cfg(feature = "mssql")]
245-
DatabaseConnection::SqlServer(client) => client.query_one_for(stmt, params).await,
245+
DatabaseConnector::SqlServer(client) => client.query_one_for(stmt, params).await,
246246

247247
#[cfg(feature = "mysql")]
248-
DatabaseConnection::MySQL(client) => client.query_one_for(stmt, params).await,
248+
DatabaseConnector::MySQL(client) => client.query_one_for(stmt, params).await,
249249
}
250250
}
251251

252252
pub(crate) async fn db_conn_execute_impl(
253-
c: &DatabaseConnection,
253+
c: &DatabaseConnector,
254254
stmt: &str,
255255
params: &[&'_ dyn QueryParameter],
256256
) -> Result<u64, Box<dyn Error + Send + Sync>> {
257257
match c {
258258
#[cfg(feature = "postgres")]
259-
DatabaseConnection::Postgres(client) => client.execute(stmt, params).await,
259+
DatabaseConnector::Postgres(client) => client.execute(stmt, params).await,
260260

261261
#[cfg(feature = "mssql")]
262-
DatabaseConnection::SqlServer(client) => client.execute(stmt, params).await,
262+
DatabaseConnector::SqlServer(client) => client.execute(stmt, params).await,
263263

264264
#[cfg(feature = "mysql")]
265-
DatabaseConnection::MySQL(client) => client.execute(stmt, params).await,
265+
DatabaseConnector::MySQL(client) => client.execute(stmt, params).await,
266266
}
267267
}

canyon_core/src/connection/db_connector.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::error::Error;
1313
/// starts, Canyon gets the information about the desired datasources,
1414
/// process them and generates a pool of 1 to 1 database connection for
1515
/// every datasource defined.
16-
pub enum DatabaseConnection {
16+
pub enum DatabaseConnector {
1717
// NOTE: is this a Datasource instead of a connection?
1818
#[cfg(feature = "postgres")]
1919
Postgres(PostgresConnection),
@@ -23,10 +23,10 @@ pub enum DatabaseConnection {
2323
MySQL(MySQLConnector),
2424
}
2525

26-
unsafe impl Send for DatabaseConnection {}
27-
unsafe impl Sync for DatabaseConnection {}
26+
unsafe impl Send for DatabaseConnector {}
27+
unsafe impl Sync for DatabaseConnector {}
2828

29-
impl DatabaseConnection {
29+
impl DatabaseConnector {
3030
pub async fn new(datasource: &DatasourceConfig) -> Result<Self, Box<dyn Error + Send + Sync>> {
3131
// Add connection pooling at the client level for better performance
3232
match datasource.get_db_type() {
@@ -50,19 +50,19 @@ impl DatabaseConnection {
5050
pub fn get_db_type(&self) -> DatabaseType {
5151
match self {
5252
#[cfg(feature = "postgres")]
53-
DatabaseConnection::Postgres(_) => DatabaseType::PostgreSql,
53+
DatabaseConnector::Postgres(_) => DatabaseType::PostgreSql,
5454
#[cfg(feature = "mssql")]
55-
DatabaseConnection::SqlServer(_) => DatabaseType::SqlServer,
55+
DatabaseConnector::SqlServer(_) => DatabaseType::SqlServer,
5656
#[cfg(feature = "mysql")]
57-
DatabaseConnection::MySQL(_) => DatabaseType::MySQL,
57+
DatabaseConnector::MySQL(_) => DatabaseType::MySQL,
5858
}
5959
}
6060

6161
/*
6262
#[cfg(feature = "postgres")]
6363
pub fn postgres_connection(&self) -> &PostgreSqlConnection {
6464
match self {
65-
DatabaseConnection::Postgres(conn) => conn,
65+
DatabaseConnector::Postgres(conn) => conn,
6666
#[cfg(any(feature = "mssql", feature = "mysql"))]
6767
_ => panic!(),
6868
}
@@ -71,7 +71,7 @@ impl DatabaseConnection {
7171
#[cfg(feature = "mssql")]
7272
pub fn sqlserver_connection(&mut self) -> &mut SqlServerConnection {
7373
match self {
74-
DatabaseConnection::SqlServer(conn) => conn,
74+
DatabaseConnector::SqlServer(conn) => conn,
7575
#[cfg(any(feature = "postgres", feature = "mysql"))]
7676
_ => panic!(),
7777
}
@@ -80,7 +80,7 @@ impl DatabaseConnection {
8080
#[cfg(feature = "mysql")]
8181
pub fn mysql_connection(&self) -> &MysqlConnection {
8282
match self {
83-
DatabaseConnection::MySQL(conn) => conn,
83+
DatabaseConnector::MySQL(conn) => conn,
8484
#[cfg(any(feature = "postgres", feature = "mssql"))]
8585
_ => panic!(),
8686
}

canyon_core/src/connection/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type MsManager = TiberiusConnectionManager;
3636
type SqlServerConnectionPool = Arc<bb8::Pool<MsManager>>;
3737

3838
//
39-
// // TODO's: DatabaseConnection and DataSource can implement default, so there's no need to use str and &str
39+
// // TODO's: DatabaseConnector and DataSource can implement default, so there's no need to use str and &str
4040
// // as defaults anymore, since the can load as the default the first one defined in the config file, or have more
4141
// // complex workflows that are deferred to initialization time
4242
//

canyon_core/src/connection/provisional_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// mod connection_tests {
77
// use tokio;
88
// use super::connection_helpers::*;
9-
// use crate::{db_connector::DatabaseConnection, datasources::{Auth, DatasourceConfig, DatasourceProperties, PostgresAuth}};
9+
// use crate::{db_connector::DatabaseConnector, datasources::{Auth, DatasourceConfig, DatasourceProperties, PostgresAuth}};
1010

1111
// #[tokio::test]
1212
// #[cfg(feature = "postgres")]
@@ -97,7 +97,7 @@
9797
// },
9898
// };
9999

100-
// let result = DatabaseConnection::new(&config).await;
100+
// let result = DatabaseConnector::new(&config).await;
101101
// assert!(result.is_ok());
102102
// }
103103

@@ -116,7 +116,7 @@
116116
// // },
117117
// // };
118118

119-
// // let result = DatabaseConnection::new(&config).await;
119+
// // let result = DatabaseConnector::new(&config).await;
120120
// // assert!(result.is_ok());
121121
// // }
122122

@@ -135,7 +135,7 @@
135135
// // },
136136
// // };
137137

138-
// // let result = DatabaseConnection::new(&config).await;
138+
// // let result = DatabaseConnector::new(&config).await;
139139
// // assert!(result.is_ok());
140140
// // }
141141
// }

canyon_migrations/src/migrations/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
use canyon_core::canyon::Canyon;
1111
use canyon_core::{
1212
column::Column,
13-
connection::db_connector::DatabaseConnection,
13+
connection::db_connector::DatabaseConnector,
1414
row::{Row, RowOperations},
1515
rows::CanyonRows,
1616
transaction::Transaction,
@@ -91,7 +91,7 @@ impl Migrations {
9191
/// chosen by its datasource name property
9292
async fn fetch_database(
9393
ds_name: &str,
94-
db_conn: &DatabaseConnection,
94+
db_conn: &DatabaseConnector,
9595
db_type: DatabaseType,
9696
) -> CanyonRows {
9797
let query = match db_type {

canyon_migrations/src/migrations/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::constants;
22
use canyon_core::canyon::Canyon;
33
use canyon_core::connection::contracts::DbConnection;
4-
use canyon_core::connection::db_connector::DatabaseConnection;
4+
use canyon_core::connection::db_connector::DatabaseConnector;
55
use canyon_core::transaction::Transaction;
66
use canyon_crud::{DatabaseType, DatasourceConfig};
77
use regex::Regex;
@@ -262,7 +262,7 @@ impl CanyonMemory {
262262
/// Generates, if not exists the `canyon_memory` table
263263
async fn create_memory(
264264
datasource_name: &str,
265-
db_conn: &DatabaseConnection,
265+
db_conn: &DatabaseConnector,
266266
database_type: &DatabaseType,
267267
) {
268268
let query = match database_type {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub mod macros {
3030
pub mod connection {
3131
pub use canyon_core::connection::contracts::DbConnection;
3232
pub use canyon_core::connection::database_type::DatabaseType;
33-
pub use canyon_core::connection::db_connector::DatabaseConnection;
33+
pub use canyon_core::connection::db_connector::DatabaseConnector;
3434
}
3535

3636
pub mod core {

0 commit comments

Comments
 (0)