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

refactor(db): Implement query_paged_as! macro to construct paginated queries that are still statically checked #1600

Merged
merged 10 commits into from
Mar 12, 2024

Conversation

boxbeam
Copy link
Contributor

@boxbeam boxbeam commented Mar 1, 2024

Things to note:

  • Every column is selected as non-nullable, which might not be desirable
  • & must be used to separate the last column instead of , due to a number of limitations

This might be better drafted as a procedural macro? Let me know if you'd be open to that, it would be more code but wouldn't come with these compromises

@boxbeam boxbeam requested a review from wsxiaoys March 1, 2024 22:16
@boxbeam boxbeam force-pushed the pagination-query-macro branch 2 times, most recently from 85535bb to ab4fcae Compare March 1, 2024 23:33
@boxbeam boxbeam force-pushed the pagination-query-macro branch from aa794f1 to c6bb163 Compare March 6, 2024 22:21
@boxbeam boxbeam marked this pull request as ready for review March 8, 2024 21:02
Copy link

codecov bot commented Mar 8, 2024

Codecov Report

Attention: Patch coverage is 95.08197% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 53.90%. Comparing base (d8628f1) to head (f77a6f9).
Report is 16 commits behind head on main.

Files Patch % Lines
ee/tabby-db-macros/src/lib.rs 92.40% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1600      +/-   ##
==========================================
+ Coverage   52.03%   53.90%   +1.86%     
==========================================
  Files         113      115       +2     
  Lines        9263     9580     +317     
==========================================
+ Hits         4820     5164     +344     
+ Misses       4443     4416      -27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@boxbeam boxbeam changed the title Draft pagination query macro refactor(db): Implement query_paginated_as! macro to construct paginated queries that are still statically checked Mar 8, 2024
@boxbeam boxbeam changed the title refactor(db): Implement query_paginated_as! macro to construct paginated queries that are still statically checked refactor(db): Implement query_paged_as! macro to construct paginated queries that are still statically checked Mar 8, 2024
let skip_id = input.skip_id;
let backwards = input.backwards;
quote! {
sqlx::query_as(&crate::make_pagination_query_with_condition({
Copy link
Member

Choose a reason for hiding this comment

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

this makes tabby-macros library only meaningful for tabby-db, correct? Maybe move it to ee/tabby-db-macros

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will do that, but I want to note that this has no actual dependency on tabby-db and has no feature flags associated with it, since it never actually uses that code, only generates syntax which refers to it. I was figuring that it would make sense to group all our macros in one place, if we want to add more.

ee/tabby-db/src/job_runs.rs Show resolved Hide resolved
@@ -49,6 +49,54 @@ pub struct DbConn {
cache: Arc<DbCache>,
}

fn make_pagination_query_with_condition(
Copy link
Member

Choose a reason for hiding this comment

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

consider move code that will be used by macros into a separate file, e.g src/macro_deps.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not only used by macros for the time being, so I think we should leave it here until the refactoring is complete.

@wsxiaoys wsxiaoys marked this pull request as draft March 10, 2024 07:44
@boxbeam boxbeam marked this pull request as ready for review March 11, 2024 18:14
@boxbeam boxbeam force-pushed the pagination-query-macro branch from f5be55f to 0d648cd Compare March 12, 2024 00:46
@wsxiaoys wsxiaoys merged commit f94b597 into main Mar 12, 2024
7 checks passed
@wsxiaoys wsxiaoys deleted the pagination-query-macro branch March 12, 2024 16:13
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