Skip to content

Commit 04605ff

Browse files
committed
chore: cargo fmt
1 parent ef2ac17 commit 04605ff

30 files changed

Lines changed: 407 additions & 244 deletions

File tree

canyon_core/src/connection/database_type.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ pub enum DatabaseType {
7070
/// .where_("id", Comp::Eq, &42)
7171
/// .build()?; // resolved dynamically to the active database type
7272
/// ```
73-
#[default] Deferred,
73+
#[default]
74+
Deferred,
7475
}
7576

7677
impl Display for DatabaseType {

canyon_core/src/query/operators.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ pub enum Comp {
2222
/// Operator "=<" less or equals than value
2323
LtEq,
2424
/// A "LIKE" comp operator
25-
Like(LikeKind)
25+
Like(LikeKind),
2626
}
2727

28-
2928
impl Display for Comp {
3029
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3130
let op = match *self {
@@ -35,7 +34,7 @@ impl Display for Comp {
3534
Self::GtEq => ">=",
3635
Self::Lt => "<",
3736
Self::LtEq => "<=",
38-
Self::Like(ref __kind) => "LIKE"
37+
Self::Like(ref __kind) => "LIKE",
3938
};
4039
write!(f, "{}", op)
4140
}

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
//! Contains the elements that makes part of the formal declaration
22
//! of the behaviour of the Canyon-SQL QueryBuilder
33
4-
use std::error::Error;
54
use crate::query::bounds::{FieldIdentifier, FieldValueIdentifier};
65
use crate::query::operators::Comp;
76
use crate::query::parameters::QueryParameter;
87
use crate::query::querybuilder::syntax::column::ColumnRef;
98
use crate::query::querybuilder::syntax::table_metadata::TableMetadata;
9+
use std::error::Error;
1010

1111
pub trait DeleteQueryBuilderOps<'a>: QueryBuilderOps<'a> {}
1212

1313
pub trait UpdateQueryBuilderOps<'a>: QueryBuilderOps<'a> {
1414
/// Creates an SQL `SET` clause by specifying the columns that must be updated in the sentence,
1515
/// but without adding any [`QueryParameter`] value to the internal querybuilder.
16-
///
16+
///
1717
/// Is it the responsibility of the callee to pass the query values that will match the generated
1818
/// sql placeholders
19-
///
19+
///
2020
/// Note: If there's values already on the querybuilder, and the only placeholders api is called,
2121
/// UB (provisionally) will occur, since we're refactoring the API's and these are subject to change
2222
/// at any time while in the v0.x.x
23-
fn set<I: Into<ColumnRef<'a>>>(self, columns: Vec<I>) -> Result<Self, Box<dyn Error + Send + Sync + 'a>>
24-
where Self: Sized;
23+
fn set<I: Into<ColumnRef<'a>>>(
24+
self,
25+
columns: Vec<I>,
26+
) -> Result<Self, Box<dyn Error + Send + Sync + 'a>>
27+
where
28+
Self: Sized;
2529

2630
/// Similar to [`Self::set`] but storing the underlying update values for each column in the
2731
/// internal values collection of the [`crate::query::querybuilder::QueryBuilder`]
28-
fn set_values<Z, Q>(self, columns: &'a [(Z, Q)]) -> Result<Self, Box<dyn Error + Send + Sync + 'a>>
32+
fn set_values<Z, Q>(
33+
self,
34+
columns: &'a [(Z, Q)],
35+
) -> Result<Self, Box<dyn Error + Send + Sync + 'a>>
2936
where
3037
Z: FieldIdentifier,
3138
Q: QueryParameter,
@@ -36,7 +43,7 @@ pub trait SelectQueryBuilderOps<'a>: QueryBuilderOps<'a> {
3643
/// Adds the column names that must be added to the query in order to retrieve the correct mapped fields
3744
/// If this method isn't invoked, the querybuilder will create a SELECT * FROM query
3845
fn with_columns<I: Into<ColumnRef<'a>>>(self, columns: Vec<I>) -> Self;
39-
46+
4047
/// Adds a *LEFT JOIN* SQL statement to the underlying
4148
/// `Sql Statement` held by the [`QueryBuilder`], where:
4249
///
@@ -181,7 +188,11 @@ pub trait QueryBuilderOps<'a> {
181188
/// the field name that maps the targeted column name
182189
/// * `values` - An array of [`QueryParameter`] with the values to filter
183190
/// inside the `IN` operator
184-
fn and_values_in<'b, Z, Q>(self, column: Z, values: &'a [Q]) -> Result<Self, Box<dyn Error + Send + Sync + 'b>>
191+
fn and_values_in<'b, Z, Q>(
192+
self,
193+
column: Z,
194+
values: &'a [Q],
195+
) -> Result<Self, Box<dyn Error + Send + Sync + 'b>>
185196
where
186197
Z: FieldIdentifier,
187198
Q: QueryParameter,
@@ -195,7 +206,11 @@ pub trait QueryBuilderOps<'a> {
195206
/// the field name that maps the targeted column name
196207
/// * `values` - An array of [`QueryParameter`] with the values to filter
197208
/// inside the `IN` operator
198-
fn or_values_in<'b, Z, Q>(self, r#or: Z, values: &'a [Q]) -> Result<Self, Box<dyn Error + Send + Sync + 'b>>
209+
fn or_values_in<'b, Z, Q>(
210+
self,
211+
r#or: Z,
212+
values: &'a [Q],
213+
) -> Result<Self, Box<dyn Error + Send + Sync + 'b>>
199214
where
200215
Z: FieldIdentifier,
201216
Q: QueryParameter,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub mod contracts;
2-
pub mod types;
32
pub mod syntax;
3+
pub mod types;
44

