Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick-fix unused import warnings of generated code #134

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PaginationResult<Self>> {{
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}?;
Expand Down Expand Up @@ -729,7 +727,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| {
Expand Down
3 changes: 1 addition & 2 deletions test/advanced_queries/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down Expand Up @@ -95,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<PaginationResult<Self>> {
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)?;
Expand Down
1 change: 1 addition & 0 deletions test/autogenerated_all/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/autogenerated_attributes/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/autogenerated_primary_keys/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/cleanup_generated_content/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/create_update_bytes_cow/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/create_update_bytes_slice/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/create_update_str_cow/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/create_update_str_str/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::data::schema::*;

Expand Down
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
1 change: 1 addition & 0 deletions test/custom_model_path/models/table_a/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/custom_model_path/models/table_b/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::data::models::table_a::TableA;
use crate::schema::*;
Expand Down
1 change: 1 addition & 0 deletions test/manual_primary_keys/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/multiple_primary_keys/models/users/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/no_default_features/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/once_common_structs/models/table1/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;
use crate::models::common::*;
Expand Down
1 change: 1 addition & 0 deletions test/once_common_structs/models/table2/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;
use crate::models::common::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;
use crate::models::common::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;
use crate::models::common::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;
use crate::models::common::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;
use crate::models::common::*;
Expand Down
1 change: 1 addition & 0 deletions test/once_connection_type/models/table1/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;
use crate::models::common::*;
Expand Down
1 change: 1 addition & 0 deletions test/once_connection_type/models/table2/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;
use crate::models::common::*;
Expand Down
1 change: 1 addition & 0 deletions test/postgres_array_column/models/user/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/readonly/models/normal/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/readonly/models/prefix_table/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/readonly/models/prefix_table_suffix/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/readonly/models/table_suffix/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/simple_table_async/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use diesel_async::RunQueryDsl;
use crate::schema::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::data::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/simple_table_mysql/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/simple_table_no_crud/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/simple_table_no_serde/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/simple_table_pg/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/simple_table_sqlite/models/todos/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/single_model_file/models/table1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/single_model_file/models/table2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
1 change: 1 addition & 0 deletions test/use_statements/models/fang_tasks/generated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @generated and managed by dsync */

#[allow(unused)]
use crate::diesel::*;
use crate::schema::*;

Expand Down
Loading