Skip to content

Commit d81c9e4

Browse files
committed
Cargo fmt
1 parent 11604da commit d81c9e4

6 files changed

Lines changed: 29 additions & 35 deletions

File tree

canyon_macros/src/canyon_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Provides helpers to build the `#[canyon_macros::canyon]` procedural like attribute macro
22
3-
use proc_macro2::TokenStream;
4-
use quote::quote;
53
use canyon_connection::CANYON_TOKIO_RUNTIME;
6-
use canyon_migrations::{CM_QUERIES_TO_EXECUTE, QUERIES_TO_EXECUTE};
74
use canyon_migrations::migrations::handler::Migrations;
5+
use canyon_migrations::{CM_QUERIES_TO_EXECUTE, QUERIES_TO_EXECUTE};
6+
use proc_macro2::TokenStream;
7+
use quote::quote;
88

99
#[cfg(feature = "migrations")]
1010
pub fn main_with_queries() -> TokenStream {

canyon_macros/src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
extern crate proc_macro;
22

3-
mod utils;
4-
mod query_operations;
53
mod canyon_entity_macro;
6-
#[cfg(feature = "migrations")] mod canyon_macro;
4+
#[cfg(feature = "migrations")]
5+
mod canyon_macro;
6+
mod query_operations;
7+
mod utils;
78

89
use canyon_entity_macro::parse_canyon_entity_proc_macro_attr;
910
use proc_macro::TokenStream as CompilerTokenStream;
1011
use proc_macro2::{Ident, TokenStream};
1112
use quote::{quote, ToTokens};
1213
use syn::{DeriveInput, Fields, Type, Visibility};
1314

14-
#[cfg(feature = "migrations")] use canyon_macro::main_with_queries;
15+
#[cfg(feature = "migrations")]
16+
use canyon_macro::main_with_queries;
1517

1618
use query_operations::{
1719
delete::{generate_delete_query_tokens, generate_delete_tokens},
@@ -26,15 +28,14 @@ use query_operations::{
2628
use utils::{function_parser::FunctionParser, helpers, macro_tokens::MacroTokens};
2729

2830
use canyon_entities::{
29-
CANYON_REGISTER_ENTITIES,
3031
entity::CanyonEntity,
3132
manager_builder::{
3233
generate_enum_with_fields, generate_enum_with_fields_values, generate_user_struct,
3334
},
34-
register_types::{CanyonRegisterEntity, CanyonRegisterEntityField}
35+
register_types::{CanyonRegisterEntity, CanyonRegisterEntityField},
36+
CANYON_REGISTER_ENTITIES,
3537
};
3638

37-
3839
/// Macro for handling the entry point to the program.
3940
///
4041
/// Avoids the user to write the tokio proc_attribute and
@@ -57,7 +58,8 @@ pub fn main(_meta: CompilerTokenStream, input: CompilerTokenStream) -> CompilerT
5758

5859
#[allow(unused_mut, unused_assignments)]
5960
let mut migrations_tokens = quote! {};
60-
#[cfg(feature = "migrations")] {
61+
#[cfg(feature = "migrations")]
62+
{
6163
migrations_tokens = main_with_queries();
6264
}
6365

canyon_migrations/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mod constants;
2020
use canyon_connection::lazy_static::lazy_static;
2121
use std::{collections::HashMap, sync::Mutex};
2222

23-
2423
lazy_static! {
2524
pub static ref QUERIES_TO_EXECUTE: Mutex<HashMap<String, Vec<String>>> =
2625
Mutex::new(HashMap::new());

canyon_migrations/src/migrations/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use canyon_connection::{datasources::Migrations as MigrationsStatus, DATASOURCES};
22
use canyon_crud::rows::CanyonRows;
3-
use partialdebug::placeholder::PartialDebug;
43
use canyon_entities::CANYON_REGISTER_ENTITIES;
4+
use partialdebug::placeholder::PartialDebug;
55

66
use crate::{
77
canyon_crud::{
@@ -14,7 +14,7 @@ use crate::{
1414
information_schema::{ColumnMetadata, ColumnMetadataTypeValue, TableMetadata},
1515
memory::CanyonMemory,
1616
processor::MigrationsProcessor,
17-
}
17+
},
1818
};
1919

2020
#[derive(PartialDebug)]

canyon_migrations/src/migrations/processor.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ use crate::save_migrations_query_to_execute;
1313

1414
use super::information_schema::{ColumnMetadata, TableMetadata};
1515
use super::memory::CanyonMemory;
16+
#[cfg(feature = "postgres")]
17+
use crate::migrations::transforms::{to_postgres_alter_syntax, to_postgres_syntax};
18+
#[cfg(feature = "mssql")]
19+
use crate::migrations::transforms::{to_sqlserver_alter_syntax, to_sqlserver_syntax};
1620
use canyon_entities::register_types::{CanyonRegisterEntity, CanyonRegisterEntityField};
17-
#[cfg(feature = "postgres")] use crate::migrations::transforms::{to_postgres_alter_syntax, to_postgres_syntax};
18-
#[cfg(feature = "mssql")] use crate::migrations::transforms::{to_sqlserver_alter_syntax, to_sqlserver_syntax};
1921

2022
/// Responsible of generating the queries to sync the database status with the
2123
/// Rust source code managed by Canyon, for successfully make the migrations
@@ -663,19 +665,15 @@ impl MigrationsHelper {
663665
#[cfg(feature = "postgres")]
664666
{
665667
if db_type == DatabaseType::PostgreSql {
666-
return
667-
to_postgres_alter_syntax(canyon_register_entity_field)
668-
.to_lowercase()
668+
return to_postgres_alter_syntax(canyon_register_entity_field).to_lowercase()
669669
== current_column_metadata.datatype;
670670
}
671671
}
672672
#[cfg(feature = "mssql")]
673673
{
674674
if db_type == DatabaseType::SqlServer {
675675
// TODO Search a better way to get the datatype without useless info (like "VARCHAR(MAX)")
676-
return
677-
to_sqlserver_alter_syntax(canyon_register_entity_field)
678-
.to_lowercase()
676+
return to_sqlserver_alter_syntax(canyon_register_entity_field).to_lowercase()
679677
== current_column_metadata.datatype;
680678
}
681679
}

canyon_migrations/src/migrations/transforms.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#[cfg(feature = "postgres")] use crate::constants::postgresql_type;
2-
#[cfg(feature = "mssql")] use crate::constants::sqlserver_type;
1+
#[cfg(feature = "postgres")]
2+
use crate::constants::postgresql_type;
3+
#[cfg(feature = "mssql")]
4+
use crate::constants::sqlserver_type;
35
use crate::constants::{regex_patterns, rust_type};
46

5-
67
use canyon_entities::register_types::CanyonRegisterEntityField;
78
use regex::Regex;
89

@@ -59,9 +60,7 @@ pub fn to_sqlserver_syntax(field: &CanyonRegisterEntityField) -> String {
5960
let rust_type_clean = field.field_type.replace(' ', "");
6061

6162
match rust_type_clean.as_str() {
62-
rust_type::I8 | rust_type::U8 => {
63-
String::from(&format!("{} NOT NULL", sqlserver_type::INT))
64-
}
63+
rust_type::I8 | rust_type::U8 => String::from(&format!("{} NOT NULL", sqlserver_type::INT)),
6564
rust_type::OPT_I8 | rust_type::OPT_U8 => String::from(sqlserver_type::INT),
6665

6766
rust_type::I16 | rust_type::U16 => {
@@ -131,12 +130,8 @@ pub fn to_postgres_alter_syntax(field: &CanyonRegisterEntityField) -> String {
131130
}
132131
rust_type::STRING | rust_type::OPT_STRING => String::from(postgresql_type::TEXT),
133132
rust_type::BOOL | rust_type::OPT_BOOL => String::from(postgresql_type::BOOLEAN),
134-
rust_type::NAIVE_DATE | rust_type::OPT_NAIVE_DATE => {
135-
String::from(postgresql_type::DATE)
136-
}
137-
rust_type::NAIVE_TIME | rust_type::OPT_NAIVE_TIME => {
138-
String::from(postgresql_type::TIME)
139-
}
133+
rust_type::NAIVE_DATE | rust_type::OPT_NAIVE_DATE => String::from(postgresql_type::DATE),
134+
rust_type::NAIVE_TIME | rust_type::OPT_NAIVE_TIME => String::from(postgresql_type::TIME),
140135
rust_type::NAIVE_DATE_TIME | rust_type::OPT_NAIVE_DATE_TIME => {
141136
String::from(postgresql_type::DATETIME)
142137
}
@@ -181,4 +176,4 @@ pub fn to_sqlserver_alter_syntax(field: &CanyonRegisterEntityField) -> String {
181176
}
182177
&_ => todo!("Not supported datatype for this migrations version"),
183178
}
184-
}
179+
}

0 commit comments

Comments
 (0)