55
pub use self::{contracts::*, types::*};

canyon_core/src/query/querybuilder/syntax/ast/delete.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::query::querybuilder::syntax::emitter::{AsEmitBody, AsEmitFrom, AsEmitKind, AstProcessor, EmitBody, EmitFrom, EmitKind, ToSql};
1+
use crate::query::querybuilder::syntax::emitter::{
2+
AsEmitBody, AsEmitFrom, AsEmitKind, AstProcessor, EmitBody, EmitFrom, EmitKind, ToSql,
3+
};
24
use crate::query::querybuilder::syntax::table_metadata::TableMetadata;
35
use crate::query::querybuilder::syntax::tokens::{SqlToken, ToSqlTokens};
46

@@ -26,15 +28,23 @@ impl Default for DeleteAst {
2628
}
2729

2830
impl DeleteAst {
29-
pub fn new() -> Self { Self{} }
31+
pub fn new() -> Self {
32+
Self {}
33+
}
3034
}
3135

3236
impl<'a> AsEmitKind<'a> for DeleteAst {
33-
fn as_emit_kind(&self) -> Option<&dyn EmitKind<'a>> { Some(self as &dyn EmitKind<'a>) }
37+
fn as_emit_kind(&self) -> Option<&dyn EmitKind<'a>> {
38+
Some(self as &dyn EmitKind<'a>)
39+
}
3440
}
3541
impl<'a> AsEmitFrom<'a> for DeleteAst {
36-
fn as_emit_from(&self) -> Option<&dyn EmitFrom<'a>> { Some(self as &dyn EmitFrom<'a>) }
42+
fn as_emit_from(&self) -> Option<&dyn EmitFrom<'a>> {
43+
Some(self as &dyn EmitFrom<'a>)
44+
}
3745
}
3846
impl<'a> AsEmitBody<'a> for DeleteAst {
39-
fn as_emit_body(&self) -> Option<&dyn EmitBody<'a>> { None }
40-
}
47+
fn as_emit_body(&self) -> Option<&dyn EmitBody<'a>> {
48+
None
49+
}
50+
}

canyon_core/src/query/querybuilder/syntax/ast/insert.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::borrow::Cow;
21
use crate::query::parameters::QueryParameter;
32
use crate::query::querybuilder::syntax::emitter::{EmitBody, EmitFrom, EmitKind};
43
use crate::query::querybuilder::syntax::table_metadata::TableMetadata;
5-
use crate::query::querybuilder::syntax::tokens::{SqlToken, Symbol, ToSqlTokens};
64
use crate::query::querybuilder::syntax::tokens::Symbol::{LParen, RParen};
5+
use crate::query::querybuilder::syntax::tokens::{SqlToken, Symbol, ToSqlTokens};
6+
use std::borrow::Cow;
77

