Skip to content

Commit 044efe7

Browse files
committed
refactor: more querybuilder public interface
1 parent f8ce5e4 commit 044efe7

23 files changed

Lines changed: 109 additions & 60 deletions

File tree

canyon_core/src/connection/clients/mssql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl DbConnection for SqlServerConnector {
130130
.map_err(From::from)
131131
}
132132

133-
async fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
133+
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
134134
Ok(DatabaseType::SqlServer)
135135
}
136136
}

canyon_core/src/connection/clients/mysql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl DbConnection for MySQLConnector {
8787
Ok(mysql_stmt.run(mysql_connection).await?.affected_rows())
8888
}
8989

90-
async fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
90+
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
9191
Ok(DatabaseType::MySQL)
9292
}
9393
}

canyon_core/src/connection/clients/postgresql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl DbConnection for PostgresConnector {
110110
.map_err(From::from)
111111
}
112112

113-
async fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
113+
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
114114
Ok(DatabaseType::PostgreSql)
115115
}
116116
}

canyon_core/src/connection/contracts/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,5 @@ pub trait DbConnection {
114114
///
115115
/// # Returns
116116
/// A `Result` containing the [`DatabaseType`] on success or an error on failure.
117-
async fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>>;
117+
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>>;
118118
}

canyon_core/src/connection/datasources.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl DatasourceConfig {
137137
DatabaseType::SqlServer => 1433,
138138
#[cfg(feature = "mysql")]
139139
DatabaseType::MySQL => 3306,
140+
_ => todo!("Non legal port cfg"),
140141
})
141142
}
142143
}

canyon_core/src/connection/db_connector.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ impl DatabaseConnector {
4848

4949
#[cfg(feature = "mysql")]
5050
DatabaseType::MySQL => Ok(Self::MySQL(MySQLConnector::new(datasource).await?)),
51+
52+
DatabaseType::Deferred => panic!("Deferred connection"),
5153
}
5254
}
5355

canyon_core/src/connection/impl_db_connection_macro.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ macro_rules! impl_db_connection_for_db_connector {
104104
}
105105
}
106106

107-
async fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
107+
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
108108
Ok(self.get_db_type())
109109
}
110110
}
@@ -168,7 +168,7 @@ macro_rules! impl_db_connection_for_str {
168168
conn.execute(stmt, params).await
169169
}
170170

171-
async fn get_database_type(
171+
fn get_database_type(
172172
&self,
173173
) -> Result<
174174
$crate::connection::database_type::DatabaseType,

canyon_core/src/connection/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ where
117117
self.lock().await.execute(stmt, params).await
118118
}
119119

120-
async fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
120+
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
121121
todo!()
122122
}
123123
}

canyon_core/src/query/operators.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl Operator for Like {
6767
DatabaseType::SqlServer => "VARCHAR",
6868
#[cfg(feature = "mysql")]
6969
DatabaseType::MySQL => "CHAR",
70+
_ => panic!("Provisional LIKE"),
7071
};
7172

7273
match *self {

canyon_core/src/query/querybuilder/contracts/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@ pub trait UpdateQueryBuilderOps<'a>: QueryBuilderOps<'a> {
1212
/// Creates an SQL `SET` clause by specifying the columns that must be updated in the sentence,
1313
/// but without adding any [`QueryParameter`] value to the internal querybuilder
1414
fn set(self, columns: &'a [String]) -> Result<Self, Box<dyn Error + Send + Sync + 'a>>
15-
where Self: std::marker::Sized;
15+
where Self: Sized;
1616

1717
/// Similar to [`Self::set`] but storing the underlying update values for each column in the
1818
/// internal values collection of the [`crate::query::querybuilder::QueryBuilder`]
1919
fn set_with_values<Z, Q>(self, columns: &'a [(Z, Q)]) -> Result<Self, Box<dyn Error + Send + Sync + 'a>>
2020
where
2121
Z: FieldIdentifier,
2222
Q: QueryParameter,
23-
Self: std::marker::Sized,
23+
Self: Sized,
2424
Vec<&'a dyn QueryParameter>: Extend<&'a Q>;
2525
}
2626

2727
pub trait SelectQueryBuilderOps<'a>: QueryBuilderOps<'a> {
28+
/// Adds the column names that must be added to the query in order to retrieve the correct mapped fields
29+
/// If this method isn't invoked, the querybuilder will create a SELECT * FROM query
30+
fn with_columns(self, columns: &'a [String]) -> Self;
31+
2832
/// Adds a *LEFT JOIN* SQL statement to the underlying
2933
/// `Sql Statement` held by the [`QueryBuilder`], where:
3034
///

0 commit comments

Comments
 (0)