Skip to content

Allows offset & limit to take Option<u64>#1410

Merged
tyt2y3 merged 3 commits intomasterfrom
optional-limit-n-offset
Jan 27, 2023
Merged

Allows offset & limit to take Option<u64>#1410
tyt2y3 merged 3 commits intomasterfrom
optional-limit-n-offset

Conversation

@billy1624
Copy link
Copy Markdown
Member

@billy1624 billy1624 commented Jan 20, 2023

PR Info

New Features

  • QuerySelect::offset() and QuerySelect::limit() take either Option<64> or u64

Breaking Changes

  • Changed the parameter of QuerySelect::offset() and QuerySelect::limit() to OptionalU64

@billy1624 billy1624 self-assigned this Jan 20, 2023
@billy1624 billy1624 requested a review from tyt2y3 January 21, 2023 03:44
@billy1624 billy1624 marked this pull request as ready for review January 21, 2023 03:46
@tyt2y3
Copy link
Copy Markdown
Member

tyt2y3 commented Jan 21, 2023

I don't quite like this API, something like https://docs.rs/sea-query/latest/sea_query/query/struct.SelectStatement.html#method.conditions would serve a more general usecase, may be something like:

fn maybe<T, F>(&mut self, val: Option<T>, if_some: F)
where F: FnOnce(&mut Self, v: T)

In any case I think fn foo<T>(param: T) where T: Into<Option<u64>> will do the trick better.

@billy1624
Copy link
Copy Markdown
Member Author

Hey @tyt2y3, check check #1415 for the maybe API

@billy1624
Copy link
Copy Markdown
Member Author

I still think making limit and offset to accept Into<Option<u64>> is worth doing. @tyt2y3 please advice

@tyt2y3
Copy link
Copy Markdown
Member

tyt2y3 commented Jan 26, 2023

I think the API behaviour here should be if None is passed in, it should clear the limit/offset instead of no-op.

@billy1624
Copy link
Copy Markdown
Member Author

I think the API behaviour here should be if None is passed in, it should clear the limit/offset instead of no-op.

Yes, you're right! How could I miss that. Let me add that in.

@tyt2y3
Copy link
Copy Markdown
Member

tyt2y3 commented Jan 26, 2023

That's why I said the original intention is handled better by the apply_if API instead of this one

@billy1624
Copy link
Copy Markdown
Member Author

billy1624 commented Jan 26, 2023

Still hesitated on publishing this API?

@tyt2y3 tyt2y3 merged commit 4e1a0e4 into master Jan 27, 2023
@tyt2y3 tyt2y3 deleted the optional-limit-n-offset branch January 27, 2023 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Allow limit to take -1

2 participants