Skip to content

Commit

Permalink
refactor(code): have less new-lines in impl block section
Browse files Browse the repository at this point in the history
this may be opinionated
  • Loading branch information
hasezoey committed Oct 30, 2023
1 parent 77ce422 commit 4a64dfe
Show file tree
Hide file tree
Showing 28 changed files with 3 additions and 69 deletions.
12 changes: 3 additions & 9 deletions src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,10 @@ fn build_table_fns(

if !config.once_common_structs {
buffer.push_str(&generate_common_structs(&table_options));
buffer.push('\n');
}

buffer.push_str(&format!(
r##"
impl {struct_name} {{
"##
));
buffer.push_str(&format!("impl {struct_name} {{"));

if !is_readonly {
if create_struct.has_fields() {
Expand Down Expand Up @@ -512,10 +509,7 @@ impl {struct_name} {{
));
}

buffer.push_str(
r##"
}"##,
);
buffer.push('}');

buffer
}
Expand Down
2 changes: 0 additions & 2 deletions test/autogenerated_all/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub struct PaginationResult<T> {
}

impl Todos {

pub fn create(db: &mut ConnectionType) -> QueryResult<Self> {
use crate::schema::todos::dsl::*;

Expand Down Expand Up @@ -74,5 +73,4 @@ impl Todos {

diesel::delete(todos.filter(id.eq(param_id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/autogenerated_attributes/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pub struct PaginationResult<T> {
}

impl Todos {

pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
use crate::schema::todos::dsl::*;

Expand Down Expand Up @@ -80,5 +79,4 @@ impl Todos {

diesel::delete(todos.filter(id.eq(param_id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/autogenerated_primary_keys/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pub struct PaginationResult<T> {
}

impl Todos {

pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
use crate::schema::todos::dsl::*;

Expand Down Expand Up @@ -80,5 +79,4 @@ impl Todos {

diesel::delete(todos.filter(id.eq(param_id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/cleanup_generated_content/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub struct PaginationResult<T> {
}

impl Todos {

pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
use crate::schema::todos::dsl::*;

Expand Down Expand Up @@ -88,5 +87,4 @@ impl Todos {

diesel::delete(todos.filter(id.eq(param_id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/create_update_str_cow/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub struct PaginationResult<T> {
}

impl Todos {

pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
use crate::schema::todos::dsl::*;

Expand Down Expand Up @@ -87,5 +86,4 @@ impl Todos {

diesel::delete(todos.filter(text.eq(param_text))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/create_update_str_str/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub struct PaginationResult<T> {
}

impl Todos {

pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
use crate::schema::todos::dsl::*;

Expand Down Expand Up @@ -87,5 +86,4 @@ impl Todos {

diesel::delete(todos.filter(text.eq(param_text))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/custom_model_and_schema_path/models/tableA/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub struct PaginationResult<T> {
}

impl TableA {

pub fn create(db: &mut ConnectionType, item: &CreateTableA) -> QueryResult<Self> {
use crate::data::schema::tableA::dsl::*;

Expand Down Expand Up @@ -67,5 +66,4 @@ impl TableA {

diesel::delete(tableA.filter(_id.eq(param__id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/custom_model_and_schema_path/models/tableB/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub struct PaginationResult<T> {
}

impl TableB {

pub fn create(db: &mut ConnectionType, item: &CreateTableB) -> QueryResult<Self> {
use crate::data::schema::tableB::dsl::*;

Expand Down Expand Up @@ -82,5 +81,4 @@ impl TableB {

diesel::delete(tableB.filter(_id.eq(param__id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/custom_model_path/models/tableA/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub struct PaginationResult<T> {
}

impl TableA {

pub fn create(db: &mut ConnectionType, item: &CreateTableA) -> QueryResult<Self> {
use crate::schema::tableA::dsl::*;

Expand Down Expand Up @@ -67,5 +66,4 @@ impl TableA {

diesel::delete(tableA.filter(_id.eq(param__id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/custom_model_path/models/tableB/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub struct PaginationResult<T> {
}

impl TableB {

pub fn create(db: &mut ConnectionType, item: &CreateTableB) -> QueryResult<Self> {
use crate::schema::tableB::dsl::*;

Expand Down Expand Up @@ -82,5 +81,4 @@ impl TableB {

diesel::delete(tableB.filter(_id.eq(param__id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/manual_primary_keys/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub struct PaginationResult<T> {
}

impl Todos {

pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
use crate::schema::todos::dsl::*;

Expand Down Expand Up @@ -67,5 +66,4 @@ impl Todos {

diesel::delete(todos.filter(id.eq(param_id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/multiple_primary_keys/models/users/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub struct PaginationResult<T> {
}

impl Users {

pub fn create(db: &mut ConnectionType, item: &CreateUsers) -> QueryResult<Self> {
use crate::schema::users::dsl::*;

Expand Down Expand Up @@ -83,5 +82,4 @@ impl Users {

diesel::delete(users.filter(name.eq(param_name)).filter(address.eq(param_address))).execute(db)
}

}
3 changes: 0 additions & 3 deletions test/once_common_structs/models/table1/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ pub struct Table1 {
pub id: i32,
}


impl Table1 {

pub fn create(db: &mut ConnectionType) -> QueryResult<Self> {
use crate::schema::table1::dsl::*;

Expand Down Expand Up @@ -52,5 +50,4 @@ impl Table1 {

diesel::delete(table1.filter(id.eq(param_id))).execute(db)
}

}
3 changes: 0 additions & 3 deletions test/once_common_structs/models/table2/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ pub struct Table2 {
pub id: i32,
}


impl Table2 {

pub fn create(db: &mut ConnectionType) -> QueryResult<Self> {
use crate::schema::table2::dsl::*;

Expand Down Expand Up @@ -52,5 +50,4 @@ impl Table2 {

diesel::delete(table2.filter(id.eq(param_id))).execute(db)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ pub struct Table1 {
pub id: i32,
}


impl Table1 {

pub fn create(db: &mut ConnectionType) -> QueryResult<Self> {
use crate::schema::table1::dsl::*;

Expand Down Expand Up @@ -50,5 +48,4 @@ impl Table1 {

diesel::delete(table1.filter(id.eq(param_id))).execute(db)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ pub struct Table2 {
pub id: i32,
}


impl Table2 {

pub fn create(db: &mut ConnectionType) -> QueryResult<Self> {
use crate::schema::table2::dsl::*;

Expand Down Expand Up @@ -50,5 +48,4 @@ impl Table2 {

diesel::delete(table2.filter(id.eq(param_id))).execute(db)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ pub struct Table1 {
pub id: i32,
}


impl Table1 {

pub fn create(db: &mut ConnectionType) -> QueryResult<Self> {
use crate::schema::table1::dsl::*;

Expand Down Expand Up @@ -50,5 +48,4 @@ impl Table1 {

diesel::delete(table1.filter(id.eq(param_id))).execute(db)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ pub struct Table2 {
pub id: i32,
}


impl Table2 {

pub fn create(db: &mut ConnectionType) -> QueryResult<Self> {
use crate::schema::table2::dsl::*;

Expand Down Expand Up @@ -50,5 +48,4 @@ impl Table2 {

diesel::delete(table2.filter(id.eq(param_id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/once_connection_type/models/table1/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub struct PaginationResult<T> {
}

impl Table1 {

pub fn create(db: &mut ConnectionType) -> QueryResult<Self> {
use crate::schema::table1::dsl::*;

Expand Down Expand Up @@ -60,5 +59,4 @@ impl Table1 {

diesel::delete(table1.filter(id.eq(param_id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/once_connection_type/models/table2/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub struct PaginationResult<T> {
}

impl Table2 {

pub fn create(db: &mut ConnectionType) -> QueryResult<Self> {
use crate::schema::table2::dsl::*;

Expand Down Expand Up @@ -60,5 +59,4 @@ impl Table2 {

diesel::delete(table2.filter(id.eq(param_id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/simple_table/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ pub struct PaginationResult<T> {
}

impl Todos {

pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
use crate::schema::todos::dsl::*;

Expand Down Expand Up @@ -96,5 +95,4 @@ impl Todos {

diesel::delete(todos.filter(id.eq(param_id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/simple_table_async/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub struct PaginationResult<T> {
}

impl Todos {

pub async fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
use crate::schema::todos::dsl::*;

Expand Down Expand Up @@ -91,5 +90,4 @@ impl Todos {

diesel::delete(todos.filter(id.eq(param_id))).execute(db).await
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub struct PaginationResult<T> {
}

impl Todos {

pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
use crate::data::schema::todos::dsl::*;

Expand Down Expand Up @@ -90,5 +89,4 @@ impl Todos {

diesel::delete(todos.filter(id.eq(param_id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/simple_table_no_serde/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub struct PaginationResult<T> {
}

impl Todos {

pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
use crate::schema::todos::dsl::*;

Expand Down Expand Up @@ -89,5 +88,4 @@ impl Todos {

diesel::delete(todos.filter(id.eq(param_id))).execute(db)
}

}
2 changes: 0 additions & 2 deletions test/single_model_file/models/table1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub struct PaginationResult<T> {
}

impl Table1 {

pub fn create(db: &mut ConnectionType) -> QueryResult<Self> {
use crate::schema::table1::dsl::*;

Expand Down Expand Up @@ -61,5 +60,4 @@ impl Table1 {

diesel::delete(table1.filter(id.eq(param_id))).execute(db)
}

}
Loading

0 comments on commit 4a64dfe

Please sign in to comment.