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

feat: Advanced queries flag (BREAKING CHANGE) #126

Merged
merged 5 commits into from
Jan 15, 2024
Merged

feat: Advanced queries flag (BREAKING CHANGE) #126

merged 5 commits into from
Jan 15, 2024

Conversation

Wulf
Copy link
Owner

@Wulf Wulf commented Jan 15, 2024

Some of this was discussed in #103 and #120

  • Introduced a flag to separate out experimental 'advanced' queries
  • Removes paginate() fn from default feature set
  • Introduces Filter and paginate fn changes

@Wulf Wulf requested a review from hasezoey January 15, 2024 01:48
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.

Looks better than #103 (thanks for the feature gate), but there are some things that still need to be done.
also it seems like the tests were not run and pushed, resulting in CI failure

let items = {table_name}.limit(page_size).offset(page * page_size).load::<Self>(db){await_keyword}?;
let page = page.max(0);
let page_size = page_size.max(1);
let total_items = Self::filter(filter.clone()).count().get_result(db)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe in the future we can eliminate this and only do it once, so that subsequent calls dont need to also execute this (something like returning a generator / iterator)

src/code.rs Show resolved Hide resolved
// Table::filter() helper fn
{
let diesel_backend = &config.diesel_backend;
let filters = table
Copy link
Collaborator

Choose a reason for hiding this comment

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

this array / iterator could likely be directly pushed onto the buffer, instead of collecting it in a intermediate vec (though not important to change now)

#[cfg(feature = "advanced-queries")]
// generate filter struct for filter() helper function
{
let filter_fields = table
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here, this could also be done without a intermediate vec (though not necessary now)

src/code.rs Outdated Show resolved Hide resolved
Comment on lines +573 to +586
if let Some(filter_{column_name}) = filter.{column_name}.clone() {{
query = if filter_{column_name}.is_some() {{
query.filter({schema_path}{table_name}::{column_name}.eq(filter_{column_name}))
}} else {{
query.filter({schema_path}{table_name}::{column_name}.is_null())
}};
}}"##
)
} else {
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.

do we really need to .clone everything? shouldnt it be possible to just use partial-moves because the function takes in full ownership of the passed filter instead of a reference and does not return the filter itself?

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 for pointing this out -- I'll have to look into it later

Copy link
Owner Author

Choose a reason for hiding this comment

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

Wulf and others added 3 commits January 15, 2024 17:57
Co-authored-by: hasezoey <hasezoey@gmail.com>
Co-authored-by: hasezoey <hasezoey@gmail.com>
@Wulf Wulf merged commit fd5862d into main Jan 15, 2024
6 checks passed
@Wulf Wulf deleted the advanced-queries branch January 15, 2024 23:09
hasezoey added a commit to hasezoey/dsync that referenced this pull request Jan 16, 2024
hasezoey added a commit to hasezoey/dsync that referenced this pull request Jan 16, 2024
hasezoey added a commit to hasezoey/dsync that referenced this pull request Jan 16, 2024
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