-
Notifications
You must be signed in to change notification settings - Fork 14
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
Implement generator for impl Default
#142
base: main
Are you sure you want to change the base?
Conversation
…s,bin/main.rs}] Expose new generator all the way up to binary
…ames don't match struct
@Wulf Something weird is happening on my latest commit: if update_struct.has_code() {
ret_buffer.push('\n');
ret_buffer.push_str(update_struct.code());
if config.options.default_impl {
ret_buffer.push('\n');
ret_buffer.push_str(
build_default_impl_fn(
&format!("Update{struct_name}"),
&update_struct.table.columns,
)
.as_str(),
);
}
ret_buffer.push('\n');
} The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests (see simple_table_sqlite as a example), aside from that some minor style improvements.
btw, we dont have a CONTRIBUTING currently, but the commit style is angular/conventional-ish, see the commit history for examples. |
…pdate ; use `StructType::format`
Good suggestions. Yeah I still need to add tests, but it should be ready now (aside from that). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better, but still the tests are missing (at least one for being enabled with most common types).
Also consider using r#
and multiple lines instead of \n
for the format!
(like other code in the file), example:
Lines 497 to 515 in 2797966
r##" | |
/// Insert a new row into `{table_name}` with a given [`{create_struct_identifier}`] | |
pub{async_keyword} fn create(db: &mut ConnectionType, item: &{create_struct_identifier}) -> diesel::QueryResult<Self> {{ | |
use {schema_path}{table_name}::dsl::*; | |
diesel::insert_into({table_name}).values(item).get_result::<Self>(db){await_keyword} | |
}} | |
"## | |
)); | |
} else { | |
buffer.push_str(&format!( | |
r##" | |
/// Insert a new row into `{table_name}` with all default values | |
pub{async_keyword} fn create(db: &mut ConnectionType) -> diesel::QueryResult<Self> {{ | |
use {schema_path}{table_name}::dsl::*; | |
diesel::insert_into({table_name}).default_values().get_result::<Self>(db){await_keyword} | |
}} | |
"## |
PS: also existing test output needs to be updated if it is meant to change. (though to my understanding it shouldnt change as long as default_impl
is false
, which it is by default)
buffer | ||
format!( | ||
"impl Default for {struct_name} {{\n fn default() -> Self {{\n Self {{\n{f2d}\n }}\n }}\n}}", | ||
struct_name = struct_name, f2d=fields_to_defaults.as_str() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct_name = struct_name, f2d=fields_to_defaults.as_str() | |
f2d=fields_to_defaults.as_str() |
unless i missed something, that shouldnt be required anymore.
i think f2d
should also be able to be directly embedded.
No description provided.