From 4649554171a5cd66dd0b81093fa9dca8a73647b4 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Mon, 12 Feb 2024 16:15:59 +0100 Subject: [PATCH 1/2] fix(code): add "allow(unused") for diesel import this is a quick fix, and the import should be removed in the future altogether re #94 --- src/code.rs | 2 +- test/advanced_queries/models/todos/generated.rs | 1 + test/autogenerated_all/models/todos/generated.rs | 1 + test/autogenerated_attributes/models/todos/generated.rs | 1 + test/autogenerated_primary_keys/models/todos/generated.rs | 1 + test/cleanup_generated_content/models/todos/generated.rs | 1 + test/create_update_bytes_cow/models/todos/generated.rs | 1 + test/create_update_bytes_slice/models/todos/generated.rs | 1 + test/create_update_str_cow/models/todos/generated.rs | 1 + test/create_update_str_str/models/todos/generated.rs | 1 + .../data/models/table_a/generated.rs | 1 + .../data/models/table_b/generated.rs | 1 + test/custom_model_path/models/table_a/generated.rs | 1 + test/custom_model_path/models/table_b/generated.rs | 1 + test/manual_primary_keys/models/todos/generated.rs | 1 + test/multiple_primary_keys/models/users/generated.rs | 1 + test/no_default_features/models/todos/generated.rs | 1 + test/once_common_structs/models/table1/generated.rs | 1 + test/once_common_structs/models/table2/generated.rs | 1 + .../models/table1/generated.rs | 1 + .../models/table2/generated.rs | 1 + .../models/table1.rs | 1 + .../models/table2.rs | 1 + test/once_connection_type/models/table1/generated.rs | 1 + test/once_connection_type/models/table2/generated.rs | 1 + test/postgres_array_column/models/user/generated.rs | 1 + test/readonly/models/normal/generated.rs | 1 + test/readonly/models/prefix_table/generated.rs | 1 + test/readonly/models/prefix_table_suffix/generated.rs | 1 + test/readonly/models/table_suffix/generated.rs | 1 + test/simple_table_async/models/todos/generated.rs | 1 + test/simple_table_custom_schema_path/models/todos/generated.rs | 1 + test/simple_table_mysql/models/todos/generated.rs | 1 + test/simple_table_no_crud/models/todos/generated.rs | 1 + test/simple_table_no_serde/models/todos/generated.rs | 1 + test/simple_table_pg/models/todos/generated.rs | 1 + test/simple_table_sqlite/models/todos/generated.rs | 1 + test/single_model_file/models/table1.rs | 1 + test/single_model_file/models/table2.rs | 1 + test/use_statements/models/fang_tasks/generated.rs | 1 + 40 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/code.rs b/src/code.rs index 115b04cc..7124232e 100644 --- a/src/code.rs +++ b/src/code.rs @@ -729,7 +729,7 @@ fn build_imports(table: &ParsedTableMacro, config: &GenerationConfig) -> String // Note: i guess this could also just be a string that is appended to, or a vec of "Cow", but i personally think this is the most use-able // because you dont have to think of any context style (like forgetting to put "\n" before / after something) let mut imports_vec = Vec::with_capacity(10); - imports_vec.push("use crate::diesel::*;".into()); + imports_vec.push("#[allow(unused)]\nuse crate::diesel::*;".into()); let table_options = config.table(&table.name.to_string()); imports_vec.extend(table.foreign_keys.iter().map(|fk| { diff --git a/test/advanced_queries/models/todos/generated.rs b/test/advanced_queries/models/todos/generated.rs index cd2c9c80..74b436bc 100644 --- a/test/advanced_queries/models/todos/generated.rs +++ b/test/advanced_queries/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/autogenerated_all/models/todos/generated.rs b/test/autogenerated_all/models/todos/generated.rs index 96a9e952..f2739530 100644 --- a/test/autogenerated_all/models/todos/generated.rs +++ b/test/autogenerated_all/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/autogenerated_attributes/models/todos/generated.rs b/test/autogenerated_attributes/models/todos/generated.rs index dbe37fe9..b30d19ad 100644 --- a/test/autogenerated_attributes/models/todos/generated.rs +++ b/test/autogenerated_attributes/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/autogenerated_primary_keys/models/todos/generated.rs b/test/autogenerated_primary_keys/models/todos/generated.rs index 4b9c2dd7..6e41bd91 100644 --- a/test/autogenerated_primary_keys/models/todos/generated.rs +++ b/test/autogenerated_primary_keys/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/cleanup_generated_content/models/todos/generated.rs b/test/cleanup_generated_content/models/todos/generated.rs index 9ebf1942..3fab8013 100644 --- a/test/cleanup_generated_content/models/todos/generated.rs +++ b/test/cleanup_generated_content/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/create_update_bytes_cow/models/todos/generated.rs b/test/create_update_bytes_cow/models/todos/generated.rs index 8661721d..7ed4d487 100644 --- a/test/create_update_bytes_cow/models/todos/generated.rs +++ b/test/create_update_bytes_cow/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/create_update_bytes_slice/models/todos/generated.rs b/test/create_update_bytes_slice/models/todos/generated.rs index e4e2d3c8..258d90e9 100644 --- a/test/create_update_bytes_slice/models/todos/generated.rs +++ b/test/create_update_bytes_slice/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/create_update_str_cow/models/todos/generated.rs b/test/create_update_str_cow/models/todos/generated.rs index dd61ada7..94674ecd 100644 --- a/test/create_update_str_cow/models/todos/generated.rs +++ b/test/create_update_str_cow/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/create_update_str_str/models/todos/generated.rs b/test/create_update_str_str/models/todos/generated.rs index 886bdf58..2a752d0a 100644 --- a/test/create_update_str_str/models/todos/generated.rs +++ b/test/create_update_str_str/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/custom_model_and_schema_path/data/models/table_a/generated.rs b/test/custom_model_and_schema_path/data/models/table_a/generated.rs index 812a89f6..51550bb0 100644 --- a/test/custom_model_and_schema_path/data/models/table_a/generated.rs +++ b/test/custom_model_and_schema_path/data/models/table_a/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::data::schema::*; diff --git a/test/custom_model_and_schema_path/data/models/table_b/generated.rs b/test/custom_model_and_schema_path/data/models/table_b/generated.rs index cdcf4ad3..62dc43d3 100644 --- a/test/custom_model_and_schema_path/data/models/table_b/generated.rs +++ b/test/custom_model_and_schema_path/data/models/table_b/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::data::models::table_a::TableA; use crate::data::schema::*; diff --git a/test/custom_model_path/models/table_a/generated.rs b/test/custom_model_path/models/table_a/generated.rs index 65d43a3a..ec14d67a 100644 --- a/test/custom_model_path/models/table_a/generated.rs +++ b/test/custom_model_path/models/table_a/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/custom_model_path/models/table_b/generated.rs b/test/custom_model_path/models/table_b/generated.rs index d9ab2308..2e3d0ad0 100644 --- a/test/custom_model_path/models/table_b/generated.rs +++ b/test/custom_model_path/models/table_b/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::data::models::table_a::TableA; use crate::schema::*; diff --git a/test/manual_primary_keys/models/todos/generated.rs b/test/manual_primary_keys/models/todos/generated.rs index 5b8b4c13..e95a7237 100644 --- a/test/manual_primary_keys/models/todos/generated.rs +++ b/test/manual_primary_keys/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/multiple_primary_keys/models/users/generated.rs b/test/multiple_primary_keys/models/users/generated.rs index 9df11315..c89ea257 100644 --- a/test/multiple_primary_keys/models/users/generated.rs +++ b/test/multiple_primary_keys/models/users/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/no_default_features/models/todos/generated.rs b/test/no_default_features/models/todos/generated.rs index b184146f..464c9253 100644 --- a/test/no_default_features/models/todos/generated.rs +++ b/test/no_default_features/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/once_common_structs/models/table1/generated.rs b/test/once_common_structs/models/table1/generated.rs index e2fef4b1..afda5bc2 100644 --- a/test/once_common_structs/models/table1/generated.rs +++ b/test/once_common_structs/models/table1/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; use crate::models::common::*; diff --git a/test/once_common_structs/models/table2/generated.rs b/test/once_common_structs/models/table2/generated.rs index 4a9b4403..28acc135 100644 --- a/test/once_common_structs/models/table2/generated.rs +++ b/test/once_common_structs/models/table2/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; use crate::models::common::*; diff --git a/test/once_common_structs_once_connection_type/models/table1/generated.rs b/test/once_common_structs_once_connection_type/models/table1/generated.rs index 7d940d4c..82f08d9f 100644 --- a/test/once_common_structs_once_connection_type/models/table1/generated.rs +++ b/test/once_common_structs_once_connection_type/models/table1/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; use crate::models::common::*; diff --git a/test/once_common_structs_once_connection_type/models/table2/generated.rs b/test/once_common_structs_once_connection_type/models/table2/generated.rs index ce4aef40..1d3cdcde 100644 --- a/test/once_common_structs_once_connection_type/models/table2/generated.rs +++ b/test/once_common_structs_once_connection_type/models/table2/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; use crate::models::common::*; diff --git a/test/once_common_structs_once_connection_type_single_file/models/table1.rs b/test/once_common_structs_once_connection_type_single_file/models/table1.rs index 7d940d4c..82f08d9f 100644 --- a/test/once_common_structs_once_connection_type_single_file/models/table1.rs +++ b/test/once_common_structs_once_connection_type_single_file/models/table1.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; use crate::models::common::*; diff --git a/test/once_common_structs_once_connection_type_single_file/models/table2.rs b/test/once_common_structs_once_connection_type_single_file/models/table2.rs index ce4aef40..1d3cdcde 100644 --- a/test/once_common_structs_once_connection_type_single_file/models/table2.rs +++ b/test/once_common_structs_once_connection_type_single_file/models/table2.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; use crate::models::common::*; diff --git a/test/once_connection_type/models/table1/generated.rs b/test/once_connection_type/models/table1/generated.rs index 03911360..082ce697 100644 --- a/test/once_connection_type/models/table1/generated.rs +++ b/test/once_connection_type/models/table1/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; use crate::models::common::*; diff --git a/test/once_connection_type/models/table2/generated.rs b/test/once_connection_type/models/table2/generated.rs index 27cbd524..51c88e3a 100644 --- a/test/once_connection_type/models/table2/generated.rs +++ b/test/once_connection_type/models/table2/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; use crate::models::common::*; diff --git a/test/postgres_array_column/models/user/generated.rs b/test/postgres_array_column/models/user/generated.rs index 01c8c6a7..6f621421 100644 --- a/test/postgres_array_column/models/user/generated.rs +++ b/test/postgres_array_column/models/user/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/readonly/models/normal/generated.rs b/test/readonly/models/normal/generated.rs index 83f216a6..00e173fe 100644 --- a/test/readonly/models/normal/generated.rs +++ b/test/readonly/models/normal/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/readonly/models/prefix_table/generated.rs b/test/readonly/models/prefix_table/generated.rs index 31d53a51..1351168d 100644 --- a/test/readonly/models/prefix_table/generated.rs +++ b/test/readonly/models/prefix_table/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/readonly/models/prefix_table_suffix/generated.rs b/test/readonly/models/prefix_table_suffix/generated.rs index 04ecc241..3c3190c0 100644 --- a/test/readonly/models/prefix_table_suffix/generated.rs +++ b/test/readonly/models/prefix_table_suffix/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/readonly/models/table_suffix/generated.rs b/test/readonly/models/table_suffix/generated.rs index e986e111..cf2a6ec8 100644 --- a/test/readonly/models/table_suffix/generated.rs +++ b/test/readonly/models/table_suffix/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/simple_table_async/models/todos/generated.rs b/test/simple_table_async/models/todos/generated.rs index 8f049b19..2583e238 100644 --- a/test/simple_table_async/models/todos/generated.rs +++ b/test/simple_table_async/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use diesel_async::RunQueryDsl; use crate::schema::*; diff --git a/test/simple_table_custom_schema_path/models/todos/generated.rs b/test/simple_table_custom_schema_path/models/todos/generated.rs index 443a08b3..b54bf349 100644 --- a/test/simple_table_custom_schema_path/models/todos/generated.rs +++ b/test/simple_table_custom_schema_path/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::data::schema::*; diff --git a/test/simple_table_mysql/models/todos/generated.rs b/test/simple_table_mysql/models/todos/generated.rs index 5a8672b7..c1192352 100644 --- a/test/simple_table_mysql/models/todos/generated.rs +++ b/test/simple_table_mysql/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/simple_table_no_crud/models/todos/generated.rs b/test/simple_table_no_crud/models/todos/generated.rs index 074c34e7..24d04296 100644 --- a/test/simple_table_no_crud/models/todos/generated.rs +++ b/test/simple_table_no_crud/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/simple_table_no_serde/models/todos/generated.rs b/test/simple_table_no_serde/models/todos/generated.rs index 8171bd47..08e61bff 100644 --- a/test/simple_table_no_serde/models/todos/generated.rs +++ b/test/simple_table_no_serde/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/simple_table_pg/models/todos/generated.rs b/test/simple_table_pg/models/todos/generated.rs index 2e777ec2..727efc5c 100644 --- a/test/simple_table_pg/models/todos/generated.rs +++ b/test/simple_table_pg/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/simple_table_sqlite/models/todos/generated.rs b/test/simple_table_sqlite/models/todos/generated.rs index 7d596a5f..eccd751b 100644 --- a/test/simple_table_sqlite/models/todos/generated.rs +++ b/test/simple_table_sqlite/models/todos/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/single_model_file/models/table1.rs b/test/single_model_file/models/table1.rs index 5689ac58..3a9e1835 100644 --- a/test/single_model_file/models/table1.rs +++ b/test/single_model_file/models/table1.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/single_model_file/models/table2.rs b/test/single_model_file/models/table2.rs index 1f89881b..6fad4f9e 100644 --- a/test/single_model_file/models/table2.rs +++ b/test/single_model_file/models/table2.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; diff --git a/test/use_statements/models/fang_tasks/generated.rs b/test/use_statements/models/fang_tasks/generated.rs index f4592420..987c12b7 100644 --- a/test/use_statements/models/fang_tasks/generated.rs +++ b/test/use_statements/models/fang_tasks/generated.rs @@ -1,5 +1,6 @@ /* @generated and managed by dsync */ +#[allow(unused)] use crate::diesel::*; use crate::schema::*; From fe96128df68232636f0704330a8b62d461da8106 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Mon, 12 Feb 2024 16:18:45 +0100 Subject: [PATCH 2/2] fix(code): remove unused import in "paginate" function --- src/code.rs | 2 -- test/advanced_queries/models/todos/generated.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/code.rs b/src/code.rs index 7124232e..7a263e78 100644 --- a/src/code.rs +++ b/src/code.rs @@ -537,8 +537,6 @@ fn build_table_fns( buffer.push_str(&format!(r##" /// Paginates through the table where page is a 0-based index (i.e. page 0 is the first page) pub{async_keyword} fn paginate(db: &mut ConnectionType, page: i64, page_size: i64, filter: {struct_name}Filter) -> diesel::QueryResult> {{ - use {schema_path}{table_name}::dsl::*; - let page = page.max(0); let page_size = page_size.max(1); let total_items = Self::filter(filter.clone()).count().get_result(db){await_keyword}?; diff --git a/test/advanced_queries/models/todos/generated.rs b/test/advanced_queries/models/todos/generated.rs index 74b436bc..86b4202d 100644 --- a/test/advanced_queries/models/todos/generated.rs +++ b/test/advanced_queries/models/todos/generated.rs @@ -96,8 +96,6 @@ impl Todos { /// Paginates through the table where page is a 0-based index (i.e. page 0 is the first page) pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64, filter: TodosFilter) -> diesel::QueryResult> { - use crate::schema::todos::dsl::*; - let page = page.max(0); let page_size = page_size.max(1); let total_items = Self::filter(filter.clone()).count().get_result(db)?;