Skip to content

Commit

Permalink
fix(code): dont modify "base_type" with "Option" wrapping
Browse files Browse the repository at this point in the history
because that is what the "is_optional" bool is for, also it would result in "Option<Option<TYPE>>" for "Update" structs
  • Loading branch information
hasezoey committed Sep 30, 2023
1 parent 826f738 commit 8a68c01
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,7 @@ impl<'a> Struct<'a> {
} else {
c.ty.clone()
};
let base_type = if c.is_nullable {
format!("Option<{}>", base_type)
} else {
base_type
};
let mut is_optional = false;
let mut is_optional = c.is_nullable;

let is_pk = self
.table
Expand Down
2 changes: 1 addition & 1 deletion test/simple_table/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct CreateTodo {
#[diesel(table_name=todos)]
pub struct UpdateTodo {
pub unsigned: Option<u32>,
pub unsigned_nullable: Option<Option<u32>>,
pub unsigned_nullable: Option<u32>,
pub text: Option<String>,
pub completed: Option<bool>,
pub type_: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions test/use_statements/models/fang_tasks/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ pub struct CreateFangTask {
#[diesel(table_name=fang_tasks)]
pub struct UpdateFangTask {
pub metadata: Option<serde_json::Value>,
pub error_message: Option<Option<String>>,
pub error_message: Option<String>,
pub state: Option<crate::schema::sql_types::FangTaskState>,
pub task_type: Option<String>,
pub uniq_hash: Option<Option<String>>,
pub uniq_hash: Option<String>,
pub retries: Option<i32>,
pub scheduled_at: Option<chrono::DateTime<chrono::Utc>>,
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
Expand Down

0 comments on commit 8a68c01

Please sign in to comment.