Skip to content

Commit 48287f0

Browse files
committed
refactor(WIP-5)!: Querybuilder public interface
1 parent ad4082d commit 48287f0

19 files changed

Lines changed: 75 additions & 73 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-
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
133+
async 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-
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
90+
async 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-
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
113+
async 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-
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>>;
117+
async fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>>;
118118
}

canyon_core/src/connection/database_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl From<&Auth> for DatabaseType {
3333
/// The default implementation for [`DatabaseType`] returns the database type for the first
3434
/// datasource configured
3535
impl DatabaseType {
36-
pub fn default_type() -> Result<Self, Box<dyn Error + Send + Sync>> {
36+
pub async fn default_type() -> Result<Self, Box<dyn Error + Send + Sync>> {
3737
Canyon::instance()?
3838
.get_default_db_type()
3939
.map_err(|err| Box::new(err) as Box<dyn Error + Send + Sync>)

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-
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
107+
async 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-
fn get_database_type(
171+
async 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-
fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
120+
async fn get_database_type(&self) -> Result<DatabaseType, Box<dyn Error + Send + Sync>> {
121121
todo!()
122122
}
123123
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub trait DeleteQueryBuilderOps<'a>: QueryBuilderOps<'a> {}
1111
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
14-
fn set(self, columns: &'a [&'a str]) -> Result<Self, Box<dyn Error + Send + Sync + 'a>>
14+
fn set(self, columns: &'a [String]) -> Result<Self, Box<dyn Error + Send + Sync + 'a>>
1515
where Self: std::marker::Sized;
1616

1717
/// Similar to [`Self::set`] but storing the underlying update values for each column in the

canyon_core/src/query/querybuilder/types/delete.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@ impl<'a> QueryBuilderOps<'a> for DeleteQueryBuilder<'a> {
4646
}
4747

4848
#[inline]
49-
fn r#where<Z: FieldValueIdentifier>(mut self, r#where: &'a Z, op: Comp) -> Self {
50-
self._inner.r#where(r#where, op);
49+
fn r#where(mut self, column_name: &'a str, operator: Comp, value: &'a dyn QueryParameter) -> Self {
50+
self._inner.r#where(column_name, operator, value);
51+
self
52+
}
53+
54+
#[inline]
55+
fn where_value<Z: FieldValueIdentifier>(mut self, r#where: &'a Z, op: Comp) -> Self {
56+
self._inner.where_value(r#where, op);
5157
self
5258
}
5359

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ impl Display for TableMetadata {
6262
}
6363
}
6464

65+
impl AsRef<str> for TableMetadata {
66+
fn as_ref(&self) -> &str {
67+
self.schema.as_ref().unwrap()
68+
}
69+
}
70+
6571
pub struct ConditionClause<'a> {
6672
// TODO: where are missing complex where usages, like in joins, so we should consider to add the table
6773
// to the column like where table.column = ...

0 commit comments

Comments
 (0)