Skip to content
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

Add filter() fn, update pagination() fn #103

Closed
wants to merge 10 commits into from
Closed

Add filter() fn, update pagination() fn #103

wants to merge 10 commits into from

Conversation

Wulf
Copy link
Owner

@Wulf Wulf commented Oct 28, 2023

No description provided.

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some changes that should likely be done.

i personally dont really like having to add such verbose "query = query" things, but there is no helper trait for that in diesel, right?

Comment on lines +451 to +459
.map(|column| {
let column_name = column.name.to_string();
format!(
r##"
if let Some(filter_{column_name}) = filter.{column_name}.clone() {{
query = query.filter({schema_path}{table_name}::{column_name}.eq(filter_{column_name}));
}}"##
)
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks quite redundant, is there not better option?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to suggest changes. This new filter() API is an experiment I want to run and play with. We might want to remove it in the future as intellisense gets better and better around macros.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had already looked, but there does not seem to be a diesel helper trait which would have a Update-like struct be the filter, something as simple as .filter(FilterStruct { someprop: Some(SomeValue), ..Default::default() }) similar to what .select(Struct::as_select()) would look like

buffer.push_str(&format!(
r##"
#[derive(Clone)]
pub struct {struct_name}Filter {{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be a new structtype

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's leave this for now as it's an experimental API that needs more iterations before we solidify it as a core struct.

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments.

also noticed that the tests have not been re-run since 7518fa1

Comment on lines +451 to +459
.map(|column| {
let column_name = column.name.to_string();
format!(
r##"
if let Some(filter_{column_name}) = filter.{column_name}.clone() {{
query = query.filter({schema_path}{table_name}::{column_name}.eq(filter_{column_name}));
}}"##
)
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had already looked, but there does not seem to be a diesel helper trait which would have a Update-like struct be the filter, something as simple as .filter(FilterStruct { someprop: Some(SomeValue), ..Default::default() }) similar to what .select(Struct::as_select()) would look like

@Wulf
Copy link
Owner Author

Wulf commented Nov 1, 2023

Thanks for your review @hasezoey, I've taken your feedback and applied it! 🙌

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont really like how the current filter implementation works (and i dont know a improvement), but the code otherwise looks fine, some points that could probably be changed though:

  • the validate config message will look somewhat weird, because the only case it currently will be triggered is by the input being empty
  • the example for the filter method could make use of the table names instead of the generic Todo

it would be nice if we could somehow consistently figure out what backend is being used from the connection string, and only require it if we cant figure it out (this should be possible for sqlite, mysql and postgres, but i dont know about clap liking it)

Marking this still as "Request changes" because this PR will need to be rebased onto latest master

@@ -441,6 +442,51 @@ impl {struct_name} {{
}}
"##));

// Table::filter() helper fn
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block should likely be its own function to keep the functions smaller, but this can be delayed until we refactor this (see #105)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, I’ll take a look at this later and try to rebase 🙌

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless you want to delay this PR, i will hold off on merging other stuff (even if approved) so you can get this (and possibly your other PR's) merged without having to rebase it often

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hasezoey, I really appreciate your consideration 🤗

Please do approve this PR if you think it's generally acceptable. That way, I can rebase and merge later without having to stop any others.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do approve this PR if you think it's generally acceptable. That way, I can rebase and merge later without having to stop any others.

i take this as meaning you have not rebased yet, so i will merge the other standing (approved) PRs to not have to wait, after that i will approve

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as per #103 (comment) to be able to rebase and merge it directly.

unless this PR will get closed because of #120

@Wulf
Copy link
Owner Author

Wulf commented Jan 2, 2024

Also going to close this -- we can reference it later :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants