Skip to content

Commit

Permalink
fix(code): remove extra new-line between struct and paginationresult
Browse files Browse the repository at this point in the history
also add a new-line inbetween the file-signature and code in "common.rs" to be consistent with other files
  • Loading branch information
hasezoey committed Oct 30, 2023
1 parent 4a64dfe commit 2633bb8
Show file tree
Hide file tree
Showing 28 changed files with 13 additions and 49 deletions.
6 changes: 3 additions & 3 deletions src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,15 @@ fn build_table_fns(
pub fn generate_common_structs(table_options: &TableOptions<'_>) -> String {
#[cfg(feature = "tsync")]
let tsync = match table_options.get_tsync() {
true => "#[tsync::tsync]",
true => "#[tsync::tsync]\n",
false => "",
};
#[cfg(not(feature = "tsync"))]
let tsync = "";

formatdoc!(
r##"{tsync}
#[derive({debug_derive}, {serde_derive})]
r##"
{tsync}#[derive({debug_derive}, {serde_derive})]
pub struct PaginationResult<T> {{
pub items: Vec<T>,
pub total_items: i64,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub fn generate_files(
let mut common_file = MarkedFile::new(output_models_dir.join("common.rs"))?;
common_file.ensure_file_signature()?;
common_file.change_file_contents({
let mut tmp = String::from(FILE_SIGNATURE);
let mut tmp = format!("{FILE_SIGNATURE}\n");
if config.once_common_structs {
tmp.push_str(&code::generate_common_structs(
&config.default_table_options,
Expand Down
1 change: 0 additions & 1 deletion test/autogenerated_all/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub struct UpdateTodos {
pub created_at: Option<chrono::NaiveDateTime>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/autogenerated_attributes/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub struct UpdateTodos {
pub created_at: Option<chrono::NaiveDateTime>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/autogenerated_primary_keys/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub struct UpdateTodos {
pub text: Option<String>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/cleanup_generated_content/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub struct UpdateTodos {
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/create_update_str_cow/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub struct UpdateTodos<'a> {
pub varchar_nullable: Option<Option<Cow<'a, str>>>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/create_update_str_str/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub struct UpdateTodos<'a> {
pub varchar_nullable: Option<Option<&'a str>>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub struct CreateTableA {
pub _id: i32,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub struct UpdateTableB {
pub link: Option<i32>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/custom_model_path/models/tableA/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub struct CreateTableA {
pub _id: i32,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/custom_model_path/models/tableB/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub struct UpdateTableB {
pub link: Option<i32>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/manual_primary_keys/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub struct CreateTodos {
pub id: i32,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/multiple_primary_keys/models/users/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub struct UpdateUsers {
pub secret: Option<String>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 1 addition & 0 deletions test/once_connection_type/models/common.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* @generated and managed by dsync */

type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
1 change: 0 additions & 1 deletion test/once_connection_type/models/table1/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub struct Table1 {
pub id: i32,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/once_connection_type/models/table2/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub struct Table2 {
pub id: i32,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
8 changes: 2 additions & 6 deletions test/readonly/models/normal/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

use crate::diesel::*;
use crate::schema::*;
use diesel::QueryResult;
use serde::{Deserialize, Serialize};

use diesel::QueryResult;

type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;

Expand All @@ -27,7 +26,6 @@ pub struct UpdateNormal {
pub testprop: Option<i32>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand All @@ -39,7 +37,6 @@ pub struct PaginationResult<T> {
}

impl Normal {

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

Expand Down Expand Up @@ -81,5 +78,4 @@ impl Normal {

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

}
}
8 changes: 2 additions & 6 deletions test/readonly/models/prefixTable/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

use crate::diesel::*;
use crate::schema::*;
use diesel::QueryResult;
use serde::{Deserialize, Serialize};

use diesel::QueryResult;

type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;

Expand All @@ -15,7 +14,6 @@ pub struct PrefixTable {
pub testprop: i32,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand All @@ -27,7 +25,6 @@ pub struct PaginationResult<T> {
}

impl PrefixTable {

pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult<Self> {
use crate::schema::prefixTable::dsl::*;

Expand All @@ -51,5 +48,4 @@ impl PrefixTable {
num_pages: total_items / page_size + i64::from(total_items % page_size != 0)
})
}

}
}
8 changes: 2 additions & 6 deletions test/readonly/models/prefixTableSuffix/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

use crate::diesel::*;
use crate::schema::*;
use diesel::QueryResult;
use serde::{Deserialize, Serialize};

use diesel::QueryResult;

type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;

Expand All @@ -15,7 +14,6 @@ pub struct PrefixTableSuffix {
pub testprop: i32,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand All @@ -27,7 +25,6 @@ pub struct PaginationResult<T> {
}

impl PrefixTableSuffix {

pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult<Self> {
use crate::schema::prefixTableSuffix::dsl::*;

Expand All @@ -51,5 +48,4 @@ impl PrefixTableSuffix {
num_pages: total_items / page_size + i64::from(total_items % page_size != 0)
})
}

}
}
8 changes: 2 additions & 6 deletions test/readonly/models/tableSuffix/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

use crate::diesel::*;
use crate::schema::*;
use diesel::QueryResult;
use serde::{Deserialize, Serialize};

use diesel::QueryResult;

type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;

Expand All @@ -15,7 +14,6 @@ pub struct TableSuffix {
pub testprop: i32,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand All @@ -27,7 +25,6 @@ pub struct PaginationResult<T> {
}

impl TableSuffix {

pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult<Self> {
use crate::schema::tableSuffix::dsl::*;

Expand All @@ -51,5 +48,4 @@ impl TableSuffix {
num_pages: total_items / page_size + i64::from(total_items % page_size != 0)
})
}

}
}
1 change: 0 additions & 1 deletion test/simple_table/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub struct UpdateTodos {
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/simple_table_async/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub struct UpdateTodos {
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub struct UpdateTodos {
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/simple_table_no_serde/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub struct UpdateTodos {
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
}


#[derive(Debug, )]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/single_model_file/models/table1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub struct Table1 {
pub id: i32,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/single_model_file/models/table2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub struct Table2 {
pub id: i32,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down
1 change: 0 additions & 1 deletion test/use_statements/models/fang_tasks/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ pub struct UpdateFangTasks {
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
}


#[derive(Debug, Serialize)]
pub struct PaginationResult<T> {
pub items: Vec<T>,
Expand Down

0 comments on commit 2633bb8

Please sign in to comment.