88
pub struct InsertAst<'a> {
99
pub columns: Vec<&'a str>,
@@ -17,13 +17,16 @@ impl<'a> EmitKind<'a> for InsertAst<'a> {
1717
}
1818
impl<'a> EmitFrom<'a> for InsertAst<'a> {
1919
fn emit_from<'b>(&self, meta: &TableMetadata<'b>, out: &mut Vec<SqlToken<'b>>) {
20-
if !self.columns.is_empty() { // this can't be emitted here
20+
if !self.columns.is_empty() {
21+
// this can't be emitted here
2122
// TODO: can we create like a pre-validator trait a-la-emit-kind but for checking invariants?
2223
out.push(SqlToken::new_ident("INTO"));
2324
meta.to_tokens(out);
2425
out.push(SqlToken::Symbol(LParen));
2526
for (i, c) in self.columns.iter().enumerate() {
26-
if i > 0 { out.push(SqlToken::Symbol(Symbol::Comma)); }
27+
if i > 0 {
28+
out.push(SqlToken::Symbol(Symbol::Comma));
29+
}
2730
//out.push(SqlToken::new_ident(c));
2831
}
2932
out.push(SqlToken::Symbol(Symbol::RParen));
@@ -44,6 +47,9 @@ impl<'a> EmitBody<'a> for InsertAst<'a> {
4447

4548
impl<'a> InsertAst<'a> {
4649
pub fn new() -> Self {
47-
Self { columns: Vec::new(), values: Vec::new() }
50+
Self {
51+
columns: Vec::new(),
52+
values: Vec::new(),
53+
}
4854
}
49-
}
55+
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
pub(crate) mod select;
1+
pub(crate) mod delete;
22
pub(crate) mod insert;
3+
pub(crate) mod select;
34
pub(crate) mod update;
4-
pub(crate) mod delete;
55

66
use crate::query::querybuilder::syntax::clause::ConditionClause;
77
use crate::query::querybuilder::syntax::table_metadata::TableMetadata;
88

99
/// Base AST for common parts
10-
#[derive(Default)] pub struct BaseAst<'a> {
10+
#[derive(Default)]
11+
pub struct BaseAst<'a> {
1112
pub table: TableMetadata<'a>,
1213
pub conditions: Vec<ConditionClause<'a>>,
1314
}
@@ -16,7 +17,7 @@ impl<'a> BaseAst<'a> {
1617
pub fn new(table: impl Into<TableMetadata<'a>>) -> Self {
1718
Self {
1819
table: table.into(),
19-
conditions: Vec::new()
20+
conditions: Vec::new(),
2021
}
2122
}
2223
}

canyon_core/src/query/querybuilder/syntax/ast/select.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
use std::borrow::Cow;
21
use crate::query::querybuilder::syntax::column::ColumnRef;
3-
use crate::query::querybuilder::syntax::emitter::{AsEmitBody, AsEmitFrom, AsEmitKind, AstProcessor, EmitBody, EmitFrom, EmitKind, ToSql};
2+
use crate::query::querybuilder::syntax::emitter::{
3+
AsEmitBody, AsEmitFrom, AsEmitKind, AstProcessor, EmitBody, EmitFrom, EmitKind, ToSql,
4+
};
45
use crate::query::querybuilder::syntax::having::HavingClause;
56
use crate::query::querybuilder::syntax::join::JoinClause;
67
use crate::query::querybuilder::syntax::order::OrderByClause;
78
use crate::query::querybuilder::syntax::symbol::Symbol;
89
use crate::query::querybuilder::syntax::table_metadata::TableMetadata;
910
use crate::query::querybuilder::syntax::tokens::{SqlToken, ToSqlTokens};
11+
use std::borrow::Cow;
1012

1113
#[derive(Default)]
1214
pub struct SelectAst<'a> {
@@ -15,7 +17,7 @@ pub struct SelectAst<'a> {
1517
pub order_by: Option<OrderByClause<'a>>,
1618
pub having: Option<HavingClause<'a>>,
1719
pub group_by: Vec<ColumnRef<'a>>, // TODO: ColumnRef
18-
pub limit: Option<u64>, // TODO: strong typing
20+
pub limit: Option<u64>, // TODO: strong typing
1921
pub offset: Option<u64>,
2022
}
2123

@@ -44,7 +46,7 @@ impl<'a> EmitKind<'a> for SelectAst<'a> {
4446
}
4547

4648
impl<'a> EmitFrom<'a> for SelectAst<'a> {
47-
fn emit_from(&self, meta: &TableMetadata<'a>, out: &mut Vec<SqlToken<'a>>) {
49+
fn emit_from(&self, meta: &TableMetadata<'a>, out: &mut Vec<SqlToken<'a>>) {
4850
// columns
4951
if self.columns.is_empty() {
5052
out.push(SqlToken::Symbol(Symbol::Asterisk));
@@ -60,7 +62,6 @@ impl<'a> EmitFrom<'a> for SelectAst<'a> {
6062
// FROM
6163
out.push(SqlToken::new_keyword("FROM"));
6264
meta.to_tokens(out);
63-
6465
}
6566
}
6667
impl<'a> EmitBody<'a> for SelectAst<'a> {
@@ -76,16 +77,21 @@ impl<'a> EmitBody<'a> for SelectAst<'a> {
7677
}
7778
}
7879

