Skip to content

Commit 763c527

Browse files
committed
[src/code.rs] Add impl Default for Update
1 parent 4d31663 commit 763c527

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/code.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ impl<'a> Struct<'a> {
228228
derives_vec.push(derives::PARTIALEQ);
229229
}
230230

231-
derives_vec.push(derives::DEFAULT);
231+
if !self.config.options.default_impl {
232+
derives_vec.push(derives::DEFAULT);
233+
}
232234
}
233235
StructType::Create => derives_vec.extend_from_slice(&[derives::INSERTABLE]),
234236
}
@@ -824,8 +826,6 @@ pub fn generate_for_table(table: &ParsedTableMacro, config: &GenerationConfig) -
824826
let struct_name = &table.struct_name;
825827
let table_options = config.table(&table.name.to_string());
826828
let generated_columns = table_options.get_autogenerated_columns();
827-
println!("struct_name: {}", struct_name);
828-
println!("&table.name: {}", &table.name);
829829
let not_generated = |col: &&ParsedColumnMacro| -> bool {
830830
!generated_columns.contains(&col.column_name.as_str())
831831
};
@@ -870,6 +870,25 @@ pub fn generate_for_table(table: &ParsedTableMacro, config: &GenerationConfig) -
870870
if update_struct.has_code() {
871871
ret_buffer.push('\n');
872872
ret_buffer.push_str(update_struct.code());
873+
if config.options.default_impl {
874+
ret_buffer.push('\n');
875+
ret_buffer.push_str(
876+
build_default_impl_fn(
877+
&StructType::format(&StructType::Update, &struct_name),
878+
update_struct
879+
.table
880+
.columns
881+
.iter()
882+
.filter(not_generated)
883+
.map(|col| NameTypNullable {
884+
name: col.column_name.to_string(),
885+
typ: col.ty.as_str(),
886+
nullable: col.is_nullable,
887+
}),
888+
)
889+
.as_str(),
890+
);
891+
}
873892
}
874893

875894
// third, push functions - if enabled
@@ -883,15 +902,11 @@ pub fn generate_for_table(table: &ParsedTableMacro, config: &GenerationConfig) -
883902
ret_buffer.push_str(
884903
build_default_impl_fn(
885904
&struct_name,
886-
table
887-
.columns
888-
.iter()
889-
// .filter(not_generated)
890-
.map(|col| NameTypNullable {
891-
name: col.name.to_string().to_owned(),
892-
typ: col.ty.as_str(),
893-
nullable: col.is_nullable,
894-
}),
905+
table.columns.iter().map(|col| NameTypNullable {
906+
name: col.name.to_string().to_owned(),
907+
typ: col.ty.as_str(),
908+
nullable: col.is_nullable,
909+
}),
895910
)
896911
.as_str(),
897912
);

0 commit comments

Comments
 (0)