79-
8080
// tell the system that SelectAst supports these phases:
8181
impl<'a> AsEmitKind<'a> for SelectAst<'a> {
82-
fn as_emit_kind(&self) -> Option<&dyn EmitKind<'a>> { Some(self as &dyn EmitKind<'a>) }
82+
fn as_emit_kind(&self) -> Option<&dyn EmitKind<'a>> {
83+
Some(self as &dyn EmitKind<'a>)
84+
}
8385
}
8486
impl<'a> AsEmitFrom<'a> for SelectAst<'a> {
85-
fn as_emit_from(&self) -> Option<&dyn EmitFrom<'a>> { Some(self as &dyn EmitFrom<'a>) }
87+
fn as_emit_from(&self) -> Option<&dyn EmitFrom<'a>> {
88+
Some(self as &dyn EmitFrom<'a>)
89+
}
8690
}
8791
impl<'a> AsEmitBody<'a> for SelectAst<'a> {
88-
fn as_emit_body(&self) -> Option<&dyn EmitBody<'a>> { Some(self as &dyn EmitBody<'a>) }
92+
fn as_emit_body(&self) -> Option<&dyn EmitBody<'a>> {
93+
Some(self as &dyn EmitBody<'a>)
94+
}
8995
}
9096
// impl<'a> AsEmitConditions<'a> for SelectAst<'a> {
9197
// fn as_emit_conditions(&self) -> Option<&dyn EmitConditions<'a>> { Some(self as &dyn EmitConditions<'a>) }

canyon_core/src/query/querybuilder/syntax/ast/update.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::query::querybuilder::syntax::column::ColumnRef;
2-
use crate::query::querybuilder::syntax::emitter::{AsEmitBody, AsEmitFrom, AsEmitKind, AstProcessor, EmitBody, EmitFrom, EmitKind, ToSql};
2+
use crate::query::querybuilder::syntax::emitter::{
3+
AsEmitBody, AsEmitFrom, AsEmitKind, AstProcessor, EmitBody, EmitFrom, EmitKind, ToSql,
4+
};
35
use crate::query::querybuilder::syntax::tokens::SqlToken;
46

57
pub struct UpdateAst<'a> {
@@ -36,16 +38,24 @@ impl<'a> Default for UpdateAst<'a> {
3638

3739
impl<'a> UpdateAst<'a> {
3840
pub fn new() -> Self {
39-
Self { columns: Vec::new() }
41+
Self {
42+
columns: Vec::new(),
43+
}
4044
}
4145
}
4246

4347
impl<'a> AsEmitKind<'a> for UpdateAst<'a> {
44-
fn as_emit_kind(&self) -> Option<&dyn EmitKind<'a>> { Some(self as &dyn EmitKind<'a>) }
48+
fn as_emit_kind(&self) -> Option<&dyn EmitKind<'a>> {
49+
Some(self as &dyn EmitKind<'a>)
50+
}
4551
}
4652
impl<'a> AsEmitFrom<'a> for UpdateAst<'a> {
47-
fn as_emit_from(&self) -> Option<&dyn EmitFrom<'a>> { None }
53+
fn as_emit_from(&self) -> Option<&dyn EmitFrom<'a>> {
54+
None
55+
}
4856
}
4957
impl<'a> AsEmitBody<'a> for UpdateAst<'a> {
50-
fn as_emit_body(&self) -> Option<&dyn EmitBody<'a>> { Some(self as &dyn EmitBody<'a>) }
51-
}
58+
fn as_emit_body(&self) -> Option<&dyn EmitBody<'a>> {
59+
Some(self as &dyn EmitBody<'a>)
60+
}
61+
}

canyon_core/src/query/querybuilder/syntax/clause.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::query::operators::Comp;
22
use crate::query::querybuilder::syntax::column::ColumnRef;
33

4-
#[derive(Clone)] pub struct ConditionClause<'a> {
4+
#[derive(Clone)]
5+
pub struct ConditionClause<'a> {
56
pub(crate) kind: ConditionClauseKind,
67
pub(crate) column_name: ColumnRef<'a>,
78
pub(crate) operator: Comp,
@@ -12,7 +13,7 @@ pub enum ConditionClauseKind {
1213
Where,
1314
And,
1415
Or,
15-
In
16+
In,
1617
}
1718

1819
impl AsRef<str> for ConditionClauseKind {

0 commit comments

Comments
 (0)